Class EntryStream<K,​V>

    • Method Detail

      • join

        public StreamEx<String> join​(CharSequence delimiter)
        Returns a StreamEx of strings which are created joining the keys and values of the current stream using the specified delimiter.

        This is an intermediate operation.

        Parameters:
        delimiter - the delimiter to be used between key and value
        Returns:
        the new stream
        Since:
        0.2.2
      • join

        public StreamEx<String> join​(CharSequence delimiter,
                                     CharSequence prefix,
                                     CharSequence suffix)
        Returns a StreamEx of strings which are created joining the keys and values of the current stream using the specified delimiter, with the specified prefix and suffix.

        This is an intermediate operation.

        Parameters:
        delimiter - the delimiter to be used between key and value
        prefix - the sequence of characters to be used at the beginning of each resulting string
        suffix - the sequence of characters to be used at the end of each resulting string
        Returns:
        the new stream
        Since:
        0.2.2
      • flatMapKeys

        public <KK> EntryStream<KK,​V> flatMapKeys​(Function<? super K,​? extends Stream<? extends KK>> mapper)
        Returns an EntryStream consisting of the entries whose keys are results of replacing source keys with the contents of a mapped stream produced by applying the provided mapping function to each source key and values are left intact. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream is null an empty stream is used, instead.)

        This is an intermediate operation.

        Type Parameters:
        KK - The type of new keys
        Parameters:
        mapper - a non-interfering , stateless function to apply to each key which produces a stream of new keys
        Returns:
        the new stream
      • flatMapToKey

        public <KK> EntryStream<KK,​V> flatMapToKey​(BiFunction<? super K,​? super V,​? extends Stream<? extends KK>> mapper)
        Returns an EntryStream consisting of the entries whose keys are results of replacing source keys with the contents of a mapped stream produced by applying the provided mapping function and values are left intact. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream is null an empty stream is used, instead.)

        This is an intermediate operation.

        Type Parameters:
        KK - The type of new keys
        Parameters:
        mapper - a non-interfering , stateless function to apply to each key and value which produces a stream of new keys
        Returns:
        the new stream
        Since:
        0.5.2
      • flatMapValues

        public <VV> EntryStream<K,​VV> flatMapValues​(Function<? super V,​? extends Stream<? extends VV>> mapper)
        Returns an EntryStream consisting of the entries whose values are results of replacing source values with the contents of a mapped stream produced by applying the provided mapping function to each source value and keys are left intact. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream is null an empty stream is used, instead.)

        This is an intermediate operation.

        Type Parameters:
        VV - The type of new values
        Parameters:
        mapper - a non-interfering , stateless function to apply to each value which produces a stream of new values
        Returns:
        the new stream
      • flatMapToValue

        public <VV> EntryStream<K,​VV> flatMapToValue​(BiFunction<? super K,​? super V,​? extends Stream<? extends VV>> mapper)
        Returns an EntryStream consisting of the entries whose values are results of replacing source values with the contents of a mapped stream produced by applying the provided mapping function and keys are left intact. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream is null an empty stream is used, instead.)

        This is an intermediate operation.

        Type Parameters:
        VV - The type of new values
        Parameters:
        mapper - a non-interfering , stateless function to apply to each key and value which produces a stream of new values
        Returns:
        the new stream
        Since:
        0.5.2
      • flatMapKeyValue

        public <R> StreamEx<R> flatMapKeyValue​(BiFunction<? super K,​? super V,​? extends Stream<? extends R>> mapper)
        Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each key-value pair. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream is null an empty stream is used, instead.)

        This is an intermediate operation.

        Type Parameters:
        R - The element type of the new stream
        Parameters:
        mapper - a non-interfering, stateless function to apply to each key-value pair which produces a stream of new values
        Returns:
        the new stream
        Since:
        0.3.0
      • append

        public EntryStream<K,​V> append​(Map<K,​V> map)
        Returns a new EntryStream which is a concatenation of this stream and the stream created from the supplied map entries.

        This is a quasi-intermediate operation.

        May return this if the supplied map is empty and non-concurrent.

        Parameters:
        map - the map to prepend to the stream
        Returns:
        the new stream
        Since:
        0.2.1
      • append

        public EntryStream<K,​V> append​(K key,
                                             V value)
        Returns a new EntryStream which is a concatenation of this stream and the supplied key-value pair.

        This is a quasi-intermediate operation.

        Parameters:
        key - the key of the new Entry to append to this stream
        value - the value of the new Entry to append to this stream
        Returns:
        the new stream
      • append

        public EntryStream<K,​V> append​(K k1,
                                             V v1,
                                             K k2,
                                             V v2)
        Returns a new EntryStream which is a concatenation of this stream and two supplied key-value pairs.

        This is a quasi-intermediate operation.

        Parameters:
        k1 - the key of the first Entry to append to this stream
        v1 - the value of the first Entry to append to this stream
        k2 - the key of the second Entry to append to this stream
        v2 - the value of the second Entry to append to this stream
        Returns:
        the new stream
        Since:
        0.2.3
      • append

        public EntryStream<K,​V> append​(K k1,
                                             V v1,
                                             K k2,
                                             V v2,
                                             K k3,
                                             V v3)
        Returns a new EntryStream which is a concatenation of this stream and three supplied key-value pairs.

        This is a quasi-intermediate operation.

        Parameters:
        k1 - the key of the first Entry to append to this stream
        v1 - the value of the first Entry to append to this stream
        k2 - the key of the second Entry to append to this stream
        v2 - the value of the second Entry to append to this stream
        k3 - the key of the third Entry to append to this stream
        v3 - the value of the third Entry to append to this stream
        Returns:
        the new stream
        Since:
        0.2.3
      • prepend

        public EntryStream<K,​V> prepend​(Map<K,​V> map)
        Returns a new EntryStream which is a concatenation of the stream created from the supplied map entries and this stream.

        This is a quasi-intermediate operation with tail-stream optimization.

        May return this if the supplied map is empty and non-concurrent.

        Parameters:
        map - the map to prepend to the stream
        Returns:
        the new stream
        Since:
        0.2.1
      • prepend

        public EntryStream<K,​V> prepend​(K key,
                                              V value)
        Returns a new EntryStream which is a concatenation of the supplied key-value pair and this stream.

        This is a quasi-intermediate operation with tail-stream optimization.

        Parameters:
        key - the key of the new Entry to prepend to this stream
        value - the value of the new Entry to prepend to this stream
        Returns:
        the new stream
      • prepend

        public EntryStream<K,​V> prepend​(K k1,
                                              V v1,
                                              K k2,
                                              V v2)
        Returns a new EntryStream which is a concatenation of two supplied key-value pairs and this stream.

        This is a quasi-intermediate operation with tail-stream optimization.

        Parameters:
        k1 - the key of the first Entry to prepend to this stream
        v1 - the value of the first Entry to prepend to this stream
        k2 - the key of the second Entry to prepend to this stream
        v2 - the value of the second Entry to prepend to this stream
        Returns:
        the new stream
        Since:
        0.2.3
      • prepend

        public EntryStream<K,​V> prepend​(K k1,
                                              V v1,
                                              K k2,
                                              V v2,
                                              K k3,
                                              V v3)
        Returns a new EntryStream which is a concatenation of three supplied key-value pairs and this stream.

        This is a quasi-intermediate operation with tail-stream optimization.

        Parameters:
        k1 - the key of the first Entry to prepend to this stream
        v1 - the value of the first Entry to prepend to this stream
        k2 - the key of the second Entry to prepend to this stream
        v2 - the value of the second Entry to prepend to this stream
        k3 - the key of the third Entry to prepend to this stream
        v3 - the value of the third Entry to prepend to this stream
        Returns:
        the new stream
        Since:
        0.2.3
      • distinctKeys

        public EntryStream<K,​V> distinctKeys()
        Returns a stream consisting of the elements of this stream which have distinct keys (according to object equality).

        For ordered streams, the selection of distinct keys is stable (for elements with duplicating keys, the element appearing first in the encounter order is preserved.) For unordered streams, no stability guarantees are made.

        This is a stateful intermediate operation.

        Returns:
        the new stream
        Since:
        0.3.8
      • distinctValues

        public EntryStream<K,​V> distinctValues()
        Returns a stream consisting of the elements of this stream which have distinct values (according to object equality).

        For ordered streams, the selection of distinct values is stable (for elements with duplicating values, the element appearing first in the encounter order is preserved.) For unordered streams, no stability guarantees are made.

        This is a stateful intermediate operation.

        Returns:
        the new stream
        Since:
        0.3.8
      • mapKeys

        public <KK> EntryStream<KK,​V> mapKeys​(Function<? super K,​? extends KK> keyMapper)
        Returns an EntryStream consisting of the entries whose keys are modified by applying the given function and values are left unchanged.

        This is an intermediate operation.

        Type Parameters:
        KK - The type of the keys of the new stream
        Parameters:
        keyMapper - a non-interfering, stateless function to apply to each key
        Returns:
        the new stream
      • mapValues

        public <VV> EntryStream<K,​VV> mapValues​(Function<? super V,​? extends VV> valueMapper)
        Returns an EntryStream consisting of the entries whose keys are left unchanged and values are modified by applying the given function.

        This is an intermediate operation.

        Type Parameters:
        VV - The type of the values of the new stream
        Parameters:
        valueMapper - a non-interfering, stateless function to apply to each value
        Returns:
        the new stream
      • mapKeyValue

        public <R> StreamEx<R> mapKeyValue​(BiFunction<? super K,​? super V,​? extends R> mapper)
        Returns a StreamEx consisting of the results of applying the given function to the keys and values of this stream.

        This is an intermediate operation.

        Type Parameters:
        R - The element type of the new stream
        Parameters:
        mapper - a non-interfering , stateless function to apply to key and value of each Map.Entry in this stream
        Returns:
        the new stream
      • mapKeyValuePartial

        public <R> StreamEx<R> mapKeyValuePartial​(BiFunction<? super K,​? super V,​? extends Optional<? extends R>> mapper)
        Performs a mapping of the stream keys and values to a partial function removing the elements to which the function is not applicable.

        If the mapping function returns Optional.empty(), the original entry will be removed from the resulting stream. The mapping function may not return null.

        This is an intermediate operation.

        The mapKeyValuePartial() operation has the effect of applying a one-to-zero-or-one transformation to the elements of the stream, and then flattening the resulting elements into a new stream.

        Type Parameters:
        R - The element type of the new stream
        Parameters:
        mapper - a non-interfering , stateless partial function to apply to original keys and values which returns a present optional if it's applicable, or an empty optional otherwise
        Returns:
        the new stream
        Since:
        0.6.8
      • mapToKey

        public <KK> EntryStream<KK,​V> mapToKey​(BiFunction<? super K,​? super V,​? extends KK> keyMapper)
        Returns an EntryStream consisting of the entries whose keys are modified by applying the given function and values are left unchanged.

        This is an intermediate operation.

        Type Parameters:
        KK - The type of the keys of the new stream
        Parameters:
        keyMapper - a non-interfering, stateless function to apply to each key-value pair which returns the updated key
        Returns:
        the new stream
        Since:
        0.3.0
      • mapToKeyPartial

        public <KK> EntryStream<KK,​V> mapToKeyPartial​(BiFunction<? super K,​? super V,​? extends Optional<? extends KK>> keyMapper)
        Performs a mapping of the stream content to a partial function removing the entries to which the function is not applicable.

        If the mapping function returns an optional containing a new key, or Optional.empty() if function is not applicable to the entry. For successfully mapped keys the values are left intact. The mapping function may not return null.

        This is an intermediate operation.

        The mapToValuePartial() operation has the effect of applying a one-to-zero-or-one transformation to the elements of the stream, and then flattening the resulting elements into a new stream.

        Type Parameters:
        KK - The type of new keys
        Parameters:
        keyMapper - a non-interfering , stateless partial function to apply to original keys and values which returns a present optional if it's applicable, or an empty optional otherwise
        Returns:
        the new stream
        Since:
        0.6.8
      • mapToValue

        public <VV> EntryStream<K,​VV> mapToValue​(BiFunction<? super K,​? super V,​? extends VV> valueMapper)
        Returns an EntryStream consisting of the entries whose keys are left unchanged and values are modified by applying the given function.

        This is an intermediate operation.

        Type Parameters:
        VV - The type of the values of the new stream
        Parameters:
        valueMapper - a non-interfering, stateless function to apply to each key-value pair which returns the updated value
        Returns:
        the new stream
        Since:
        0.3.0
      • mapToValuePartial

        public <VV> EntryStream<K,​VV> mapToValuePartial​(BiFunction<? super K,​? super V,​? extends Optional<? extends VV>> valueMapper)
        Performs a mapping of the stream content to a partial function removing the entries to which the function is not applicable.

        If the mapping function returns an optional containing a new value, or Optional.empty() if function is not applicable to the entry. For successfully mapped values the keys are left intact. The mapping function may not return null.

        This is an intermediate operation.

        The mapToValuePartial() operation has the effect of applying a one-to-zero-or-one transformation to the elements of the stream, and then flattening the resulting elements into a new stream.

        Type Parameters:
        VV - The type of new values
        Parameters:
        valueMapper - a non-interfering , stateless partial function to apply to original keys and values which returns a present optional if it's applicable, or an empty optional otherwise
        Returns:
        the new stream
        Since:
        0.6.8
      • invert

        public EntryStream<V,​K> invert()
        Returns a stream consisting of the Map.Entry objects which keys are the values of this stream elements and vice versa.

        This is an intermediate operation.

        Returns:
        the new stream
      • anyMatch

        public boolean anyMatch​(BiPredicate<? super K,​? super V> predicate)
        Returns whether any elements of this stream match the provided predicate. If the stream is empty then false is returned and the predicate is not evaluated.

        This is a terminal operation.

        Parameters:
        predicate - a non-interfering, stateless predicate to apply to elements of this stream
        Returns:
        true if any elements of the stream match the provided predicate, otherwise false
        Since:
        0.7.0
      • allMatch

        public boolean allMatch​(BiPredicate<? super K,​? super V> predicate)
        Returns whether all elements of this stream match the provided predicate. If the stream is empty then true is returned and the predicate is not evaluated.

        This is a terminal operation.

        Parameters:
        predicate - a non-interfering, stateless predicate to apply to elements of this stream
        Returns:
        true if either all elements of the stream match the provided predicate or the stream is empty, otherwise false
        Since:
        0.7.0
      • noneMatch

        public boolean noneMatch​(BiPredicate<? super K,​? super V> predicate)
        Returns whether no elements of this stream match the provided predicate. If the stream is empty then true is returned and the predicate is not evaluated.

        This is a terminal operation.

        Parameters:
        predicate - a non-interfering, stateless predicate to apply to elements of this stream
        Returns:
        true if either no elements of the stream match the provided predicate or the stream is empty, otherwise false
        Since:
        0.7.0
      • peekKeys

        public EntryStream<K,​V> peekKeys​(Consumer<? super K> keyAction)
        Returns a stream consisting of the entries of this stream, additionally performing the provided action on each entry key as entries are consumed from the resulting stream.

        This is an intermediate operation.

        For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.

        Parameters:
        keyAction - a non-interfering action to perform on the keys of the entries as they are consumed from the stream
        Returns:
        the new stream
        Since:
        0.2.3
      • peekValues

        public EntryStream<K,​V> peekValues​(Consumer<? super V> valueAction)
        Returns a stream consisting of the entries of this stream, additionally performing the provided action on each entry value as entries are consumed from the resulting stream.

        This is an intermediate operation.

        For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.

        Parameters:
        valueAction - a non-interfering action to perform on the values of the entries as they are consumed from the stream
        Returns:
        the new stream
        Since:
        0.2.3
      • peekKeyValue

        public EntryStream<K,​V> peekKeyValue​(BiConsumer<? super K,​? super V> action)
        Returns a stream consisting of the entries of this stream, additionally performing the provided action on each entry key-value pair as entries are consumed from the resulting stream.

        This is an intermediate operation.

        For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.

        Parameters:
        action - a non-interfering action to perform on the keys and values of the entries as they are consumed from the stream
        Returns:
        the new stream
        Since:
        0.2.3
      • keys

        public StreamEx<K> keys()
        Returns a stream consisting of the keys of this stream elements.

        This is an intermediate operation.

        Returns:
        the new stream
      • values

        public StreamEx<V> values()
        Returns a stream consisting of the values of this stream elements.

        This is an intermediate operation.

        Returns:
        the new stream
      • sorted

        public EntryStream<K,​V> sorted()

        This method is unlikely to work on EntryStream, because Map.Entry instances rarely implement the Comparable interface. If you want to sort the stream by Map keys use sorted(Map.Entry.comparingByKey()) or sortedBy(Map.Entry::getKey). If you want to sort the stream by Map values use sorted(Map.Entry.comparingByValue()) or sortedBy(Map.Entry::getValue).

        Specified by:
        sorted in interface Stream<K>
        Overrides:
        sorted in class AbstractStreamEx<Map.Entry<K,​V>,​EntryStream<K,​V>>
      • collapseKeys

        public EntryStream<K,​List<V>> collapseKeys()
        Merge series of adjacent stream entries with equal keys grouping the corresponding values into List.

        This is a quasi-intermediate partial reduction operation.

        There are no guarantees on the type, mutability, serializability, or thread-safety of the List objects of the resulting stream.

        The key of the resulting entry is the key of the first merged entry.

        Returns:
        a new EntryStream which keys are the keys of the original stream and the values of adjacent entries with the same keys are grouped into List
        Since:
        0.5.5
        See Also:
        StreamEx.groupRuns(BiPredicate)
      • collapseKeys

        public EntryStream<K,​V> collapseKeys​(BinaryOperator<V> merger)
        Merge series of adjacent stream entries with equal keys combining the corresponding values using the provided function.

        This is a quasi-intermediate partial reduction operation.

        The key of the resulting entry is the key of the first merged entry.

        Parameters:
        merger - a non-interfering, stateless, associative function to merge values of two adjacent entries which keys are equal. Note that it can be applied to the results if previous merges.
        Returns:
        a new EntryStream which keys are the keys of the original stream and the values are values of the adjacent entries with the same keys, combined using the provided merger function.
        Since:
        0.5.5
        See Also:
        StreamEx.collapse(BiPredicate, BinaryOperator)
      • collapseKeys

        public <A,​R> EntryStream<K,​R> collapseKeys​(Collector<? super V,​A,​R> collector)
        Merge series of adjacent stream entries with equal keys combining the corresponding values using the provided Collector.

        This is a quasi-intermediate partial reduction operation.

        The key of the resulting entry is the key of the first merged entry.

        Type Parameters:
        R - the type of the values in the resulting stream
        A - the intermediate accumulation type of the Collector
        Parameters:
        collector - a Collector which is used to combine the values of the adjacent entries with the equal keys.
        Returns:
        a new EntryStream which keys are the keys of the original stream and the values are values of the adjacent entries with the same keys, combined using the provided collector.
        Since:
        0.5.5
        See Also:
        StreamEx.collapse(BiPredicate, Collector)
      • toImmutableMap

        public Map<K,​V> toImmutableMap()
        Returns an immutable Map containing the elements of this stream. There's no guarantees on exact type of the returned Map. In particular, no specific element order in the resulting Map is guaranteed. The returned Map is guaranteed to be serializable if all its elements are serializable.

        This is a terminal operation.

        Returns:
        a Map containing the elements of this stream
        Throws:
        IllegalStateException - if this stream contains duplicate keys (according to Object.equals(Object))
        Since:
        0.6.3
        See Also:
        toMap()
      • toMapAndThen

        public <R> R toMapAndThen​(Function<? super Map<K,​V>,​R> finisher)
        Creates a Map containing the elements of this stream, then performs finishing transformation and returns its result. There are no guarantees on the type or serializability of the Map created.

        This is a terminal operation.

        Created Map is guaranteed to be modifiable.

        For parallel stream the concurrent Map is created.

        Type Parameters:
        R - the type of the result
        Parameters:
        finisher - a function to be applied to the intermediate map
        Returns:
        result of applying the finisher transformation to the Map of the stream elements.
        Throws:
        IllegalStateException - if this stream contains duplicate keys (according to Object.equals(Object))
        Since:
        0.5.5
        See Also:
        toMap()
      • toCustomMap

        public <M extends Map<K,​V>> M toCustomMap​(BinaryOperator<V> mergeFunction,
                                                        Supplier<M> mapSupplier)
        Returns a Map containing the elements of this stream. The Map is created by a provided supplier function.

        If the mapped keys contains duplicates (according to Object.equals(Object)), the value mapping function is applied to each equal element, and the results are merged using the provided merging function.

        This is a terminal operation.

        Type Parameters:
        M - the type of the resulting map
        Parameters:
        mergeFunction - a merge function, used to resolve collisions between values associated with the same key.
        mapSupplier - a function which returns a new, empty Map into which the results will be inserted
        Returns:
        a Map containing the elements of this stream
        See Also:
        Collectors.toMap(Function, Function), Collectors.toConcurrentMap(Function, Function)
      • toSortedMap

        public SortedMap<K,​V> toSortedMap()
        Returns a SortedMap containing the elements of this stream. There are no guarantees on the type or serializability of the SortedMap returned; if more control over the returned Map is required, use toCustomMap(Supplier).

        This is a terminal operation.

        Returned SortedMap is guaranteed to be modifiable.

        For parallel stream the concurrent SortedMap is created.

        Returns:
        a SortedMap containing the elements of this stream
        Throws:
        IllegalStateException - if this stream contains duplicate keys (according to Object.equals(Object))
        Since:
        0.1.0
        See Also:
        toNavigableMap()
      • toSortedMap

        public SortedMap<K,​V> toSortedMap​(BinaryOperator<V> mergeFunction)
        Returns a SortedMap containing the elements of this stream. There are no guarantees on the type or serializability of the SortedMap returned; if more control over the returned Map is required, use toCustomMap(BinaryOperator, Supplier).

        If the mapped keys contains duplicates (according to Object.equals(Object)), the value mapping function is applied to each equal element, and the results are merged using the provided merging function.

        This is a terminal operation.

        Returned SortedMap is guaranteed to be modifiable.

        Parameters:
        mergeFunction - a merge function, used to resolve collisions between values associated with the same key, as supplied to Map.merge(Object, Object, BiFunction)
        Returns:
        a SortedMap containing the elements of this stream
        Since:
        0.1.0
        See Also:
        toNavigableMap(BinaryOperator)
      • toNavigableMap

        public NavigableMap<K,​V> toNavigableMap​(BinaryOperator<V> mergeFunction)
        Returns a NavigableMap containing the elements of this stream. There are no guarantees on the type or serializability of the NavigableMap returned; if more control over the returned Map is required, use toCustomMap(BinaryOperator, Supplier).

        If the mapped keys contains duplicates (according to Object.equals(Object)), the value mapping function is applied to each equal element, and the results are merged using the provided merging function.

        This is a terminal operation.

        Returned NavigableMap is guaranteed to be modifiable.

        Parameters:
        mergeFunction - a merge function, used to resolve collisions between values associated with the same key, as supplied to Map.merge(Object, Object, BiFunction)
        Returns:
        a NavigableMap containing the elements of this stream
        Since:
        0.6.5
        See Also:
        Collectors.toMap(Function, Function)
      • into

        public <M extends Map<K,​V>> M into​(M map)
        Drains the stream content into the supplied Map.

        This is a terminal operation.

        Type Parameters:
        M - type of the resulting map
        Parameters:
        map - a mutable map to put the stream elements into
        Returns:
        the supplied map, updated from this stream
        Throws:
        IllegalStateException - if this stream contains duplicate keys, or the stream contains the key which was already present in the map (according to Object.equals(Object))
        Since:
        0.6.3
      • grouping

        public Map<K,​List<V>> grouping()
        Returns a Map where elements of this stream with the same key are grouped together. The resulting Map keys are the keys of this stream entries and the values are the lists of the corresponding values.

        There are no guarantees on the type, mutability, serializability, or thread-safety of the Map or List objects returned. If more control over the returned Map is required, use grouping(Supplier). If more control over the lists required, use groupingTo(Supplier).

        This is a terminal operation.

        Returns:
        a Map containing the elements of this stream
        See Also:
        Collectors.groupingBy(Function)
      • grouping

        public <M extends Map<K,​List<V>>> M grouping​(Supplier<M> mapSupplier)
        Returns a Map where elements of this stream with the same key are grouped together. The resulting Map keys are the keys of this stream entries and the values are the lists of the corresponding values. The Map is created using the provided supplier function.

        There are no guarantees on the type, mutability, serializability, or thread-safety of the List objects returned. If more control over the lists required, use groupingTo(Supplier).

        This is a terminal operation.

        Type Parameters:
        M - the type of the resulting Map
        Parameters:
        mapSupplier - a function which returns a new, empty Map into which the results will be inserted
        Returns:
        a Map containing the elements of this stream
        See Also:
        grouping(Supplier, Collector), groupingTo(Supplier, Supplier)
      • grouping

        public <A,​D> Map<K,​D> grouping​(Collector<? super V,​A,​D> downstream)
        Returns a Map where elements of this stream with the same key are grouped together. The resulting Map keys are the keys of this stream entries and the corresponding values are combined using the provided downstream collector.

        There are no guarantees on the type, mutability, serializability, or thread-safety of the Map object returned. If more control over the returned Map is required, use grouping(Supplier, Collector).

        This is a terminal operation.

        Type Parameters:
        A - the intermediate accumulation type of the downstream collector
        D - the result type of the downstream reduction
        Parameters:
        downstream - a Collector implementing the downstream reduction
        Returns:
        a Map containing the elements of this stream
        See Also:
        Collectors.groupingBy(Function, Collector)
      • grouping

        public <A,​D,​M extends Map<K,​D>> M grouping​(Supplier<M> mapSupplier,
                                                                     Collector<? super V,​A,​D> downstream)
        Returns a Map where elements of this stream with the same key are grouped together. The resulting Map keys are the keys of this stream entries and the corresponding values are combined using the provided downstream collector. The Map is created using the provided supplier function.

        This is a terminal operation.

        Type Parameters:
        A - the intermediate accumulation type of the downstream collector
        D - the result type of the downstream reduction
        M - the type of the resulting Map
        Parameters:
        mapSupplier - a function which returns a new, empty Map into which the results will be inserted
        downstream - a Collector implementing the downstream reduction
        Returns:
        a Map containing the elements of this stream
        See Also:
        Collectors.groupingBy(Function, Supplier, Collector)
      • groupingTo

        public <C extends Collection<V>> Map<K,​C> groupingTo​(Supplier<C> collectionFactory)
        Returns a Map where elements of this stream with the same key are grouped together. The resulting Map keys are the keys of this stream entries and the values are the collections of the corresponding values. The collections are created by the provided factory.

        There are no guarantees on the type, mutability, serializability, or thread-safety of the Map object returned. If more control over the returned Map is required, use groupingTo(Supplier, Supplier).

        This is a terminal operation.

        Type Parameters:
        C - the type of the resulting Collection
        Parameters:
        collectionFactory - a Supplier which returns a new, empty Collection of the appropriate type
        Returns:
        a Map containing the elements of this stream
        See Also:
        Collectors.toCollection(Supplier)
      • groupingTo

        public <C extends Collection<V>,​M extends Map<K,​C>> M groupingTo​(Supplier<M> mapSupplier,
                                                                                     Supplier<C> collectionFactory)
        Returns a Map where elements of this stream with the same key are grouped together. The resulting Map keys are the keys of this stream entries and the values are the collections of the corresponding values. The collections are created by the provided factory.

        This is a terminal operation.

        Type Parameters:
        C - the type of the resulting Collection
        M - the type of the resulting Map
        Parameters:
        mapSupplier - a function which returns a new, empty Map into which the results will be inserted
        collectionFactory - a Supplier which returns a new, empty Collection of the appropriate type
        Returns:
        a Map containing the elements of this stream
        See Also:
        Collectors.toCollection(Supplier)
      • forKeyValue

        public void forKeyValue​(BiConsumer<? super K,​? super V> action)
        Performs an action for each key-value pair of this stream.

        This is a terminal operation.

        The behavior of this operation is explicitly non-deterministic. For parallel stream pipelines, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever thread the library chooses. If the action accesses shared state, it is responsible for providing the required synchronization.

        Parameters:
        action - a non-interfering action to perform on the key and value
        See Also:
        AbstractStreamEx.forEach(java.util.function.Consumer)
      • empty

        public static <K,​V> EntryStream<K,​V> empty()
        Returns an empty sequential EntryStream.
        Type Parameters:
        K - the type of stream element keys
        V - the type of stream element values
        Returns:
        an empty sequential stream
        Since:
        0.0.8
      • of

        public static <K,​V> EntryStream<K,​V> of​(Stream<? extends Map.Entry<K,​V>> stream)
        Returns an EntryStream object which wraps given Stream of Map.Entry elements
        Type Parameters:
        K - the type of original stream keys
        V - the type of original stream values
        Parameters:
        stream - original stream
        Returns:
        the wrapped stream
      • of

        public static <K,​V> EntryStream<K,​V> of​(Spliterator<? extends Map.Entry<K,​V>> spliterator)
        Returns a sequential EntryStream created from given Spliterator.
        Type Parameters:
        K - the type of stream keys
        V - the type of stream values
        Parameters:
        spliterator - a spliterator to create the stream from.
        Returns:
        the new stream
        Since:
        0.3.4
      • of

        public static <K,​V> EntryStream<K,​V> of​(Iterator<? extends Map.Entry<K,​V>> iterator)
        Returns a sequential, ordered EntryStream created from given Iterator.

        This method is roughly equivalent to EntryStream.of(Spliterators.spliteratorUnknownSize(iterator, ORDERED)) , but may show better performance for parallel processing.

        Use this method only if you cannot provide better Stream source (like Collection or Spliterator).

        Type Parameters:
        K - the type of stream keys
        V - the type of stream values
        Parameters:
        iterator - an iterator to create the stream from.
        Returns:
        the new stream
        Since:
        0.5.1
      • of

        public static <K,​V> EntryStream<K,​V> of​(Map<K,​V> map)
        Returns an EntryStream object which contains the entries of supplied Map.
        Type Parameters:
        K - the type of map keys
        V - the type of map values
        Parameters:
        map - the map to create the stream from
        Returns:
        a new EntryStream
      • of

        public static <V> EntryStream<Integer,​V> of​(List<V> list)
        Returns an EntryStream object whose keys are indices of given list and the values are the corresponding list elements.

        The list elements are accessed using List.get(int), so the list should provide fast random access. The list is assumed to be unmodifiable during the stream operations.

        Type Parameters:
        V - list element type
        Parameters:
        list - list to create the stream from
        Returns:
        a new EntryStream
        Since:
        0.2.3
      • of

        public static <V> EntryStream<Integer,​V> of​(V[] array)
        Returns an EntryStream object whose keys are indices of given array and the values are the corresponding array elements.
        Type Parameters:
        V - array element type
        Parameters:
        array - array to create the stream from
        Returns:
        a new EntryStream
        Since:
        0.2.3
      • of

        public static <K,​V> EntryStream<K,​V> of​(K key,
                                                            V value)
        Returns a sequential EntryStream containing a single key-value pair
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        key - the key of the single element
        value - the value of the single element
        Returns:
        a singleton sequential stream
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2)
        Returns a sequential EntryStream containing two key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        Returns:
        a sequential stream
        Since:
        0.2.3
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2,
                                                            K k3,
                                                            V v3)
        Returns a sequential EntryStream containing three key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        k3 - the key of the third element
        v3 - the value of the third element
        Returns:
        a sequential stream
        Since:
        0.2.3
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2,
                                                            K k3,
                                                            V v3,
                                                            K k4,
                                                            V v4)
        Returns a sequential EntryStream containing four key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        k3 - the key of the third element
        v3 - the value of the third element
        k4 - the key of the fourth element
        v4 - the value of the fourth element
        Returns:
        a sequential stream
        Since:
        0.5.2
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2,
                                                            K k3,
                                                            V v3,
                                                            K k4,
                                                            V v4,
                                                            K k5,
                                                            V v5)
        Returns a sequential EntryStream containing five key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        k3 - the key of the third element
        v3 - the value of the third element
        k4 - the key of the fourth element
        v4 - the value of the fourth element
        k5 - the key of the fifth element
        v5 - the value of the fifth element
        Returns:
        a sequential stream
        Since:
        0.5.2
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2,
                                                            K k3,
                                                            V v3,
                                                            K k4,
                                                            V v4,
                                                            K k5,
                                                            V v5,
                                                            K k6,
                                                            V v6)
        Returns a sequential EntryStream containing six key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        k3 - the key of the third element
        v3 - the value of the third element
        k4 - the key of the fourth element
        v4 - the value of the fourth element
        k5 - the key of the fifth element
        v5 - the value of the fifth element
        k6 - the key of the sixth element
        v6 - the value of the sixth element
        Returns:
        a sequential stream
        Since:
        0.5.2
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2,
                                                            K k3,
                                                            V v3,
                                                            K k4,
                                                            V v4,
                                                            K k5,
                                                            V v5,
                                                            K k6,
                                                            V v6,
                                                            K k7,
                                                            V v7)
        Returns a sequential EntryStream containing seven key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        k3 - the key of the third element
        v3 - the value of the third element
        k4 - the key of the fourth element
        v4 - the value of the fourth element
        k5 - the key of the fifth element
        v5 - the value of the fifth element
        k6 - the key of the sixth element
        v6 - the value of the sixth element
        k7 - the key of the seventh element
        v7 - the value of the seventh element
        Returns:
        a sequential stream
        Since:
        0.5.2
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2,
                                                            K k3,
                                                            V v3,
                                                            K k4,
                                                            V v4,
                                                            K k5,
                                                            V v5,
                                                            K k6,
                                                            V v6,
                                                            K k7,
                                                            V v7,
                                                            K k8,
                                                            V v8)
        Returns a sequential EntryStream containing eight key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        k3 - the key of the third element
        v3 - the value of the third element
        k4 - the key of the fourth element
        v4 - the value of the fourth element
        k5 - the key of the fifth element
        v5 - the value of the fifth element
        k6 - the key of the sixth element
        v6 - the value of the sixth element
        k7 - the key of the seventh element
        v7 - the value of the seventh element
        k8 - the key of the eighth element
        v8 - the value of the eighth element
        Returns:
        a sequential stream
        Since:
        0.5.2
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2,
                                                            K k3,
                                                            V v3,
                                                            K k4,
                                                            V v4,
                                                            K k5,
                                                            V v5,
                                                            K k6,
                                                            V v6,
                                                            K k7,
                                                            V v7,
                                                            K k8,
                                                            V v8,
                                                            K k9,
                                                            V v9)
        Returns a sequential EntryStream containing nine key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        k3 - the key of the third element
        v3 - the value of the third element
        k4 - the key of the fourth element
        v4 - the value of the fourth element
        k5 - the key of the fifth element
        v5 - the value of the fifth element
        k6 - the key of the sixth element
        v6 - the value of the sixth element
        k7 - the key of the seventh element
        v7 - the value of the seventh element
        k8 - the key of the eighth element
        v8 - the value of the eighth element
        k9 - the key of the ninth element
        v9 - the value of the ninth element
        Returns:
        a sequential stream
        Since:
        0.5.2
      • of

        public static <K,​V> EntryStream<K,​V> of​(K k1,
                                                            V v1,
                                                            K k2,
                                                            V v2,
                                                            K k3,
                                                            V v3,
                                                            K k4,
                                                            V v4,
                                                            K k5,
                                                            V v5,
                                                            K k6,
                                                            V v6,
                                                            K k7,
                                                            V v7,
                                                            K k8,
                                                            V v8,
                                                            K k9,
                                                            V v9,
                                                            K k10,
                                                            V v10)
        Returns a sequential EntryStream containing ten key-value pairs
        Type Parameters:
        K - the type of key
        V - the type of value
        Parameters:
        k1 - the key of the first element
        v1 - the value of the first element
        k2 - the key of the second element
        v2 - the value of the second element
        k3 - the key of the third element
        v3 - the value of the third element
        k4 - the key of the fourth element
        v4 - the value of the fourth element
        k5 - the key of the fifth element
        v5 - the value of the fifth element
        k6 - the key of the sixth element
        v6 - the value of the sixth element
        k7 - the key of the seventh element
        v7 - the value of the seventh element
        k8 - the key of the eighth element
        v8 - the value of the eighth element
        k9 - the key of the ninth element
        v9 - the value of the ninth element
        k10 - the key of the tenth element
        v10 - the value of the tenth element
        Returns:
        a sequential stream
        Since:
        0.5.2
      • zip

        public static <K,​V> EntryStream<K,​V> zip​(List<K> keys,
                                                             List<V> values)
        Returns a sequential EntryStream containing Entry objects composed from corresponding key and value in given two lists.

        The keys and values are accessed using List.get(int), so the lists should provide fast random access. The lists are assumed to be unmodifiable during the stream operations.

        Type Parameters:
        K - the type of stream element keys
        V - the type of stream element values
        Parameters:
        keys - the list of keys, assumed to be unmodified during use
        values - the list of values, assumed to be unmodified during use
        Returns:
        a new EntryStream
        Throws:
        IllegalArgumentException - if length of the lists differs.
        Since:
        0.2.1
        See Also:
        StreamEx.zip(List, List, BiFunction)
      • zip

        public static <K,​V> EntryStream<K,​V> zip​(K[] keys,
                                                             V[] values)
        Returns a sequential EntryStream containing Entry objects composed from corresponding key and value in given two arrays.
        Type Parameters:
        K - the type of stream element keys
        V - the type of stream element values
        Parameters:
        keys - the array of keys
        values - the array of values
        Returns:
        a new EntryStream
        Throws:
        IllegalArgumentException - if length of the arrays differs.
        Since:
        0.2.1
        See Also:
        StreamEx.zip(Object[], Object[], BiFunction)
      • ofPairs

        public static <T> EntryStream<T,​T> ofPairs​(List<T> list)
        Returns a sequential ordered EntryStream containing the possible pairs of elements taken from the provided list.

        Both keys and values are taken from the input list. The index of the key is always strictly less than the index of the value. The pairs in the stream are lexicographically ordered. For example, for the list of three elements the stream of three elements is created: Map.Entry(list.get(0), list.get(1)), Map.Entry(list.get(0), list.get(2)) and Map.Entry(list.get(1), list.get(2)). The number of elements in the resulting stream is list.size()*(list.size()+1L)/2.

        The list values are accessed using List.get(int), so the list should provide fast random access. The list is assumed to be unmodifiable during the stream operations.

        Type Parameters:
        T - type of the list elements
        Parameters:
        list - a list to take the elements from
        Returns:
        a new EntryStream
        Since:
        0.3.6
        See Also:
        StreamEx.ofPairs(List, BiFunction)
      • ofPairs

        public static <T> EntryStream<T,​T> ofPairs​(T[] array)
        Returns a sequential ordered EntryStream containing the possible pairs of elements taken from the provided array.

        Both keys and values are taken from the input array. The index of the key is always strictly less than the index of the value. The pairs in the stream are lexicographically ordered. For example, for the array of three elements the stream of three elements is created: Map.Entry(array[0], array[1]), Map.Entry(array[0], array[2]) and Map.Entry(array[1], array[2]). The number of elements in the resulting stream is array.length*(array.length+1L)/2..

        Type Parameters:
        T - type of the array elements
        Parameters:
        array - a array to take the elements from
        Returns:
        a new EntryStream
        Since:
        0.3.6
        See Also:
        StreamEx.ofPairs(Object[], BiFunction)
      • ofTree

        public static <T> EntryStream<Integer,​T> ofTree​(T root,
                                                              BiFunction<Integer,​T,​Stream<T>> mapper)
        Return a new EntryStream containing all the nodes of tree-like data structure in entry values along with the corresponding tree depths in entry keys, in depth-first order.

        The keys of the returned stream are non-negative integer numbers. 0 is used for the root node only, 1 is for root immediate children, 2 is for their children and so on.

        The streams created by mapper may be automatically closed after its contents already consumed and unnecessary anymore. It's not guaranteed that all created streams will be closed during the stream terminal operation. If it's necessary to close all the created streams, call the close() method of the resulting stream returned by ofTree().

        Type Parameters:
        T - the type of tree nodes
        Parameters:
        root - root node of the tree
        mapper - a non-interfering, stateless function to apply to each tree node and its depth which returns null for leaf nodes or stream of direct children for non-leaf nodes.
        Returns:
        the new sequential ordered EntryStream
        Since:
        0.5.2
        See Also:
        StreamEx.ofTree(Object, Function), ofTree(Object, Class, BiFunction)
      • ofTree

        public static <T,​TT extends T> EntryStream<Integer,​T> ofTree​(T root,
                                                                                 Class<TT> collectionClass,
                                                                                 BiFunction<Integer,​TT,​Stream<T>> mapper)
        Return a new EntryStream containing all the nodes of tree-like data structure in entry values along with the corresponding tree depths in entry keys, in depth-first order.

        The keys of the returned stream are non-negative integer numbers. 0 is used for the root node only, 1 is for root immediate children, 2 is for their children and so on.

        The streams created by mapper may be automatically closed after its contents already consumed and unnecessary anymore. It's not guaranteed that all created streams will be closed during the stream terminal operation. If it's necessary to close all the created streams, call the close() method of the resulting stream returned by ofTree().

        Type Parameters:
        T - the base type of tree nodes
        TT - the sub-type of composite tree nodes which may have children
        Parameters:
        root - root node of the tree
        collectionClass - a class representing the composite tree node
        mapper - a non-interfering, stateless function to apply to each composite tree node and its depth which returns stream of direct children. May return null if the given node has no children.
        Returns:
        the new sequential ordered stream
        Since:
        0.5.2
        See Also:
        StreamEx.ofTree(Object, Class, Function), ofTree(Object, BiFunction)
      • generate

        public static <K,​V> EntryStream<K,​V> generate​(Supplier<? extends K> keySupplier,
                                                                  Supplier<? extends V> valueSupplier)
        Returns an infinite sequential unordered EntryStream where each entry key is generated by the provided keySupplier and each entry value is generated by the provided valueSupplier. This is suitable for generating constant streams, streams of random elements, etc.
        Type Parameters:
        K - the type of stream element keys
        V - the type of stream element values
        Parameters:
        keySupplier - the supplier to generate keys for the new stream
        valueSupplier - the supplier to generate values for the new stream
        Returns:
        a new infinite sequential unordered EntryStream
        Since:
        0.6.6
        See Also:
        StreamEx.generate(Supplier)