Class 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>>
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.stream.Stream
Stream.Builder<T extends Object>
-
Field Summary
Fields inherited from class one.util.streamex.BaseStreamEx
CONSUMED_MESSAGE, context, spliterator
-
Constructor Summary
ConstructorsConstructorDescriptionEntryStream
(Spliterator<? extends Map.Entry<K, V>> spliterator, StreamContext context) EntryStream
(Stream<? extends Map.Entry<K, V>> stream, StreamContext context) -
Method Summary
Modifier and TypeMethodDescriptionboolean
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.Returns a newEntryStream
which is a concatenation of this stream and the stream created from the supplied map entries.Returns a newEntryStream
which is a concatenation of this stream and the supplied key-value pair.Returns a newEntryStream
which is a concatenation of this stream and two supplied key-value pairs.Returns a newEntryStream
which is a concatenation of this stream and three supplied key-value pairs.EntryStream<K,
List<V>> Merge series of adjacent stream entries with equal keys grouping the corresponding values intoList
.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
.Returns a stream consisting of the elements of this stream which have distinct keys (according to object equality).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
.filterKeys
(Predicate<? super K> keyPredicate) Returns a stream consisting of the elements of this stream which keys match the given predicate.filterKeyValue
(BiPredicate<? super K, ? super V> predicate) Returns a stream consisting of the elements of this stream which elements match the given predicate.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> Returns an infinite sequential unorderedEntryStream
where each entry key is generated by the providedkeySupplier
and each entry value is generated by the providedvalueSupplier
.grouping()
Returns aMap
where elements of this stream with the same key are grouped together.Returns aMap
where elements of this stream with the same key are grouped together.Returns aMap
where elements of this stream with the same key are grouped together.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.into
(M map) Drains the stream content into the suppliedMap
.invert()
Returns a stream consisting of theMap.Entry
objects which keys are the values of this stream elements and vice versa.join
(CharSequence delimiter) Returns aStreamEx
of strings which are created joining the keys and values of the current stream using the specified delimiter.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.keys()
Returns a stream consisting of the keys of this stream elements.<KK> EntryStream<KK,
V> 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> 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.Returns a stream consisting of the elements of this stream which key is not null.Returns a stream consisting of the elements of this stream which value is not null.static <K,
V> EntryStream<K, V> Returns a sequential, orderedEntryStream
created from givenIterator
.static <V> EntryStream<Integer,
V> Returns anEntryStream
object whose keys are indices of given list and the values are the corresponding list elements.static <K,
V> EntryStream<K, V> 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> 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> 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.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.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.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.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.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.Returns a newEntryStream
which is a concatenation of the stream created from the supplied map entries and this stream.Returns a newEntryStream
which is a concatenation of the supplied key-value pair and this stream.Returns a newEntryStream
which is a concatenation of two supplied key-value pairs and this stream.Returns a newEntryStream
which is a concatenation of three supplied key-value pairs and this stream.removeKeys
(Predicate<? super K> keyPredicate) Returns a stream consisting of the elements of this stream which keys don't match the given predicate.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.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.sorted()
(package private) EntryStream<K,
V> supply
(Spliterator<Map.Entry<K, V>> spliterator) (package private) EntryStream<K,
V> toConsumer
(BiConsumer<? super K, ? super V> action) toCustomMap
(BinaryOperator<V> mergeFunction, Supplier<M> mapSupplier) Returns aMap
containing the elements of this stream.toCustomMap
(Supplier<M> mapSupplier) Returns aMap
containing the elements of this stream.toFunction
(BiFunction<? super K, ? super V, ? extends R> mapper) Returns an immutableMap
containing the elements of this stream.toMap()
Returns aMap
containing the elements of this stream.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.toMapConsumer
(M map) Returns aNavigableMap
containing the elements of this stream.toNavigableMap
(BinaryOperator<V> mergeFunction) Returns aNavigableMap
containing the elements of this stream.Returns aSortedMap
containing the elements of this stream.toSortedMap
(BinaryOperator<V> mergeFunction) Returns aSortedMap
containing the elements of this stream.values()
Returns a stream consisting of the values of this stream elements.final EntryStream<K,
V> withoutKeys
(K... keys) Returns anEntryStream
consisting of the elements of this stream whose keys are not equal to any of supplied keys.final EntryStream<K,
V> withoutValues
(V... values) Returns anEntryStream
consisting of the elements of this stream whose values are not equal to any of the supplied values.static <K,
V> EntryStream<K, V> 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 one.util.streamex.AbstractStreamEx
addToMap, allMatch, anyMatch, append, appendSpliterator, chain, collect, collect, count, count, createStream, distinct, distinct, distinct, dropWhile, filter, findAny, findAny, findFirst, findFirst, flatArray, flatCollection, flatMap, flatMapToDouble, flatMapToInt, flatMapToLong, foldLeft, foldLeft, foldRight, foldRight, forEach, forEachOrdered, ifEmpty, ifEmpty, indexOf, indexOf, intersperse, iterator, limit, map, mapMulti, mapMultiToDouble, mapMultiToInt, mapMultiToLong, mapPartial, mapToDouble, mapToInt, mapToLong, max, maxBy, maxByDouble, maxByInt, maxByLong, min, minBy, minByDouble, minByInt, minByLong, noneMatch, nonNull, onClose, pairMap, parallel, parallel, peek, prefix, prepend, prependSpliterator, rawCollect, 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, toMapThrowing, toMutableList, toMutableSet, toSet, toSetAndThen, unordered
Methods inherited from class one.util.streamex.BaseStreamEx
close, isParallel, spliterator, stream
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.stream.BaseStream
close, isParallel, spliterator
Methods inherited from interface java.lang.Iterable
spliterator
-
Constructor Details
-
EntryStream
EntryStream(Stream<? extends Map.Entry<K, V>> stream, StreamContext context) -
EntryStream
EntryStream(Spliterator<? extends Map.Entry<K, V>> spliterator, StreamContext context)
-
-
Method Details
-
supply
- Specified by:
supply
in classAbstractStreamEx<Map.Entry<K,
V>, EntryStream<K, V>>
-
supply
- Specified by:
supply
in classAbstractStreamEx<Map.Entry<K,
V>, EntryStream<K, V>>
-
toConsumer
-
toMapConsumer
-
equalKeys
-
withValue
-
withKey
-
toFunction
static <K,V, Function<? super Map.Entry<K,R> V>, toFunction? extends R> (BiFunction<? super K, ? super V, ? extends R> mapper) -
join
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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:
-
filterValues
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:
-
filterKeyValue
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:
-
anyMatch
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
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
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
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:
-
removeValues
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:
-
removeKeyValue
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:
-
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:
-
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:
-
selectKeys
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:
-
selectValues
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:
-
peekKeys
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
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
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
Returns a stream consisting of the keys of this stream elements.This is an intermediate operation.
- Returns:
- the new stream
-
values
Returns a stream consisting of the values of this stream elements.This is an intermediate operation.
- Returns:
- the new stream
-
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
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:
-
collapseKeys
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:
-
collapseKeys
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:
-
prefixKeys
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:
-
prefixValues
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:
-
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:
-
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:
-
toMapAndThen
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
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:
-
toCustomMap
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:
-
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:
-
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:
-
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(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:
-
into
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
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:
-
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. 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
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:
-
grouping
public <A,D, M groupingM extends Map<K, D>> (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:
-
groupingTo
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:
-
groupingTo
public <C extends Collection<V>,M extends Map<K, M groupingToC>> (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:
-
forKeyValue
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:
-
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
- Type Parameters:
K
- the type of original stream keysV
- the type of original stream values- Parameters:
stream
- original stream- Returns:
- the wrapped stream
-
of
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
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
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
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
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
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
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
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
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
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:
-
zip
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:
-
ofPairs
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:
-
ofPairs
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:
-
ofTree
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:
-
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:
-
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:
-
withoutKeys
Returns anEntryStream
consisting of the elements of this stream whose keys are not equal to any of supplied keys.This is an intermediate operation. May return itself if no keys were supplied.
Current implementation scans the supplied keys linearly for every stream element. If you have many keys, consider using more efficient alternative instead.
Future implementations may take advantage on using
hashCode()
orcompareTo
forComparable
objects to improve the performance.If the
keys
array is changed between calling this method and finishing the stream traversal, then the result of the stream traversal is undefined: changes may or may not be taken into account.- Parameters:
keys
- the keys to remove from the stream.- Returns:
- the new stream
- Since:
- 0.8.0
- See Also:
-
withoutValues
Returns anEntryStream
consisting of the elements of this stream whose values are not equal to any of the supplied values.This is an intermediate operation. May return itself if no values were supplied.
Current implementation scans the supplied values linearly for every stream element. If you have many values, consider using more efficient alternative instead.
Future implementations may take advantage on using
hashCode()
orcompareTo
forComparable
objects to improve the performance.If the
values
array is changed between calling this method and finishing the stream traversal, then the result of the stream traversal is undefined: changes may or may not be taken into account.- Parameters:
values
- the values to remove from the stream.- Returns:
- the new stream
- Since:
- 0.8.0
- See Also:
-