Class EntryStream<K,V>
- Object
-
- AbstractStreamEx<Map.Entry<K,V>,EntryStream<K,V>>
-
- EntryStream<K,V>
-
- Type Parameters:
K- the type ofEntrykeysV- the type ofEntryvalues
- All Implemented Interfaces:
AutoCloseable,Iterable<Map.Entry<K,V>>,BaseStream<Map.Entry<K,V>,Stream<Map.Entry<K,V>>>,Stream<Map.Entry<K,V>>
public class EntryStream<K,V> extends AbstractStreamEx<Map.Entry<K,V>,EntryStream<K,V>>
AStreamofMap.Entryobjects which provides additional specific functionality.While
EntryStreamimplementsIterable, it is not a general-purposeIterableas it supports only a singleIterator; invoking theiteratormethod to obtain a second or subsequent iterator throwsIllegalStateException.- Author:
- Tagir Valeev
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface Stream
Stream.Builder<T extends Object>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallMatch(BiPredicate<? super K,? super V> predicate)Returns whether all elements of this stream match the provided predicate.booleananyMatch(BiPredicate<? super K,? super V> predicate)Returns whether any elements of this stream match the provided predicate.EntryStream<K,V>append(Map<K,V> map)Returns a newEntryStreamwhich is a concatenation of this stream and the stream created from the supplied map entries.EntryStream<K,V>append(K key, V value)Returns a newEntryStreamwhich is a concatenation of this stream and the supplied key-value pair.EntryStream<K,V>append(K k1, V v1, K k2, V v2)Returns a newEntryStreamwhich is a concatenation of this stream and two supplied key-value pairs.EntryStream<K,V>append(K k1, V v1, K k2, V v2, K k3, V v3)Returns a newEntryStreamwhich is a concatenation of this stream and three supplied key-value pairs.voidclose()EntryStream<K,List<V>>collapseKeys()Merge series of adjacent stream entries with equal keys grouping the corresponding values intoList.EntryStream<K,V>collapseKeys(BinaryOperator<V> merger)Merge series of adjacent stream entries with equal keys combining the corresponding values using the provided function.<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 providedCollector.EntryStream<K,V>distinctKeys()Returns a stream consisting of the elements of this stream which have distinct keys (according to object equality).EntryStream<K,V>distinctValues()Returns a stream consisting of the elements of this stream which have distinct values (according to object equality).static <K,V>
EntryStream<K,V>empty()Returns an empty sequentialEntryStream.EntryStream<K,V>filterKeys(Predicate<? super K> keyPredicate)Returns a stream consisting of the elements of this stream which keys match the given predicate.EntryStream<K,V>filterKeyValue(BiPredicate<? super K,? super V> predicate)Returns a stream consisting of the elements of this stream which elements match the given predicate.EntryStream<K,V>filterValues(Predicate<? super V> valuePredicate)Returns a stream consisting of the elements of this stream which values match the given predicate.<KK> EntryStream<KK,V>flatMapKeys(Function<? super K,? extends Stream<? extends KK>> mapper)Returns anEntryStreamconsisting 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.<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.<KK> EntryStream<KK,V>flatMapToKey(BiFunction<? super K,? super V,? extends Stream<? extends KK>> mapper)Returns anEntryStreamconsisting 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.<VV> EntryStream<K,VV>flatMapToValue(BiFunction<? super K,? super V,? extends Stream<? extends VV>> mapper)Returns anEntryStreamconsisting 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.<VV> EntryStream<K,VV>flatMapValues(Function<? super V,? extends Stream<? extends VV>> mapper)Returns anEntryStreamconsisting 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.voidforKeyValue(BiConsumer<? super K,? super V> action)Performs an action for each key-value pair of this stream.static <K,V>
EntryStream<K,V>generate(Supplier<? extends K> keySupplier, Supplier<? extends V> valueSupplier)Returns an infinite sequential unorderedEntryStreamwhere each entry key is generated by the providedkeySupplierand each entry value is generated by the providedvalueSupplier.Map<K,List<V>>grouping()Returns aMapwhere elements of this stream with the same key are grouped together.<M extends Map<K,List<V>>>
Mgrouping(Supplier<M> mapSupplier)Returns aMapwhere elements of this stream with the same key are grouped together.<A,D,M extends Map<K,D>>
Mgrouping(Supplier<M> mapSupplier, Collector<? super V,A,D> downstream)Returns aMapwhere elements of this stream with the same key are grouped together.<A,D>
Map<K,D>grouping(Collector<? super V,A,D> downstream)Returns aMapwhere elements of this stream with the same key are grouped together.<C extends Collection<V>>
Map<K,C>groupingTo(Supplier<C> collectionFactory)Returns aMapwhere elements of this stream with the same key are grouped together.<C extends Collection<V>,M extends Map<K,C>>
MgroupingTo(Supplier<M> mapSupplier, Supplier<C> collectionFactory)Returns aMapwhere elements of this stream with the same key are grouped together.<M extends Map<K,V>>
Minto(M map)Drains the stream content into the suppliedMap.EntryStream<V,K>invert()Returns a stream consisting of theMap.Entryobjects which keys are the values of this stream elements and vice versa.booleanisParallel()StreamEx<String>join(CharSequence delimiter)Returns aStreamExof strings which are created joining the keys and values of the current stream using the specified delimiter.StreamEx<String>join(CharSequence delimiter, CharSequence prefix, CharSequence suffix)Returns aStreamExof strings which are created joining the keys and values of the current stream using the specified delimiter, with the specified prefix and suffix.StreamEx<K>keys()Returns a stream consisting of the keys of this stream elements.<KK> EntryStream<KK,V>mapKeys(Function<? super K,? extends KK> keyMapper)Returns anEntryStreamconsisting of the entries whose keys are modified by applying the given function and values are left unchanged.<R> StreamEx<R>mapKeyValue(BiFunction<? super K,? super V,? extends R> mapper)Returns aStreamExconsisting of the results of applying the given function to the keys and values of this stream.<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.<KK> EntryStream<KK,V>mapToKey(BiFunction<? super K,? super V,? extends KK> keyMapper)Returns anEntryStreamconsisting of the entries whose keys are modified by applying the given function and values are left unchanged.<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.<VV> EntryStream<K,VV>mapToValue(BiFunction<? super K,? super V,? extends VV> valueMapper)Returns anEntryStreamconsisting of the entries whose keys are left unchanged and values are modified by applying the given function.<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.<VV> EntryStream<K,VV>mapValues(Function<? super V,? extends VV> valueMapper)Returns anEntryStreamconsisting of the entries whose keys are left unchanged and values are modified by applying the given function.booleannoneMatch(BiPredicate<? super K,? super V> predicate)Returns whether no elements of this stream match the provided predicate.EntryStream<K,V>nonNullKeys()Returns a stream consisting of the elements of this stream which key is not null.EntryStream<K,V>nonNullValues()Returns a stream consisting of the elements of this stream which value is not null.static <K,V>
EntryStream<K,V>of(Iterator<? extends Map.Entry<K,V>> iterator)Returns a sequential, orderedEntryStreamcreated from givenIterator.static <V> EntryStream<Integer,V>of(List<V> list)Returns anEntryStreamobject whose keys are indices of given list and the values are the corresponding list elements.static <K,V>
EntryStream<K,V>of(Map<K,V> map)Returns anEntryStreamobject which contains the entries of suppliedMap.static <K,V>
EntryStream<K,V>of(Spliterator<? extends Map.Entry<K,V>> spliterator)Returns a sequentialEntryStreamcreated from givenSpliterator.static <K,V>
EntryStream<K,V>of(Stream<? extends Map.Entry<K,V>> stream)static <K,V>
EntryStream<K,V>of(K key, V value)Returns a sequentialEntryStreamcontaining a single key-value pairstatic <K,V>
EntryStream<K,V>of(K k1, V v1, K k2, V v2)Returns a sequentialEntryStreamcontaining two key-value pairsstatic <K,V>
EntryStream<K,V>of(K k1, V v1, K k2, V v2, K k3, V v3)Returns a sequentialEntryStreamcontaining three key-value pairsstatic <K,V>
EntryStream<K,V>of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)Returns a sequentialEntryStreamcontaining four key-value pairsstatic <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 sequentialEntryStreamcontaining five key-value pairsstatic <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 sequentialEntryStreamcontaining six key-value pairsstatic <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 sequentialEntryStreamcontaining seven key-value pairsstatic <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 sequentialEntryStreamcontaining eight key-value pairsstatic <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 sequentialEntryStreamcontaining nine key-value pairsstatic <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 sequentialEntryStreamcontaining ten key-value pairsstatic <V> EntryStream<Integer,V>of(V[] array)Returns anEntryStreamobject whose keys are indices of given array and the values are the corresponding array elements.static <T> EntryStream<T,T>ofPairs(List<T> list)Returns a sequential orderedEntryStreamcontaining the possible pairs of elements taken from the provided list.static <T> EntryStream<T,T>ofPairs(T[] array)Returns a sequential orderedEntryStreamcontaining the possible pairs of elements taken from the provided array.static <T,TT extends T>
EntryStream<Integer,T>ofTree(T root, Class<TT> collectionClass, BiFunction<Integer,TT,Stream<T>> mapper)Return a newEntryStreamcontaining all the nodes of tree-like data structure in entry values along with the corresponding tree depths in entry keys, in depth-first order.static <T> EntryStream<Integer,T>ofTree(T root, BiFunction<Integer,T,Stream<T>> mapper)Return a newEntryStreamcontaining all the nodes of tree-like data structure in entry values along with the corresponding tree depths in entry keys, in depth-first order.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.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.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.EntryStream<K,V>prefixKeys(BinaryOperator<K> op)Returns a newEntryStreamwhich values are the same as this stream values and keys are the results of applying the accumulation function to this stream keys, going left to right.EntryStream<K,V>prefixValues(BinaryOperator<V> op)Returns a newEntryStreamwhich keys are the same as this stream keys and values are the results of applying the accumulation function to this stream values, going left to right.EntryStream<K,V>prepend(Map<K,V> map)Returns a newEntryStreamwhich is a concatenation of the stream created from the supplied map entries and this stream.EntryStream<K,V>prepend(K key, V value)Returns a newEntryStreamwhich is a concatenation of the supplied key-value pair and this stream.EntryStream<K,V>prepend(K k1, V v1, K k2, V v2)Returns a newEntryStreamwhich is a concatenation of two supplied key-value pairs and this stream.EntryStream<K,V>prepend(K k1, V v1, K k2, V v2, K k3, V v3)Returns a newEntryStreamwhich is a concatenation of three supplied key-value pairs and this stream.EntryStream<K,V>removeKeys(Predicate<? super K> keyPredicate)Returns a stream consisting of the elements of this stream which keys don't match the given predicate.EntryStream<K,V>removeKeyValue(BiPredicate<? super K,? super V> predicate)Returns a stream consisting of the elements of this stream which values don't match the given predicate.EntryStream<K,V>removeValues(Predicate<? super V> valuePredicate)Returns a stream consisting of the elements of this stream which values don't match the given predicate.<KK> EntryStream<KK,V>selectKeys(Class<KK> clazz)Returns a stream consisting of the elements of this stream which keys are instances of given class.<VV> EntryStream<K,VV>selectValues(Class<VV> clazz)Returns a stream consisting of the elements of this stream which values are instances of given class.EntryStream<K,V>sorted()Spliterator<Map.Entry<K, V>>spliterator()<M extends Map<K,V>>
MtoCustomMap(BinaryOperator<V> mergeFunction, Supplier<M> mapSupplier)Returns aMapcontaining the elements of this stream.<M extends Map<K,V>>
MtoCustomMap(Supplier<M> mapSupplier)Returns aMapcontaining the elements of this stream.Map<K,V>toImmutableMap()Returns an immutableMapcontaining the elements of this stream.Map<K,V>toMap()Returns aMapcontaining the elements of this stream.Map<K,V>toMap(BinaryOperator<V> mergeFunction)Returns aMapcontaining the elements of this stream.<R> RtoMapAndThen(Function<? super Map<K,V>,R> finisher)Creates aMapcontaining the elements of this stream, then performs finishing transformation and returns its result.NavigableMap<K,V>toNavigableMap()Returns aNavigableMapcontaining the elements of this stream.NavigableMap<K,V>toNavigableMap(BinaryOperator<V> mergeFunction)Returns aNavigableMapcontaining the elements of this stream.SortedMap<K,V>toSortedMap()Returns aSortedMapcontaining the elements of this stream.SortedMap<K,V>toSortedMap(BinaryOperator<V> mergeFunction)Returns aSortedMapcontaining the elements of this stream.StreamEx<V>values()Returns a stream consisting of the values of this stream elements.static <K,V>
EntryStream<K,V>zip(List<K> keys, List<V> values)Returns a sequentialEntryStreamcontainingEntryobjects composed from corresponding key and value in given two lists.static <K,V>
EntryStream<K,V>zip(K[] keys, V[] values)Returns a sequentialEntryStreamcontainingEntryobjects composed from corresponding key and value in given two arrays.-
Methods inherited from class AbstractStreamEx
allMatch, anyMatch, append, chain, collect, collect, count, distinct, distinct, distinct, dropWhile, filter, findAny, findAny, findFirst, findFirst, flatArray, flatCollection, flatMap, flatMapToDouble, flatMapToInt, flatMapToLong, foldLeft, foldLeft, foldRight, foldRight, forEach, forEachOrdered, ifEmpty, indexOf, indexOf, intersperse, iterator, limit, map, mapPartial, mapToDouble, mapToInt, mapToLong, max, maxBy, maxByDouble, maxByInt, maxByLong, min, minBy, minByDouble, minByInt, minByLong, noneMatch, nonNull, onClose, pairMap, parallel, parallel, peek, prefix, prepend, reduce, reduce, reduce, reduceWithZero, reduceWithZero, remove, reverseSorted, scanLeft, scanLeft, scanRight, scanRight, sequential, skip, sorted, sortedBy, sortedByDouble, sortedByInt, sortedByLong, takeWhile, takeWhileInclusive, toArray, toArray, toCollection, toCollectionAndThen, toImmutableList, toImmutableSet, toList, toListAndThen, toSet, toSetAndThen, unordered
-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface BaseStream
close, isParallel, spliterator
-
Methods inherited from interface Iterable
spliterator
-
-
-
-
Method Detail
-
join
public StreamEx<String> join(CharSequence delimiter)
Returns aStreamExof 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 aStreamExof 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 valueprefix- the sequence of characters to be used at the beginning of each resulting stringsuffix- 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 anEntryStreamconsisting 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 isclosedafter its contents have been placed into this stream. (If a mapped stream isnullan 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 anEntryStreamconsisting 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 isclosedafter its contents have been placed into this stream. (If a mapped stream isnullan 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 anEntryStreamconsisting 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 isclosedafter its contents have been placed into this stream. (If a mapped stream isnullan 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 anEntryStreamconsisting 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 isclosedafter its contents have been placed into this stream. (If a mapped stream isnullan 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 isnullan 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 newEntryStreamwhich 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 newEntryStreamwhich is a concatenation of this stream and the supplied key-value pair.This is a quasi-intermediate operation.
- Parameters:
key- the key of the newEntryto append to this streamvalue- the value of the newEntryto append to this stream- Returns:
- the new stream
-
append
public EntryStream<K,V> append(K k1, V v1, K k2, V v2)
Returns a newEntryStreamwhich is a concatenation of this stream and two supplied key-value pairs.This is a quasi-intermediate operation.
- Parameters:
k1- the key of the firstEntryto append to this streamv1- the value of the firstEntryto append to this streamk2- the key of the secondEntryto append to this streamv2- the value of the secondEntryto 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 newEntryStreamwhich is a concatenation of this stream and three supplied key-value pairs.This is a quasi-intermediate operation.
- Parameters:
k1- the key of the firstEntryto append to this streamv1- the value of the firstEntryto append to this streamk2- the key of the secondEntryto append to this streamv2- the value of the secondEntryto append to this streamk3- the key of the thirdEntryto append to this streamv3- the value of the thirdEntryto append to this stream- Returns:
- the new stream
- Since:
- 0.2.3
-
prepend
public EntryStream<K,V> prepend(Map<K,V> map)
Returns a newEntryStreamwhich 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 newEntryStreamwhich 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 newEntryto prepend to this streamvalue- the value of the newEntryto prepend to this stream- Returns:
- the new stream
-
prepend
public EntryStream<K,V> prepend(K k1, V v1, K k2, V v2)
Returns a newEntryStreamwhich 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 firstEntryto prepend to this streamv1- the value of the firstEntryto prepend to this streamk2- the key of the secondEntryto prepend to this streamv2- the value of the secondEntryto 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 newEntryStreamwhich 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 firstEntryto prepend to this streamv1- the value of the firstEntryto prepend to this streamk2- the key of the secondEntryto prepend to this streamv2- the value of the secondEntryto prepend to this streamk3- the key of the thirdEntryto prepend to this streamv3- the value of the thirdEntryto 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 anEntryStreamconsisting 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 anEntryStreamconsisting 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 aStreamExconsisting 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 eachMap.Entryin 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 anEntryStreamconsisting 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 anEntryStreamconsisting 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 theMap.Entryobjects which keys are the values of this stream elements and vice versa.This is an intermediate operation.
- Returns:
- the new stream
-
filterKeys
public EntryStream<K,V> filterKeys(Predicate<? super K> keyPredicate)
Returns a stream consisting of the elements of this stream which keys match the given predicate.This is an intermediate operation.
- Parameters:
keyPredicate- a non-interfering, stateless predicate to apply to the key of each element to determine if it should be included- Returns:
- the new stream
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class),selectValues(Class)
-
filterValues
public EntryStream<K,V> filterValues(Predicate<? super V> valuePredicate)
Returns a stream consisting of the elements of this stream which values match the given predicate.This is an intermediate operation.
- Parameters:
valuePredicate- a non-interfering, stateless predicate to apply to the value of each element to determine if it should be included- Returns:
- the new stream
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class),selectValues(Class)
-
filterKeyValue
public EntryStream<K,V> filterKeyValue(BiPredicate<? super K,? super V> predicate)
Returns a stream consisting of the elements of this stream which elements match the given predicate.This is an intermediate operation.
- Parameters:
predicate- a non-interfering, stateless predicate to apply to the key-value pairs of each element to determine if it should be included- Returns:
- the new stream
- Since:
- 0.3.0
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class),selectValues(Class)
-
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 thenfalseis 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:
trueif any elements of the stream match the provided predicate, otherwisefalse- 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 thentrueis 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:
trueif either all elements of the stream match the provided predicate or the stream is empty, otherwisefalse- 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 thentrueis 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:
trueif either no elements of the stream match the provided predicate or the stream is empty, otherwisefalse- Since:
- 0.7.0
-
removeKeys
public EntryStream<K,V> removeKeys(Predicate<? super K> keyPredicate)
Returns a stream consisting of the elements of this stream which keys don't match the given predicate.This is an intermediate operation.
- Parameters:
keyPredicate- a non-interfering, stateless predicate to apply to the key of each element to determine if it should be excluded- Returns:
- the new stream
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class),selectValues(Class)
-
removeValues
public EntryStream<K,V> removeValues(Predicate<? super V> valuePredicate)
Returns a stream consisting of the elements of this stream which values don't match the given predicate.This is an intermediate operation.
- Parameters:
valuePredicate- a non-interfering, stateless predicate to apply to the value of each element to determine if it should be excluded- Returns:
- the new stream
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class),selectValues(Class)
-
removeKeyValue
public EntryStream<K,V> removeKeyValue(BiPredicate<? super K,? super V> predicate)
Returns a stream consisting of the elements of this stream which values don't match the given predicate.This is an intermediate operation.
- Parameters:
predicate- a non-interfering, stateless predicate to apply to the key-value pairs of each element to determine if it should be excluded- Returns:
- the new stream
- Since:
- 0.6.0
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class),selectValues(Class)
-
nonNullKeys
public EntryStream<K,V> nonNullKeys()
Returns a stream consisting of the elements of this stream which key is not null.This is an intermediate operation.
- Returns:
- the new stream
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class),selectValues(Class)
-
nonNullValues
public EntryStream<K,V> nonNullValues()
Returns a stream consisting of the elements of this stream which value is not null.This is an intermediate operation.
- Returns:
- the new stream
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class),selectValues(Class)
-
selectKeys
public <KK> EntryStream<KK,V> selectKeys(Class<KK> clazz)
Returns a stream consisting of the elements of this stream which keys are instances of given class.This is an intermediate operation.
- Type Parameters:
KK- a type of keys to select.- Parameters:
clazz- a class to filter the keys.- Returns:
- the new stream
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectValues(Class)
-
selectValues
public <VV> EntryStream<K,VV> selectValues(Class<VV> clazz)
Returns a stream consisting of the elements of this stream which values are instances of given class.This is an intermediate operation.
- Type Parameters:
VV- a type of values to select.- Parameters:
clazz- a class to filter the values.- Returns:
- the new stream
- See Also:
AbstractStreamEx.nonNull(),AbstractStreamEx.filter(Predicate),AbstractStreamEx.remove(Predicate),selectKeys(Class)
-
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, becauseMap.Entryinstances rarely implement theComparableinterface. If you want to sort the stream by Map keys usesorted(Map.Entry.comparingByKey())orsortedBy(Map.Entry::getKey). If you want to sort the stream by Map values usesorted(Map.Entry.comparingByValue())orsortedBy(Map.Entry::getValue).
-
collapseKeys
public EntryStream<K,List<V>> collapseKeys()
Merge series of adjacent stream entries with equal keys grouping the corresponding values intoList.This is a quasi-intermediate partial reduction operation.
There are no guarantees on the type, mutability, serializability, or thread-safety of the
Listobjects of the resulting stream.The key of the resulting entry is the key of the first merged entry.
- Returns:
- a new
EntryStreamwhich keys are the keys of the original stream and the values of adjacent entries with the same keys are grouped intoList - 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
EntryStreamwhich 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 providedCollector.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 streamA- the intermediate accumulation type of theCollector- Parameters:
collector- aCollectorwhich is used to combine the values of the adjacent entries with the equal keys.- Returns:
- a new
EntryStreamwhich 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)
-
prefixKeys
public EntryStream<K,V> prefixKeys(BinaryOperator<K> op)
Returns a newEntryStreamwhich values are the same as this stream values and keys are the results of applying the accumulation function to this stream keys, going left to right.This is a stateful quasi-intermediate operation.
This method cannot take all the advantages of parallel streams as it must process elements strictly left to right. Using an unordered source or removing the ordering constraint with
AbstractStreamEx.unordered()may improve the parallel processing speed.- Parameters:
op- an associative , non-interfering , stateless function for computing the next key based on the previous one- Returns:
- the new stream.
- Since:
- 0.6.4
- See Also:
AbstractStreamEx.prefix(BinaryOperator),prefixValues(BinaryOperator)
-
prefixValues
public EntryStream<K,V> prefixValues(BinaryOperator<V> op)
Returns a newEntryStreamwhich keys are the same as this stream keys and values are the results of applying the accumulation function to this stream values, going left to right.This is a stateful quasi-intermediate operation.
This method cannot take all the advantages of parallel streams as it must process elements strictly left to right. Using an unordered source or removing the ordering constraint with
AbstractStreamEx.unordered()may improve the parallel processing speed.- Parameters:
op- an associative , non-interfering , stateless function for computing the next value based on the previous one- Returns:
- the new stream.
- Since:
- 0.6.4
- See Also:
AbstractStreamEx.prefix(BinaryOperator),prefixKeys(BinaryOperator)
-
toMap
public Map<K,V> toMap()
Returns aMapcontaining the elements of this stream. There are no guarantees on the type or serializability of theMapreturned; if more control over the returnedMapis required, usetoCustomMap(Supplier).This is a terminal operation.
Returned
Mapis guaranteed to be modifiable.For parallel stream the concurrent
Mapis created.- Returns:
- a
Mapcontaining the elements of this stream - Throws:
IllegalStateException- if this stream contains duplicate keys (according toObject.equals(Object))- See Also:
Collectors.toMap(Function, Function),Collectors.toConcurrentMap(Function, Function),toImmutableMap()
-
toImmutableMap
public Map<K,V> toImmutableMap()
Returns an immutableMapcontaining the elements of this stream. There's no guarantees on exact type of the returnedMap. In particular, no specific element order in the resultingMapis guaranteed. The returnedMapis guaranteed to be serializable if all its elements are serializable.This is a terminal operation.
- Returns:
- a
Mapcontaining the elements of this stream - Throws:
IllegalStateException- if this stream contains duplicate keys (according toObject.equals(Object))- Since:
- 0.6.3
- See Also:
toMap()
-
toMapAndThen
public <R> R toMapAndThen(Function<? super Map<K,V>,R> finisher)
Creates aMapcontaining the elements of this stream, then performs finishing transformation and returns its result. There are no guarantees on the type or serializability of theMapcreated.This is a terminal operation.
Created
Mapis guaranteed to be modifiable.For parallel stream the concurrent
Mapis 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
Mapof the stream elements. - Throws:
IllegalStateException- if this stream contains duplicate keys (according toObject.equals(Object))- Since:
- 0.5.5
- See Also:
toMap()
-
toMap
public Map<K,V> toMap(BinaryOperator<V> mergeFunction)
Returns aMapcontaining the elements of this stream. There are no guarantees on the type or serializability of theMapreturned; if more control over the returnedMapis required, usetoCustomMap(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
Mapis guaranteed to be modifiable.- Parameters:
mergeFunction- a merge function, used to resolve collisions between values associated with the same key, as supplied toMap.merge(Object, Object, BiFunction)- Returns:
- a
Mapcontaining the elements of this stream - Since:
- 0.1.0
- See Also:
Collectors.toMap(Function, Function),Collectors.toConcurrentMap(Function, Function)
-
toCustomMap
public <M extends Map<K,V>> M toCustomMap(Supplier<M> mapSupplier)
Returns aMapcontaining the elements of this stream. TheMapis created by a provided supplier function.This is a terminal operation.
- Type Parameters:
M- the type of the resulting map- Parameters:
mapSupplier- a function which returns a new, emptyMapinto which the results will be inserted- Returns:
- a
Mapcontaining the elements of this stream - Throws:
IllegalStateException- if this stream contains duplicate keys (according toObject.equals(Object))- See Also:
Collectors.toMap(Function, Function),Collectors.toConcurrentMap(Function, Function)
-
toCustomMap
public <M extends Map<K,V>> M toCustomMap(BinaryOperator<V> mergeFunction, Supplier<M> mapSupplier)
Returns aMapcontaining the elements of this stream. TheMapis 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, emptyMapinto which the results will be inserted- Returns:
- a
Mapcontaining the elements of this stream - See Also:
Collectors.toMap(Function, Function),Collectors.toConcurrentMap(Function, Function)
-
toSortedMap
public SortedMap<K,V> toSortedMap()
Returns aSortedMapcontaining the elements of this stream. There are no guarantees on the type or serializability of theSortedMapreturned; if more control over the returnedMapis required, usetoCustomMap(Supplier).This is a terminal operation.
Returned
SortedMapis guaranteed to be modifiable.For parallel stream the concurrent
SortedMapis created.- Returns:
- a
SortedMapcontaining the elements of this stream - Throws:
IllegalStateException- if this stream contains duplicate keys (according toObject.equals(Object))- Since:
- 0.1.0
- See Also:
toNavigableMap()
-
toSortedMap
public SortedMap<K,V> toSortedMap(BinaryOperator<V> mergeFunction)
Returns aSortedMapcontaining the elements of this stream. There are no guarantees on the type or serializability of theSortedMapreturned; if more control over the returnedMapis required, usetoCustomMap(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
SortedMapis guaranteed to be modifiable.- Parameters:
mergeFunction- a merge function, used to resolve collisions between values associated with the same key, as supplied toMap.merge(Object, Object, BiFunction)- Returns:
- a
SortedMapcontaining the elements of this stream - Since:
- 0.1.0
- See Also:
toNavigableMap(BinaryOperator)
-
toNavigableMap
public NavigableMap<K,V> toNavigableMap()
Returns aNavigableMapcontaining the elements of this stream. There are no guarantees on the type or serializability of theNavigableMapreturned; if more control over the returnedMapis required, usetoCustomMap(Supplier).This is a terminal operation.
Returned
NavigableMapis guaranteed to be modifiable.For parallel stream the concurrent
NavigableMapis created.- Returns:
- a
NavigableMapcontaining the elements of this stream - Throws:
IllegalStateException- if this stream contains duplicate keys (according toObject.equals(Object))- Since:
- 0.6.5
- See Also:
Collectors.toMap(Function, Function),Collectors.toConcurrentMap(Function, Function)
-
toNavigableMap
public NavigableMap<K,V> toNavigableMap(BinaryOperator<V> mergeFunction)
Returns aNavigableMapcontaining the elements of this stream. There are no guarantees on the type or serializability of theNavigableMapreturned; if more control over the returnedMapis required, usetoCustomMap(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
NavigableMapis guaranteed to be modifiable.- Parameters:
mergeFunction- a merge function, used to resolve collisions between values associated with the same key, as supplied toMap.merge(Object, Object, BiFunction)- Returns:
- a
NavigableMapcontaining 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 suppliedMap.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 toObject.equals(Object))- Since:
- 0.6.3
-
grouping
public Map<K,List<V>> grouping()
Returns aMapwhere elements of this stream with the same key are grouped together. The resultingMapkeys 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
MaporListobjects returned. If more control over the returnedMapis required, usegrouping(Supplier). If more control over the lists required, usegroupingTo(Supplier).This is a terminal operation.
- Returns:
- a
Mapcontaining the elements of this stream - See Also:
Collectors.groupingBy(Function)
-
grouping
public <M extends Map<K,List<V>>> M grouping(Supplier<M> mapSupplier)
Returns aMapwhere elements of this stream with the same key are grouped together. The resultingMapkeys are the keys of this stream entries and the values are the lists of the corresponding values. TheMapis created using the provided supplier function.There are no guarantees on the type, mutability, serializability, or thread-safety of the
Listobjects returned. If more control over the lists required, usegroupingTo(Supplier).This is a terminal operation.
- Type Parameters:
M- the type of the resultingMap- Parameters:
mapSupplier- a function which returns a new, emptyMapinto which the results will be inserted- Returns:
- a
Mapcontaining 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 aMapwhere elements of this stream with the same key are grouped together. The resultingMapkeys 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
Mapobject returned. If more control over the returnedMapis required, usegrouping(Supplier, Collector).This is a terminal operation.
- Type Parameters:
A- the intermediate accumulation type of the downstream collectorD- the result type of the downstream reduction- Parameters:
downstream- aCollectorimplementing the downstream reduction- Returns:
- a
Mapcontaining 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 aMapwhere elements of this stream with the same key are grouped together. The resultingMapkeys are the keys of this stream entries and the corresponding values are combined using the provided downstream collector. TheMapis created using the provided supplier function.This is a terminal operation.
- Type Parameters:
A- the intermediate accumulation type of the downstream collectorD- the result type of the downstream reductionM- the type of the resultingMap- Parameters:
mapSupplier- a function which returns a new, emptyMapinto which the results will be inserteddownstream- aCollectorimplementing the downstream reduction- Returns:
- a
Mapcontaining 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 aMapwhere elements of this stream with the same key are grouped together. The resultingMapkeys 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
Mapobject returned. If more control over the returnedMapis required, usegroupingTo(Supplier, Supplier).This is a terminal operation.
- Type Parameters:
C- the type of the resultingCollection- Parameters:
collectionFactory- aSupplierwhich returns a new, emptyCollectionof the appropriate type- Returns:
- a
Mapcontaining 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 aMapwhere elements of this stream with the same key are grouped together. The resultingMapkeys 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 resultingCollectionM- the type of the resultingMap- Parameters:
mapSupplier- a function which returns a new, emptyMapinto which the results will be insertedcollectionFactory- aSupplierwhich returns a new, emptyCollectionof the appropriate type- Returns:
- a
Mapcontaining 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 sequentialEntryStream.- Type Parameters:
K- the type of stream element keysV- 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)
- Type Parameters:
K- the type of original stream keysV- 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 sequentialEntryStreamcreated from givenSpliterator.- Type Parameters:
K- the type of stream keysV- 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, orderedEntryStreamcreated from givenIterator.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
CollectionorSpliterator).- Type Parameters:
K- the type of stream keysV- 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 anEntryStreamobject which contains the entries of suppliedMap.- Type Parameters:
K- the type of map keysV- 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 anEntryStreamobject 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 anEntryStreamobject 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 sequentialEntryStreamcontaining a single key-value pair- Type Parameters:
K- the type of keyV- the type of value- Parameters:
key- the key of the single elementvalue- 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 sequentialEntryStreamcontaining two key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- 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 sequentialEntryStreamcontaining three key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- the value of the second elementk3- the key of the third elementv3- 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 sequentialEntryStreamcontaining four key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- the value of the second elementk3- the key of the third elementv3- the value of the third elementk4- the key of the fourth elementv4- 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 sequentialEntryStreamcontaining five key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- the value of the second elementk3- the key of the third elementv3- the value of the third elementk4- the key of the fourth elementv4- the value of the fourth elementk5- the key of the fifth elementv5- 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 sequentialEntryStreamcontaining six key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- the value of the second elementk3- the key of the third elementv3- the value of the third elementk4- the key of the fourth elementv4- the value of the fourth elementk5- the key of the fifth elementv5- the value of the fifth elementk6- the key of the sixth elementv6- 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 sequentialEntryStreamcontaining seven key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- the value of the second elementk3- the key of the third elementv3- the value of the third elementk4- the key of the fourth elementv4- the value of the fourth elementk5- the key of the fifth elementv5- the value of the fifth elementk6- the key of the sixth elementv6- the value of the sixth elementk7- the key of the seventh elementv7- 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 sequentialEntryStreamcontaining eight key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- the value of the second elementk3- the key of the third elementv3- the value of the third elementk4- the key of the fourth elementv4- the value of the fourth elementk5- the key of the fifth elementv5- the value of the fifth elementk6- the key of the sixth elementv6- the value of the sixth elementk7- the key of the seventh elementv7- the value of the seventh elementk8- the key of the eighth elementv8- 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 sequentialEntryStreamcontaining nine key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- the value of the second elementk3- the key of the third elementv3- the value of the third elementk4- the key of the fourth elementv4- the value of the fourth elementk5- the key of the fifth elementv5- the value of the fifth elementk6- the key of the sixth elementv6- the value of the sixth elementk7- the key of the seventh elementv7- the value of the seventh elementk8- the key of the eighth elementv8- the value of the eighth elementk9- the key of the ninth elementv9- 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 sequentialEntryStreamcontaining ten key-value pairs- Type Parameters:
K- the type of keyV- the type of value- Parameters:
k1- the key of the first elementv1- the value of the first elementk2- the key of the second elementv2- the value of the second elementk3- the key of the third elementv3- the value of the third elementk4- the key of the fourth elementv4- the value of the fourth elementk5- the key of the fifth elementv5- the value of the fifth elementk6- the key of the sixth elementv6- the value of the sixth elementk7- the key of the seventh elementv7- the value of the seventh elementk8- the key of the eighth elementv8- the value of the eighth elementk9- the key of the ninth elementv9- the value of the ninth elementk10- the key of the tenth elementv10- 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 sequentialEntryStreamcontainingEntryobjects 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 keysV- the type of stream element values- Parameters:
keys- the list of keys, assumed to be unmodified during usevalues- 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 sequentialEntryStreamcontainingEntryobjects composed from corresponding key and value in given two arrays.- Type Parameters:
K- the type of stream element keysV- the type of stream element values- Parameters:
keys- the array of keysvalues- 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 orderedEntryStreamcontaining 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))andMap.Entry(list.get(1), list.get(2)). The number of elements in the resulting stream islist.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 orderedEntryStreamcontaining 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])andMap.Entry(array[1], array[2]). The number of elements in the resulting stream isarray.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 newEntryStreamcontaining 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
closedafter 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 theclose()method of the resulting stream returned byofTree().- Type Parameters:
T- the type of tree nodes- Parameters:
root- root node of the treemapper- 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 newEntryStreamcontaining 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
closedafter 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 theclose()method of the resulting stream returned byofTree().- Type Parameters:
T- the base type of tree nodesTT- the sub-type of composite tree nodes which may have children- Parameters:
root- root node of the treecollectionClass- a class representing the composite tree nodemapper- 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 unorderedEntryStreamwhere each entry key is generated by the providedkeySupplierand each entry value is generated by the providedvalueSupplier. This is suitable for generating constant streams, streams of random elements, etc.- Type Parameters:
K- the type of stream element keysV- the type of stream element values- Parameters:
keySupplier- the supplier to generate keys for the new streamvalueSupplier- 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)
-
spliterator
public Spliterator<Map.Entry<K, V>> spliterator()
- Specified by:
spliteratorin interfaceBaseStream<T,S extends BaseStream<T,S>>
-
isParallel
public boolean isParallel()
- Specified by:
isParallelin interfaceBaseStream<T,S extends BaseStream<T,S>>
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBaseStream<T,S extends BaseStream<T,S>>
-
-