Class EntryStream<K,V>
- Object
-
- AbstractStreamEx<Map.Entry<K,V>,EntryStream<K,V>>
-
- EntryStream<K,V>
-
- Type Parameters:
K
- the type ofEntry
keysV
- the type ofEntry
values
- 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>>
AStream
ofMap.Entry
objects which provides additional specific functionality.While
EntryStream
implementsIterable
, it is not a general-purposeIterable
as it supports only a singleIterator
; invoking theiterator
method 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 boolean
allMatch(BiPredicate<? super K,? super V> predicate)
Returns whether all elements of this stream match the provided predicate.boolean
anyMatch(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 newEntryStream
which 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 newEntryStream
which 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 newEntryStream
which 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 newEntryStream
which is a concatenation of this stream and three supplied key-value pairs.void
close()
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 anEntryStream
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.<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 anEntryStream
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.<VV> EntryStream<K,VV>
flatMapToValue(BiFunction<? super K,? super V,? extends Stream<? extends VV>> mapper)
Returns anEntryStream
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.<VV> EntryStream<K,VV>
flatMapValues(Function<? super V,? extends Stream<? extends VV>> mapper)
Returns anEntryStream
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.void
forKeyValue(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 unorderedEntryStream
where each entry key is generated by the providedkeySupplier
and each entry value is generated by the providedvalueSupplier
.Map<K,List<V>>
grouping()
Returns aMap
where elements of this stream with the same key are grouped together.<M extends Map<K,List<V>>>
Mgrouping(Supplier<M> mapSupplier)
Returns aMap
where 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 aMap
where elements of this stream with the same key are grouped together.<A,D>
Map<K,D>grouping(Collector<? super V,A,D> downstream)
Returns aMap
where elements of this stream with the same key are grouped together.<C extends Collection<V>>
Map<K,C>groupingTo(Supplier<C> collectionFactory)
Returns aMap
where 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 aMap
where 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.Entry
objects which keys are the values of this stream elements and vice versa.boolean
isParallel()
StreamEx<String>
join(CharSequence delimiter)
Returns aStreamEx
of 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 aStreamEx
of 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 anEntryStream
consisting 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 aStreamEx
consisting 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 anEntryStream
consisting 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 anEntryStream
consisting 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 anEntryStream
consisting of the entries whose keys are left unchanged and values are modified by applying the given function.boolean
noneMatch(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, orderedEntryStream
created from givenIterator
.static <V> EntryStream<Integer,V>
of(List<V> list)
Returns anEntryStream
object 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 anEntryStream
object which contains the entries of suppliedMap
.static <K,V>
EntryStream<K,V>of(Spliterator<? extends Map.Entry<K,V>> spliterator)
Returns a sequentialEntryStream
created 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 sequentialEntryStream
containing a single key-value pairstatic <K,V>
EntryStream<K,V>of(K k1, V v1, K k2, V v2)
Returns a sequentialEntryStream
containing two key-value pairsstatic <K,V>
EntryStream<K,V>of(K k1, V v1, K k2, V v2, K k3, V v3)
Returns a sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing ten key-value pairsstatic <V> EntryStream<Integer,V>
of(V[] array)
Returns anEntryStream
object 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 orderedEntryStream
containing the possible pairs of elements taken from the provided list.static <T> EntryStream<T,T>
ofPairs(T[] array)
Returns a sequential orderedEntryStream
containing 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 newEntryStream
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.static <T> EntryStream<Integer,T>
ofTree(T root, BiFunction<Integer,T,Stream<T>> mapper)
Return a newEntryStream
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.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 newEntryStream
which 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 newEntryStream
which 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 newEntryStream
which 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 newEntryStream
which 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 newEntryStream
which 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 newEntryStream
which 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 aMap
containing the elements of this stream.<M extends Map<K,V>>
MtoCustomMap(Supplier<M> mapSupplier)
Returns aMap
containing the elements of this stream.Map<K,V>
toImmutableMap()
Returns an immutableMap
containing the elements of this stream.Map<K,V>
toMap()
Returns aMap
containing the elements of this stream.Map<K,V>
toMap(BinaryOperator<V> mergeFunction)
Returns aMap
containing the elements of this stream.<R> R
toMapAndThen(Function<? super Map<K,V>,R> finisher)
Creates aMap
containing the elements of this stream, then performs finishing transformation and returns its result.NavigableMap<K,V>
toNavigableMap()
Returns aNavigableMap
containing the elements of this stream.NavigableMap<K,V>
toNavigableMap(BinaryOperator<V> mergeFunction)
Returns aNavigableMap
containing the elements of this stream.SortedMap<K,V>
toSortedMap()
Returns aSortedMap
containing the elements of this stream.SortedMap<K,V>
toSortedMap(BinaryOperator<V> mergeFunction)
Returns aSortedMap
containing 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 sequentialEntryStream
containingEntry
objects composed from corresponding key and value in given two lists.static <K,V>
EntryStream<K,V>zip(K[] keys, V[] values)
Returns a sequentialEntryStream
containingEntry
objects 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 aStreamEx
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 aStreamEx
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 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 anEntryStream
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 isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
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 anEntryStream
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 isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
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 anEntryStream
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 isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
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 anEntryStream
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 isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
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 isnull
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 newEntryStream
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 newEntryStream
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 newEntry
to append to this streamvalue
- the value of the newEntry
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 newEntryStream
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 firstEntry
to append to this streamv1
- the value of the firstEntry
to append to this streamk2
- the key of the secondEntry
to append to this streamv2
- the value of the secondEntry
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 newEntryStream
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 firstEntry
to append to this streamv1
- the value of the firstEntry
to append to this streamk2
- the key of the secondEntry
to append to this streamv2
- the value of the secondEntry
to append to this streamk3
- the key of the thirdEntry
to append to this streamv3
- the value of the thirdEntry
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 newEntryStream
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 newEntryStream
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 newEntry
to prepend to this streamvalue
- the value of the newEntry
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 newEntryStream
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 firstEntry
to prepend to this streamv1
- the value of the firstEntry
to prepend to this streamk2
- the key of the secondEntry
to prepend to this streamv2
- the value of the secondEntry
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 newEntryStream
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 firstEntry
to prepend to this streamv1
- the value of the firstEntry
to prepend to this streamk2
- the key of the secondEntry
to prepend to this streamv2
- the value of the secondEntry
to prepend to this streamk3
- the key of the thirdEntry
to prepend to this streamv3
- the value of the thirdEntry
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 anEntryStream
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 anEntryStream
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 aStreamEx
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 eachMap.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 anEntryStream
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 anEntryStream
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 theMap.Entry
objects 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 thenfalse
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, 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 thentrue
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, 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 thentrue
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, 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.Entry
instances rarely implement theComparable
interface. 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
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 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
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 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
- aCollector
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)
-
prefixKeys
public EntryStream<K,V> prefixKeys(BinaryOperator<K> op)
Returns a newEntryStream
which 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 newEntryStream
which 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 aMap
containing the elements of this stream. There are no guarantees on the type or serializability of theMap
returned; if more control over the returnedMap
is required, usetoCustomMap(Supplier)
.This is a terminal operation.
Returned
Map
is guaranteed to be modifiable.For parallel stream the concurrent
Map
is created.- Returns:
- a
Map
containing 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 immutableMap
containing the elements of this stream. There's no guarantees on exact type of the returnedMap
. In particular, no specific element order in the resultingMap
is guaranteed. The returnedMap
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 toObject.equals(Object)
)- Since:
- 0.6.3
- See Also:
toMap()
-
toMapAndThen
public <R> R toMapAndThen(Function<? super Map<K,V>,R> finisher)
Creates aMap
containing the elements of this stream, then performs finishing transformation and returns its result. There are no guarantees on the type or serializability of theMap
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 toObject.equals(Object)
)- Since:
- 0.5.5
- See Also:
toMap()
-
toMap
public Map<K,V> toMap(BinaryOperator<V> mergeFunction)
Returns aMap
containing the elements of this stream. There are no guarantees on the type or serializability of theMap
returned; if more control over the returnedMap
is 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
Map
is 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
Map
containing 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 aMap
containing the elements of this stream. TheMap
is 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, emptyMap
into which the results will be inserted- Returns:
- a
Map
containing 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 aMap
containing the elements of this stream. TheMap
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, emptyMap
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 aSortedMap
containing the elements of this stream. There are no guarantees on the type or serializability of theSortedMap
returned; if more control over the returnedMap
is required, usetoCustomMap(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 toObject.equals(Object)
)- Since:
- 0.1.0
- See Also:
toNavigableMap()
-
toSortedMap
public SortedMap<K,V> toSortedMap(BinaryOperator<V> mergeFunction)
Returns aSortedMap
containing the elements of this stream. There are no guarantees on the type or serializability of theSortedMap
returned; if more control over the returnedMap
is 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
SortedMap
is 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
SortedMap
containing the elements of this stream - Since:
- 0.1.0
- See Also:
toNavigableMap(BinaryOperator)
-
toNavigableMap
public NavigableMap<K,V> toNavigableMap()
Returns aNavigableMap
containing the elements of this stream. There are no guarantees on the type or serializability of theNavigableMap
returned; if more control over the returnedMap
is required, usetoCustomMap(Supplier)
.This is a terminal operation.
Returned
NavigableMap
is guaranteed to be modifiable.For parallel stream the concurrent
NavigableMap
is created.- Returns:
- a
NavigableMap
containing 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 aNavigableMap
containing the elements of this stream. There are no guarantees on the type or serializability of theNavigableMap
returned; if more control over the returnedMap
is 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
NavigableMap
is 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
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 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 aMap
where elements of this stream with the same key are grouped together. The resultingMap
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
orList
objects returned. If more control over the returnedMap
is required, usegrouping(Supplier)
. If more control over the lists required, usegroupingTo(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 aMap
where elements of this stream with the same key are grouped together. The resultingMap
keys are the keys of this stream entries and the values are the lists of the corresponding values. TheMap
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, usegroupingTo(Supplier)
.This is a terminal operation.
- Type Parameters:
M
- the type of the resultingMap
- Parameters:
mapSupplier
- a function which returns a new, emptyMap
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 aMap
where elements of this stream with the same key are grouped together. The resultingMap
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 returnedMap
is 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
- aCollector
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 aMap
where elements of this stream with the same key are grouped together. The resultingMap
keys are the keys of this stream entries and the corresponding values are combined using the provided downstream collector. TheMap
is 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, emptyMap
into which the results will be inserteddownstream
- aCollector
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 aMap
where elements of this stream with the same key are grouped together. The resultingMap
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 returnedMap
is required, usegroupingTo(Supplier, Supplier)
.This is a terminal operation.
- Type Parameters:
C
- the type of the resultingCollection
- Parameters:
collectionFactory
- aSupplier
which returns a new, emptyCollection
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 aMap
where elements of this stream with the same key are grouped together. The resultingMap
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 resultingCollection
M
- the type of the resultingMap
- Parameters:
mapSupplier
- a function which returns a new, emptyMap
into which the results will be insertedcollectionFactory
- aSupplier
which returns a new, emptyCollection
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 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 sequentialEntryStream
created 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, orderedEntryStream
created 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
Collection
orSpliterator
).- 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 anEntryStream
object 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 anEntryStream
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 anEntryStream
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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containing 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 sequentialEntryStream
containingEntry
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 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 sequentialEntryStream
containingEntry
objects 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 orderedEntryStream
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))
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 orderedEntryStream
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])
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 newEntryStream
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 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 newEntryStream
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 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 unorderedEntryStream
where each entry key is generated by the providedkeySupplier
and 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:
spliterator
in interfaceBaseStream<T,S extends BaseStream<T,S>>
-
isParallel
public boolean isParallel()
- Specified by:
isParallel
in interfaceBaseStream<T,S extends BaseStream<T,S>>
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceBaseStream<T,S extends BaseStream<T,S>>
-
-