Class MapStream<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    java.lang.AutoCloseable, java.util.stream.BaseStream<java.util.Map.Entry<K,​V>,​java.util.stream.Stream<java.util.Map.Entry<K,​V>>>, java.util.stream.Stream<java.util.Map.Entry<K,​V>>

    public final class MapStream<K,​V>
    extends java.lang.Object
    implements java.util.stream.Stream<java.util.Map.Entry<K,​V>>
    A stream implementation based on Map.Entry.

    This stream wraps a Stream&lt;Map.Entry&gt;, providing convenient methods for manipulating the keys and values. Unlike a Map, the keys in a MapStream do not have to be unique, although certain methods will fail if they are not unique.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.stream.Stream

        java.util.stream.Stream.Builder<T extends java.lang.Object>
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean allMatch​(java.util.function.BiPredicate<? super K,​? super V> predicate)
      Returns whether all elements of this stream match the provided predicate.
      boolean allMatch​(java.util.function.Predicate<? super java.util.Map.Entry<K,​V>> predicate)  
      boolean anyMatch​(java.util.function.BiPredicate<? super K,​? super V> predicate)
      Returns whether any elements of this stream match the provided predicate.
      boolean anyMatch​(java.util.function.Predicate<? super java.util.Map.Entry<K,​V>> predicate)  
      void close()  
      <R> R collect​(java.util.function.Supplier<R> supplier, java.util.function.BiConsumer<R,​? super java.util.Map.Entry<K,​V>> accumulator, java.util.function.BiConsumer<R,​R> combiner)  
      <R,​A>
      R
      collect​(java.util.stream.Collector<? super java.util.Map.Entry<K,​V>,​A,​R> collector)  
      static <K,​V>
      MapStream<K,​V>
      concat​(MapStream<? extends K,​? extends V> a, MapStream<? extends K,​? extends V> b)
      Creates a stream of map entries whose elements are those of the first stream followed by those of the second stream.
      long count()  
      MapStream<K,​V> distinct()  
      static <K,​V>
      MapStream<K,​V>
      empty()
      Returns an empty map stream.
      MapStream<K,​V> filter​(java.util.function.BiFunction<? super K,​? super V,​java.lang.Boolean> predicate)
      Filters the stream by applying the predicate function to each key and value.
      MapStream<K,​V> filter​(java.util.function.Predicate<? super java.util.Map.Entry<K,​V>> predicate)  
      <R> MapStream<R,​V> filterKeys​(java.lang.Class<R> castToClass)
      Filters the stream checking the type of each key.
      MapStream<K,​V> filterKeys​(java.util.function.Predicate<? super K> predicate)
      Filters the stream by applying the predicate function to each key.
      <R> MapStream<K,​R> filterValues​(java.lang.Class<R> castToClass)
      Filters the stream checking the type of each value.
      MapStream<K,​V> filterValues​(java.util.function.Predicate<? super V> predicate)
      Filters the stream by applying the predicate function to each value.
      java.util.Optional<java.util.Map.Entry<K,​V>> findAny()  
      java.util.Optional<java.util.Map.Entry<K,​V>> findFirst()  
      <R> java.util.stream.Stream<R> flatMap​(java.util.function.BiFunction<? super K,​? super V,​java.util.stream.Stream<R>> mapper)
      Transforms the entries in the stream by applying a mapper function to each key and value to produce a stream of elements, and then flattening the resulting stream of streams.
      <R> java.util.stream.Stream<R> flatMap​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends java.util.stream.Stream<? extends R>> mapper)  
      <R> MapStream<R,​V> flatMapKeys​(java.util.function.BiFunction<? super K,​? super V,​java.util.stream.Stream<R>> mapper)
      Transforms the keys in the stream by applying a mapper function to each key and value.
      <R> MapStream<R,​V> flatMapKeys​(java.util.function.Function<? super K,​java.util.stream.Stream<R>> mapper)
      Transforms the keys in the stream by applying a mapper function to each key.
      java.util.stream.DoubleStream flatMapToDouble​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends java.util.stream.DoubleStream> mapper)  
      java.util.stream.IntStream flatMapToInt​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends java.util.stream.IntStream> mapper)  
      java.util.stream.LongStream flatMapToLong​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends java.util.stream.LongStream> mapper)  
      <R> MapStream<K,​R> flatMapValues​(java.util.function.BiFunction<? super K,​? super V,​java.util.stream.Stream<R>> mapper)
      Transforms the values in the stream by applying a mapper function to each key and value.
      <R> MapStream<K,​R> flatMapValues​(java.util.function.Function<? super V,​java.util.stream.Stream<R>> mapper)
      Transforms the values in the stream by applying a mapper function to each value.
      void forEach​(java.util.function.BiConsumer<? super K,​? super V> action)
      Performs an action for each entry in the stream, passing the key and value to the action.
      void forEach​(java.util.function.Consumer<? super java.util.Map.Entry<K,​V>> action)  
      void forEachOrdered​(java.util.function.Consumer<? super java.util.Map.Entry<K,​V>> action)  
      boolean isParallel()  
      java.util.Iterator<java.util.Map.Entry<K,​V>> iterator()  
      java.util.stream.Stream<K> keys()
      Returns the keys as a stream, dropping the values.
      MapStream<K,​V> limit​(long maxSize)  
      <R> java.util.stream.Stream<R> map​(java.util.function.BiFunction<? super K,​? super V,​? extends R> mapper)
      Transforms the entries in the stream by applying a mapper function to each key and value.
      <R> java.util.stream.Stream<R> map​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends R> mapper)  
      <R> MapStream<R,​V> mapKeys​(java.util.function.BiFunction<? super K,​? super V,​? extends R> mapper)
      Transforms the keys in the stream by applying a mapper function to each key and value.
      <R> MapStream<R,​V> mapKeys​(java.util.function.Function<? super K,​? extends R> mapper)
      Transforms the keys in the stream by applying a mapper function to each key.
      java.util.stream.DoubleStream mapToDouble​(java.util.function.ToDoubleFunction<? super java.util.Map.Entry<K,​V>> mapper)  
      java.util.stream.IntStream mapToInt​(java.util.function.ToIntFunction<? super java.util.Map.Entry<K,​V>> mapper)  
      java.util.stream.LongStream mapToLong​(java.util.function.ToLongFunction<? super java.util.Map.Entry<K,​V>> mapper)  
      <R> MapStream<K,​R> mapValues​(java.util.function.BiFunction<? super K,​? super V,​? extends R> mapper)
      Transforms the values in the stream by applying a mapper function to each key and value.
      <R> MapStream<K,​R> mapValues​(java.util.function.Function<? super V,​? extends R> mapper)
      Transforms the values in the stream by applying a mapper function to each value.
      java.util.Optional<java.util.Map.Entry<K,​V>> max​(java.util.Comparator<? super java.util.Map.Entry<K,​V>> comparator)  
      java.util.Optional<java.util.Map.Entry<K,​V>> maxKeys​(java.util.Comparator<? super K> comparator)
      Finds the maximum entry in the stream by comparing the keys using the supplied comparator.
      java.util.Optional<java.util.Map.Entry<K,​V>> maxValues​(java.util.Comparator<? super V> comparator)
      Finds the maximum entry in the stream by comparing the values using the supplied comparator.
      java.util.Optional<java.util.Map.Entry<K,​V>> min​(java.util.Comparator<? super java.util.Map.Entry<K,​V>> comparator)  
      java.util.Optional<java.util.Map.Entry<K,​V>> minKeys​(java.util.Comparator<? super K> comparator)
      Finds the minimum entry in the stream by comparing the keys using the supplied comparator.
      java.util.Optional<java.util.Map.Entry<K,​V>> minValues​(java.util.Comparator<? super V> comparator)
      Finds the minimum entry in the stream by comparing the values using the supplied comparator.
      boolean noneMatch​(java.util.function.BiPredicate<? super K,​? super V> predicate)
      Returns whether no elements of this stream match the provided predicate.
      boolean noneMatch​(java.util.function.Predicate<? super java.util.Map.Entry<K,​V>> predicate)  
      static <K,​V>
      MapStream<K,​V>
      of​(com.google.common.collect.Multimap<K,​V> multimap)
      Returns a stream over all the entries in the multimap.
      static <T,​K,​V>
      MapStream<K,​V>
      of​(java.util.Collection<T> collection, java.util.function.Function<T,​K> keyFunction, java.util.function.Function<T,​V> valueFunction)
      Returns a stream of map entries where the keys and values are extracted from a collection by applying a function to each item in the collection.
      static <K,​V>
      MapStream<K,​V>
      of​(java.util.Collection<V> collection, java.util.function.Function<V,​K> keyFunction)
      Returns a stream of map entries where the values are taken from a collection and the keys are created by applying a function to each value.
      static <K,​V>
      MapStream<K,​V>
      of​(java.util.Map<K,​V> map)
      Returns a stream over the entries in the map.
      static <T,​K,​V>
      MapStream<K,​V>
      of​(java.util.stream.Stream<T> stream, java.util.function.Function<T,​K> keyFunction, java.util.function.Function<T,​V> valueFunction)
      Returns a stream of map entries where the keys and values are extracted from a stream by applying a function to each item in the stream.
      static <K,​V>
      MapStream<K,​V>
      of​(java.util.stream.Stream<V> stream, java.util.function.Function<V,​K> keyFunction)
      Returns a stream of map entries where the values are taken from a stream and the keys are created by applying a function to each value.
      MapStream<K,​V> onClose​(java.lang.Runnable closeHandler)  
      MapStream<K,​V> parallel()  
      MapStream<K,​V> peek​(java.util.function.Consumer<? super java.util.Map.Entry<K,​V>> action)  
      java.util.Optional<java.util.Map.Entry<K,​V>> reduce​(java.util.function.BinaryOperator<java.util.Map.Entry<K,​V>> accumulator)  
      java.util.Map.Entry<K,​V> reduce​(java.util.Map.Entry<K,​V> identity, java.util.function.BinaryOperator<java.util.Map.Entry<K,​V>> accumulator)  
      <U> U reduce​(U identity, java.util.function.BiFunction<U,​? super java.util.Map.Entry<K,​V>,​U> accumulator, java.util.function.BinaryOperator<U> combiner)  
      MapStream<K,​V> sequential()  
      MapStream<K,​V> skip​(long n)  
      MapStream<K,​V> sorted()  
      MapStream<K,​V> sorted​(java.util.Comparator<? super java.util.Map.Entry<K,​V>> comparator)  
      MapStream<K,​V> sortedKeys()
      Sorts the entries in the stream by comparing the keys using their natural ordering.
      MapStream<K,​V> sortedKeys​(java.util.Comparator<? super K> comparator)
      Sorts the entries in the stream by comparing the keys using the supplied comparator.
      MapStream<K,​V> sortedValues()
      Sorts the entries in the stream by comparing the values using their natural ordering.
      MapStream<K,​V> sortedValues​(java.util.Comparator<? super V> comparator)
      Sorts the entries in the stream by comparing the values using the supplied comparator.
      java.util.Spliterator<java.util.Map.Entry<K,​V>> spliterator()  
      java.lang.Object[] toArray()  
      <A> A[] toArray​(java.util.function.IntFunction<A[]> generator)  
      com.google.common.collect.ImmutableListMultimap<K,​V> toListMultimap()
      Returns an immutable list multimap built from the entries in the stream.
      com.google.common.collect.ImmutableMap<K,​V> toMap()
      Returns an immutable map built from the entries in the stream.
      com.google.common.collect.ImmutableMap<K,​V> toMap​(java.util.function.BiFunction<? super V,​? super V,​? extends V> mergeFn)
      Returns an immutable map built from the entries in the stream.
      com.google.common.collect.ImmutableMap<K,​java.util.List<V>> toMapGrouping()
      Returns an immutable map built from the entries in the stream, grouping by key.
      <A,​R>
      com.google.common.collect.ImmutableMap<K,​R>
      toMapGrouping​(java.util.stream.Collector<? super V,​A,​R> valueCollector)
      Returns an immutable map built from the entries in the stream, grouping by key.
      MapStream<K,​V> unordered()  
      java.util.stream.Stream<V> values()
      Returns the values as a stream, dropping the keys.
      static <K,​V>
      MapStream<K,​V>
      zip​(java.util.stream.Stream<K> keyStream, java.util.stream.Stream<V> valueStream)
      Returns a map stream that combines two other streams, continuing until either stream ends.
      static <V> MapStream<java.lang.Integer,​V> zipWithIndex​(java.util.stream.Stream<V> stream)
      Returns a stream of map entries where each key is the index of the value in the original stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.stream.Stream

        dropWhile, takeWhile
    • Method Detail

      • of

        public static <K,​V> MapStream<K,​V> of​(java.util.Map<K,​V> map)
        Returns a stream over the entries in the map.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - the map to wrap
        Returns:
        a stream over the entries in the map
      • of

        public static <K,​V> MapStream<K,​V> of​(com.google.common.collect.Multimap<K,​V> multimap)
        Returns a stream over all the entries in the multimap.

        This will typically create a stream with duplicate keys.

        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        multimap - the multimap to wrap
        Returns:
        a stream over the entries in the multimap
      • of

        public static <K,​V> MapStream<K,​V> of​(java.util.Collection<V> collection,
                                                          java.util.function.Function<V,​K> keyFunction)
        Returns a stream of map entries where the values are taken from a collection and the keys are created by applying a function to each value.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        collection - the collection of values
        keyFunction - a function which returns the key for a value
        Returns:
        a stream of map entries derived from the values in the collection
      • of

        public static <T,​K,​V> MapStream<K,​V> of​(java.util.Collection<T> collection,
                                                                  java.util.function.Function<T,​K> keyFunction,
                                                                  java.util.function.Function<T,​V> valueFunction)
        Returns a stream of map entries where the keys and values are extracted from a collection by applying a function to each item in the collection.
        Type Parameters:
        T - the collection type
        K - the key type
        V - the value type
        Parameters:
        collection - the collection of values
        keyFunction - a function which returns the key
        valueFunction - a function which returns the value
        Returns:
        a stream of map entries derived from the collection
      • of

        public static <K,​V> MapStream<K,​V> of​(java.util.stream.Stream<V> stream,
                                                          java.util.function.Function<V,​K> keyFunction)
        Returns a stream of map entries where the values are taken from a stream and the keys are created by applying a function to each value.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        stream - the stream of values
        keyFunction - a function which returns the key for a value
        Returns:
        a stream of map entries derived from the values in the stream
      • of

        public static <T,​K,​V> MapStream<K,​V> of​(java.util.stream.Stream<T> stream,
                                                                  java.util.function.Function<T,​K> keyFunction,
                                                                  java.util.function.Function<T,​V> valueFunction)
        Returns a stream of map entries where the keys and values are extracted from a stream by applying a function to each item in the stream.
        Type Parameters:
        T - the collection type
        K - the key type
        V - the value type
        Parameters:
        stream - the stream of values
        keyFunction - a function which returns the key for a value
        valueFunction - a function which returns the value
        Returns:
        a stream of map entries derived from the stream
      • zip

        public static <K,​V> MapStream<K,​V> zip​(java.util.stream.Stream<K> keyStream,
                                                           java.util.stream.Stream<V> valueStream)
        Returns a map stream that combines two other streams, continuing until either stream ends.

        Note that this can produce a stream with non-unique keys.

        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        keyStream - the stream of keys
        valueStream - the stream of values
        Returns:
        a stream of map entries derived from the stream
      • zipWithIndex

        public static <V> MapStream<java.lang.Integer,​V> zipWithIndex​(java.util.stream.Stream<V> stream)
        Returns a stream of map entries where each key is the index of the value in the original stream.
        Type Parameters:
        V - the value type
        Parameters:
        stream - the stream of values
        Returns:
        a stream of map entries derived from the stream
      • empty

        public static <K,​V> MapStream<K,​V> empty()
        Returns an empty map stream.
        Type Parameters:
        K - the key type
        V - the value type
        Returns:
        an empty map stream
      • concat

        public static <K,​V> MapStream<K,​V> concat​(MapStream<? extends K,​? extends V> a,
                                                              MapStream<? extends K,​? extends V> b)
        Creates a stream of map entries whose elements are those of the first stream followed by those of the second stream.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        a - the first stream of entries
        b - the second stream of entries
        Returns:
        the concatenation of the two input streams
      • keys

        public java.util.stream.Stream<K> keys()
        Returns the keys as a stream, dropping the values.

        A MapStream may contain the same key more than once, so callers may need to call Stream.distinct() on the result.

        Returns:
        a stream of the keys
      • values

        public java.util.stream.Stream<V> values()
        Returns the values as a stream, dropping the keys.
        Returns:
        a stream of the values
      • filter

        public MapStream<K,​V> filter​(java.util.function.BiFunction<? super K,​? super V,​java.lang.Boolean> predicate)
        Filters the stream by applying the predicate function to each key and value.

        Entries are included in the returned stream if the predicate function returns true.

        Parameters:
        predicate - a predicate function applied to each key and value in the stream
        Returns:
        a stream including the entries for which the predicate function returned true
      • filterKeys

        public MapStream<K,​V> filterKeys​(java.util.function.Predicate<? super K> predicate)
        Filters the stream by applying the predicate function to each key.

        Entries are included in the returned stream if the predicate function returns true.

        Parameters:
        predicate - a predicate function applied to each key in the stream
        Returns:
        a stream including the entries for which the predicate function returned true
      • filterKeys

        public <R> MapStream<R,​V> filterKeys​(java.lang.Class<R> castToClass)
        Filters the stream checking the type of each key.

        Entries are included in the returned stream if the key is an instance of the specified type.

        Type Parameters:
        R - the type to filter to
        Parameters:
        castToClass - the class to filter the keys to
        Returns:
        a stream including only those entries where the key is an instance of the specified type
      • filterValues

        public MapStream<K,​V> filterValues​(java.util.function.Predicate<? super V> predicate)
        Filters the stream by applying the predicate function to each value.

        Entries are included in the returned stream if the predicate function returns true.

        Parameters:
        predicate - a predicate function applied to each value in the stream
        Returns:
        a stream including the entries for which the predicate function returned true
      • filterValues

        public <R> MapStream<K,​R> filterValues​(java.lang.Class<R> castToClass)
        Filters the stream checking the type of each value.

        Entries are included in the returned stream if the value is an instance of the specified type.

        Type Parameters:
        R - the type to filter to
        Parameters:
        castToClass - the class to filter the values to
        Returns:
        a stream including only those entries where the value is an instance of the specified type
      • mapKeys

        public <R> MapStream<R,​V> mapKeys​(java.util.function.Function<? super K,​? extends R> mapper)
        Transforms the keys in the stream by applying a mapper function to each key.

        The values are unchanged.

        Type Parameters:
        R - the type of the new keys
        Parameters:
        mapper - a mapper function whose return value is used as the new key
        Returns:
        a stream of entries with the keys transformed and the values unchanged
      • mapKeys

        public <R> MapStream<R,​V> mapKeys​(java.util.function.BiFunction<? super K,​? super V,​? extends R> mapper)
        Transforms the keys in the stream by applying a mapper function to each key and value.

        The values are unchanged.

        Type Parameters:
        R - the type of the new keys
        Parameters:
        mapper - a mapper function whose return value is used as the new key
        Returns:
        a stream of entries with the keys transformed and the values unchanged
      • mapValues

        public <R> MapStream<K,​R> mapValues​(java.util.function.Function<? super V,​? extends R> mapper)
        Transforms the values in the stream by applying a mapper function to each value.

        The keys are unchanged.

        Type Parameters:
        R - the type of the new values
        Parameters:
        mapper - a mapper function whose return value is used as the new value
        Returns:
        a stream of entries with the values transformed and the keys unchanged
      • mapValues

        public <R> MapStream<K,​R> mapValues​(java.util.function.BiFunction<? super K,​? super V,​? extends R> mapper)
        Transforms the values in the stream by applying a mapper function to each key and value.

        The keys are unchanged.

        Type Parameters:
        R - the type of the new values
        Parameters:
        mapper - a mapper function whose return value is used as the new value
        Returns:
        a stream of entries with the values transformed and the keys unchanged
      • map

        public <R> java.util.stream.Stream<R> map​(java.util.function.BiFunction<? super K,​? super V,​? extends R> mapper)
        Transforms the entries in the stream by applying a mapper function to each key and value.
        Type Parameters:
        R - the type of elements in the new stream
        Parameters:
        mapper - a mapper function whose return values are included in the new stream
        Returns:
        a stream containing the values returned from the mapper function
      • flatMapKeys

        public <R> MapStream<R,​V> flatMapKeys​(java.util.function.Function<? super K,​java.util.stream.Stream<R>> mapper)
        Transforms the keys in the stream by applying a mapper function to each key.

        The new keys produced will be associated with the original value.

        Type Parameters:
        R - the type of the new keys
        Parameters:
        mapper - a mapper function whose return values are the keys in the new stream
        Returns:
        a stream of entries with new keys from the mapper function assigned to the values
      • flatMapKeys

        public <R> MapStream<R,​V> flatMapKeys​(java.util.function.BiFunction<? super K,​? super V,​java.util.stream.Stream<R>> mapper)
        Transforms the keys in the stream by applying a mapper function to each key and value.

        The new keys produced will be associated with the original value.

        For example this could turn a MapStream<List<String>, LocalDate> into a MapStream<String, LocalDate>

        Type Parameters:
        R - the type of the new keys
        Parameters:
        mapper - a mapper function whose return values are the keys in the new stream
        Returns:
        a stream of entries with new keys from the mapper function assigned to the values
      • flatMapValues

        public <R> MapStream<K,​R> flatMapValues​(java.util.function.Function<? super V,​java.util.stream.Stream<R>> mapper)
        Transforms the values in the stream by applying a mapper function to each value.

        The new values produced will be associated with the original key.

        For example this could turn a MapStream<LocalDate, List<String>> into a MapStream<LocalDate, String>

        Type Parameters:
        R - the type of the new values
        Parameters:
        mapper - a mapper function whose return values are the values in the new stream
        Returns:
        a stream of entries with new values from the mapper function assigned to the keys
      • flatMapValues

        public <R> MapStream<K,​R> flatMapValues​(java.util.function.BiFunction<? super K,​? super V,​java.util.stream.Stream<R>> mapper)
        Transforms the values in the stream by applying a mapper function to each key and value.

        The new values produced will be associated with the original key.

        For example this could turn a MapStream<LocalDate, List<String>> into a MapStream<LocalDate, String>

        Type Parameters:
        R - the type of the new values
        Parameters:
        mapper - a mapper function whose return values are the values in the new stream
        Returns:
        a stream of entries with new values from the mapper function assigned to the keys
      • flatMap

        public <R> java.util.stream.Stream<R> flatMap​(java.util.function.BiFunction<? super K,​? super V,​java.util.stream.Stream<R>> mapper)
        Transforms the entries in the stream by applying a mapper function to each key and value to produce a stream of elements, and then flattening the resulting stream of streams.
        Type Parameters:
        R - the type of the elements in the new stream
        Parameters:
        mapper - a mapper function whose return values are included in the new stream
        Returns:
        a stream containing the values returned from the mapper function
      • sortedKeys

        public MapStream<K,​V> sortedKeys()
        Sorts the entries in the stream by comparing the keys using their natural ordering.

        If the keys in this map stream are not Comparable a java.lang.ClassCastException may be thrown. In this case use sortedKeys(Comparator) instead.

        Returns:
        the sorted stream
      • sortedKeys

        public MapStream<K,​V> sortedKeys​(java.util.Comparator<? super K> comparator)
        Sorts the entries in the stream by comparing the keys using the supplied comparator.
        Parameters:
        comparator - a comparator of keys
        Returns:
        the sorted stream
      • sortedValues

        public MapStream<K,​V> sortedValues()
        Sorts the entries in the stream by comparing the values using their natural ordering.

        If the values in this map stream are not Comparable a java.lang.ClassCastException may be thrown. In this case use sortedValues(Comparator) instead.

        Returns:
        the sorted stream
      • sortedValues

        public MapStream<K,​V> sortedValues​(java.util.Comparator<? super V> comparator)
        Sorts the entries in the stream by comparing the values using the supplied comparator.
        Parameters:
        comparator - a comparator of values
        Returns:
        the sorted stream
      • minKeys

        public java.util.Optional<java.util.Map.Entry<K,​V>> minKeys​(java.util.Comparator<? super K> comparator)
        Finds the minimum entry in the stream by comparing the keys using the supplied comparator.

        This is a terminal operation.

        Parameters:
        comparator - a comparator of keys
        Returns:
        the minimum entry
      • minValues

        public java.util.Optional<java.util.Map.Entry<K,​V>> minValues​(java.util.Comparator<? super V> comparator)
        Finds the minimum entry in the stream by comparing the values using the supplied comparator.

        This is a terminal operation.

        Parameters:
        comparator - a comparator of values
        Returns:
        the minimum entry
      • maxKeys

        public java.util.Optional<java.util.Map.Entry<K,​V>> maxKeys​(java.util.Comparator<? super K> comparator)
        Finds the maximum entry in the stream by comparing the keys using the supplied comparator.

        This is a terminal operation.

        Parameters:
        comparator - a comparator of keys
        Returns:
        the maximum entry
      • maxValues

        public java.util.Optional<java.util.Map.Entry<K,​V>> maxValues​(java.util.Comparator<? super V> comparator)
        Finds the maximum entry in the stream by comparing the values using the supplied comparator.

        This is a terminal operation.

        Parameters:
        comparator - a comparator of values
        Returns:
        the maximum entry
      • anyMatch

        public boolean anyMatch​(java.util.function.BiPredicate<? super K,​? super V> predicate)
        Returns whether any elements of this stream match the provided predicate.

        This is a short-circuiting terminal operation.

        Parameters:
        predicate - the predicate to apply to the entries
        Returns:
        whether any of the entries matched the predicate
      • allMatch

        public boolean allMatch​(java.util.function.BiPredicate<? super K,​? super V> predicate)
        Returns whether all elements of this stream match the provided predicate.

        This is a short-circuiting terminal operation.

        Parameters:
        predicate - the predicate to apply to the entries
        Returns:
        whether all of the entries matched the predicate
      • noneMatch

        public boolean noneMatch​(java.util.function.BiPredicate<? super K,​? super V> predicate)
        Returns whether no elements of this stream match the provided predicate.

        This is a short-circuiting terminal operation.

        Parameters:
        predicate - the predicate to apply to the entries
        Returns:
        whether none of the entries matched the predicate
      • toMap

        public com.google.common.collect.ImmutableMap<K,​V> toMap()
        Returns an immutable map built from the entries in the stream.

        The keys must be unique or an exception will be thrown. Duplicate keys can be handled using toMap(BiFunction).

        This is a terminal operation.

        Returns:
        an immutable map built from the entries in the stream
        Throws:
        java.lang.IllegalArgumentException - if the same key occurs more than once
      • toMap

        public com.google.common.collect.ImmutableMap<K,​V> toMap​(java.util.function.BiFunction<? super V,​? super V,​? extends V> mergeFn)
        Returns an immutable map built from the entries in the stream.

        If the same key maps to multiple values the merge function is invoked with both values and the return value is used in the map.

        Can be used with concat(MapStream, MapStream) to merge immutable maps with duplicate keys.

        For example, to merge immutable maps with duplicate keys preferring values in the first map:

           MapStream.concat(mapStreamA, mapStreamB).toMap((a,b) -> a);
         

        This is a terminal operation.

        Parameters:
        mergeFn - function used to merge values when the same key appears multiple times in the stream
        Returns:
        an immutable map built from the entries in the stream
      • toMapGrouping

        public com.google.common.collect.ImmutableMap<K,​java.util.List<V>> toMapGrouping()
        Returns an immutable map built from the entries in the stream, grouping by key.

        Entries are grouped based on the equality of the key.

        This is a terminal operation.

        Returns:
        an immutable map built from the entries in the stream
      • toMapGrouping

        public <A,​R> com.google.common.collect.ImmutableMap<K,​R> toMapGrouping​(java.util.stream.Collector<? super V,​A,​R> valueCollector)
        Returns an immutable map built from the entries in the stream, grouping by key.

        Entries are grouped based on the equality of the key. The collector allows the values to be flexibly combined.

        This is a terminal operation.

        Type Parameters:
        A - the internal collector type
        R - the type of the combined values
        Parameters:
        valueCollector - the collector used to combined the values
        Returns:
        a stream where the values have been grouped
      • toListMultimap

        public com.google.common.collect.ImmutableListMultimap<K,​V> toListMultimap()
        Returns an immutable list multimap built from the entries in the stream.

        This is a terminal operation.

        Returns:
        an immutable list multimap built from the entries in the stream
      • forEach

        public void forEach​(java.util.function.BiConsumer<? super K,​? super V> action)
        Performs an action for each entry in the stream, passing the key and value to the action.

        This is a terminal operation.

        Parameters:
        action - an action performed for each entry in the stream
      • filter

        public MapStream<K,​V> filter​(java.util.function.Predicate<? super java.util.Map.Entry<K,​V>> predicate)
        Specified by:
        filter in interface java.util.stream.Stream<K>
      • map

        public <R> java.util.stream.Stream<R> map​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends R> mapper)
        Specified by:
        map in interface java.util.stream.Stream<K>
      • mapToInt

        public java.util.stream.IntStream mapToInt​(java.util.function.ToIntFunction<? super java.util.Map.Entry<K,​V>> mapper)
        Specified by:
        mapToInt in interface java.util.stream.Stream<K>
      • mapToLong

        public java.util.stream.LongStream mapToLong​(java.util.function.ToLongFunction<? super java.util.Map.Entry<K,​V>> mapper)
        Specified by:
        mapToLong in interface java.util.stream.Stream<K>
      • mapToDouble

        public java.util.stream.DoubleStream mapToDouble​(java.util.function.ToDoubleFunction<? super java.util.Map.Entry<K,​V>> mapper)
        Specified by:
        mapToDouble in interface java.util.stream.Stream<K>
      • flatMap

        public <R> java.util.stream.Stream<R> flatMap​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends java.util.stream.Stream<? extends R>> mapper)
        Specified by:
        flatMap in interface java.util.stream.Stream<K>
      • flatMapToInt

        public java.util.stream.IntStream flatMapToInt​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends java.util.stream.IntStream> mapper)
        Specified by:
        flatMapToInt in interface java.util.stream.Stream<K>
      • flatMapToLong

        public java.util.stream.LongStream flatMapToLong​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends java.util.stream.LongStream> mapper)
        Specified by:
        flatMapToLong in interface java.util.stream.Stream<K>
      • flatMapToDouble

        public java.util.stream.DoubleStream flatMapToDouble​(java.util.function.Function<? super java.util.Map.Entry<K,​V>,​? extends java.util.stream.DoubleStream> mapper)
        Specified by:
        flatMapToDouble in interface java.util.stream.Stream<K>
      • distinct

        public MapStream<K,​V> distinct()
        Specified by:
        distinct in interface java.util.stream.Stream<K>
      • sorted

        public MapStream<K,​V> sorted()
        Specified by:
        sorted in interface java.util.stream.Stream<K>
      • sorted

        public MapStream<K,​V> sorted​(java.util.Comparator<? super java.util.Map.Entry<K,​V>> comparator)
        Specified by:
        sorted in interface java.util.stream.Stream<K>
      • peek

        public MapStream<K,​V> peek​(java.util.function.Consumer<? super java.util.Map.Entry<K,​V>> action)
        Specified by:
        peek in interface java.util.stream.Stream<K>
      • limit

        public MapStream<K,​V> limit​(long maxSize)
        Specified by:
        limit in interface java.util.stream.Stream<K>
      • skip

        public MapStream<K,​V> skip​(long n)
        Specified by:
        skip in interface java.util.stream.Stream<K>
      • forEach

        public void forEach​(java.util.function.Consumer<? super java.util.Map.Entry<K,​V>> action)
        Specified by:
        forEach in interface java.util.stream.Stream<K>
      • forEachOrdered

        public void forEachOrdered​(java.util.function.Consumer<? super java.util.Map.Entry<K,​V>> action)
        Specified by:
        forEachOrdered in interface java.util.stream.Stream<K>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.stream.Stream<K>
      • toArray

        public <A> A[] toArray​(java.util.function.IntFunction<A[]> generator)
        Specified by:
        toArray in interface java.util.stream.Stream<K>
      • reduce

        public java.util.Map.Entry<K,​V> reduce​(java.util.Map.Entry<K,​V> identity,
                                                     java.util.function.BinaryOperator<java.util.Map.Entry<K,​V>> accumulator)
        Specified by:
        reduce in interface java.util.stream.Stream<K>
      • reduce

        public java.util.Optional<java.util.Map.Entry<K,​V>> reduce​(java.util.function.BinaryOperator<java.util.Map.Entry<K,​V>> accumulator)
        Specified by:
        reduce in interface java.util.stream.Stream<K>
      • reduce

        public <U> U reduce​(U identity,
                            java.util.function.BiFunction<U,​? super java.util.Map.Entry<K,​V>,​U> accumulator,
                            java.util.function.BinaryOperator<U> combiner)
        Specified by:
        reduce in interface java.util.stream.Stream<K>
      • collect

        public <R> R collect​(java.util.function.Supplier<R> supplier,
                             java.util.function.BiConsumer<R,​? super java.util.Map.Entry<K,​V>> accumulator,
                             java.util.function.BiConsumer<R,​R> combiner)
        Specified by:
        collect in interface java.util.stream.Stream<K>
      • collect

        public <R,​A> R collect​(java.util.stream.Collector<? super java.util.Map.Entry<K,​V>,​A,​R> collector)
        Specified by:
        collect in interface java.util.stream.Stream<K>
      • min

        public java.util.Optional<java.util.Map.Entry<K,​V>> min​(java.util.Comparator<? super java.util.Map.Entry<K,​V>> comparator)
        Specified by:
        min in interface java.util.stream.Stream<K>
      • max

        public java.util.Optional<java.util.Map.Entry<K,​V>> max​(java.util.Comparator<? super java.util.Map.Entry<K,​V>> comparator)
        Specified by:
        max in interface java.util.stream.Stream<K>
      • count

        public long count()
        Specified by:
        count in interface java.util.stream.Stream<K>
      • anyMatch

        public boolean anyMatch​(java.util.function.Predicate<? super java.util.Map.Entry<K,​V>> predicate)
        Specified by:
        anyMatch in interface java.util.stream.Stream<K>
      • allMatch

        public boolean allMatch​(java.util.function.Predicate<? super java.util.Map.Entry<K,​V>> predicate)
        Specified by:
        allMatch in interface java.util.stream.Stream<K>
      • noneMatch

        public boolean noneMatch​(java.util.function.Predicate<? super java.util.Map.Entry<K,​V>> predicate)
        Specified by:
        noneMatch in interface java.util.stream.Stream<K>
      • findFirst

        public java.util.Optional<java.util.Map.Entry<K,​V>> findFirst()
        Specified by:
        findFirst in interface java.util.stream.Stream<K>
      • findAny

        public java.util.Optional<java.util.Map.Entry<K,​V>> findAny()
        Specified by:
        findAny in interface java.util.stream.Stream<K>
      • iterator

        public java.util.Iterator<java.util.Map.Entry<K,​V>> iterator()
        Specified by:
        iterator in interface java.util.stream.BaseStream<K,​V>
      • spliterator

        public java.util.Spliterator<java.util.Map.Entry<K,​V>> spliterator()
        Specified by:
        spliterator in interface java.util.stream.BaseStream<K,​V>
      • isParallel

        public boolean isParallel()
        Specified by:
        isParallel in interface java.util.stream.BaseStream<K,​V>
      • sequential

        public MapStream<K,​V> sequential()
        Specified by:
        sequential in interface java.util.stream.BaseStream<K,​V>
      • parallel

        public MapStream<K,​V> parallel()
        Specified by:
        parallel in interface java.util.stream.BaseStream<K,​V>
      • unordered

        public MapStream<K,​V> unordered()
        Specified by:
        unordered in interface java.util.stream.BaseStream<K,​V>
      • onClose

        public MapStream<K,​V> onClose​(java.lang.Runnable closeHandler)
        Specified by:
        onClose in interface java.util.stream.BaseStream<K,​V>
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.util.stream.BaseStream<K,​V>