Package com.landawn.abacus.util.stream
Class EntryStream<K,V>
java.lang.Object
com.landawn.abacus.util.stream.EntryStream<K,V>
- All Implemented Interfaces:
Immutable
,BaseStream<Map.Entry<K,
,V>, Object[], Predicate<? super Map.Entry<K, V>>, Consumer<? super Map.Entry<K, V>>, List<Map.Entry<K, V>>, u.Optional<Map.Entry<K, V>>, Indexed<Map.Entry<K, V>>, ObjIterator<Map.Entry<K, V>>, EntryStream<K, V>> Closeable
,AutoCloseable
The Stream will be automatically closed after execution(A terminal method is executed/triggered).
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.landawn.abacus.util.stream.BaseStream
BaseStream.ParallelSettings, BaseStream.Splitor
-
Method Summary
Modifier and TypeMethodDescription<SS extends BaseStream>
SS__
(Function<? super EntryStream<K, V>, ? extends SS> transfer) acceptIfNotEmpty
(Throwables.Consumer<? super EntryStream<K, V>, E> action) This is a terminal operation.<E extends Exception>
booleanallMatch
(Throwables.BiPredicate<? super K, ? super V, E> predicate) <E extends Exception>
booleanallMatch
(Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) <E extends Exception>
booleananyMatch
(Throwables.BiPredicate<? super K, ? super V, E> predicate) <E extends Exception>
booleananyMatch
(Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) append
(EntryStream<K, V> stream) append
(u.Optional<Map.Entry<K, V>> op) append
(M map) appendIfEmpty
(Supplier<? extends EntryStream<K, V>> supplier) appendIfEmpty
(M map) <R,
E extends Exception>
u.Optional<R>applyIfNotEmpty
(Throwables.Function<? super EntryStream<K, V>, ? extends R, E> func) This is a terminal operation.BiIterator<K,
V> Remember to close this Stream after the iteration is done, if needed.<KK,
VV> EntryStream<KK, VV> void
close()
It will be called by terminal operations in final.collapseByKey
(BiPredicate<? super K, ? super K> collapsible) <R,
A> Stream<R> collapseByKey
(BiPredicate<? super K, ? super K> collapsible, Collector<? super V, A, R> collector) Merge series of adjacent elements which satisfy the given predicate using the merger function and return a new stream.<R> R
Only call this method when the returned typeR
is one types:Collection/Map/StringBuilder/Multiset/LongMultiset/Multimap/BooleanList/IntList/.../DoubleList
.<R> R
collect
(Supplier<R> supplier, BiConsumer<? super R, ? super Map.Entry<K, V>> accumulator, BiConsumer<R, R> combiner) <R,
A> R <R,
A, RR, E extends Exception>
RRcollectAndThen
(Collector<? super Map.Entry<K, V>, A, R> downstream, Throwables.Function<? super R, ? extends RR, E> finisher) static <K,
V> EntryStream<K, V> concat
(Collection<? extends Map<K, V>> maps) static <K,
V> EntryStream<K, V> long
count()
cycled()
This method only runs sequentially, even in parallel stream and retrieved elements will be saved in memory for next cycle.cycled
(long rounds)
This method only runs sequentially, even in parallel stream and retrieved elements will be saved in memory for next cycle.difference
(Collection<?> c)
This method only runs sequentially, even in parallel stream.distinct()
Returns a stream consisting of the distinct elements of this stream.distinct
(BinaryOperator<Map.Entry<K, V>> mergeFunction) distinctBy
(Function<? super Map.Entry<K, V>, ?> keyMapper) distinctBy
(Function<? super Map.Entry<K, V>, ?> keyMapper, BinaryOperator<Map.Entry<K, V>> mergeFunction) dropWhile
(BiPredicate<? super K, ? super V> predicate) Remove the elements until the given predicate returns false.dropWhile
(Predicate<? super Map.Entry<K, V>> predicate, Consumer<? super Map.Entry<K, V>> actionOnDroppedItem) Remove the elements until the given predicate returns false.elementAt
(long position) static <K,
V> EntryStream<K, V> empty()
entries()
filter
(BiPredicate<? super K, ? super V> predicate) Returns a stream consisting of the elements of this stream that match the given predicate.filter
(Predicate<? super Map.Entry<K, V>> predicate, Consumer<? super Map.Entry<K, V>> actionOnDroppedItem) Returns a stream consisting of the elements of this stream that match the given predicate.filterByKey
(Predicate<? super K> keyPredicate) filterByValue
(Predicate<? super V> valuePredicate) <E extends Exception>
u.Optional<Map.Entry<K,V>> findAny
(Throwables.BiPredicate<? super K, ? super V, E> predicate) <E extends Exception>
u.Optional<Map.Entry<K,V>> findAny
(Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) <E extends Exception>
u.Optional<Map.Entry<K,V>> findFirst
(Throwables.BiPredicate<? super K, ? super V, E> predicate) <E extends Exception>
u.Optional<Map.Entry<K,V>> findFirst
(Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) <E extends Exception>
u.Optional<Map.Entry<K,V>> findFirstOrAny
(Throwables.BiPredicate<? super K, ? super V, E> predicate) Returns the first element matched bypredicateForFirst
if found or the first element if this stream is not empty Otherwise an emptyOptional<Map.Entry<K, V>>
will be returned.<E extends Exception>
u.Optional<Map.Entry<K,V>> findFirstOrAny
(Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) Returns the first element matched bypredicateForFirst
if found or the first element if this stream is not empty Otherwise an emptyOptional<Map.Entry<K, V>>
will be returned.<E extends Exception>
u.Optional<Map.Entry<K,V>> findFirstOrLast
(Throwables.BiPredicate<? super K, ? super V, E> predicate) Returns the first element matched bypredicateForFirst
if found or the last element if this stream is not empty Otherwise an emptyOptional<Map.Entry<K, V>>
will be returned.<E extends Exception>
u.Optional<Map.Entry<K,V>> findFirstOrLast
(Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) Returns the first element matched bypredicateForFirst
if found or the last element if this stream is not empty Otherwise an emptyOptional<Map.Entry<K, V>>
will be returned.<E extends Exception>
u.Optional<Map.Entry<K,V>> findLast
(Throwables.BiPredicate<? super K, ? super V, E> predicate) <E extends Exception>
u.Optional<Map.Entry<K,V>> findLast
(Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) first()
<KK,
VV> EntryStream<KK, VV> flatmap
(BiFunction<? super K, ? super V, ? extends Map<? extends KK, ? extends VV>> mapper) <KK,
VV> EntryStream<KK, VV> <KK,
VV> EntryStream<KK, VV> flatMap
(BiFunction<? super K, ? super V, ? extends EntryStream<? extends KK, ? extends VV>> mapper) <KK,
VV> EntryStream<KK, VV> <KK> EntryStream<KK,
V> flatmapKey
(BiFunction<? super K, ? super V, ? extends Collection<? extends KK>> keyMapper) <KK> EntryStream<KK,
V> flatmapKey
(Function<? super K, ? extends Collection<? extends KK>> keyMapper) <KK> EntryStream<KK,
V> flatMapKey
(BiFunction<? super K, ? super V, ? extends Stream<? extends KK>> keyMapper) <KK> EntryStream<KK,
V> flatMapKey
(Function<? super K, ? extends Stream<? extends KK>> keyMapper) <KK> EntryStream<KK,
V> flatmapKeyToDisposableEntry
(Function<? super K, ? extends Collection<? extends KK>> keyMapper) Deprecated.<KK> EntryStream<KK,
V> flatMapKeyToDisposableEntry
(Function<? super K, ? extends Stream<? extends KK>> keyMapper) Deprecated.<VV> EntryStream<K,
VV> flatmapValue
(BiFunction<? super K, ? super V, ? extends Collection<? extends VV>> valueMapper) <VV> EntryStream<K,
VV> flatmapValue
(Function<? super V, ? extends Collection<? extends VV>> valueMapper) <VV> EntryStream<K,
VV> flatMapValue
(BiFunction<? super K, ? super V, ? extends Stream<? extends VV>> valueMapper) <VV> EntryStream<K,
VV> flatMapValue
(Function<? super V, ? extends Stream<? extends VV>> valueMapper) <VV> EntryStream<K,
VV> flatmapValueToDisposableEntry
(Function<? super V, ? extends Collection<? extends VV>> valueMapper) Deprecated.<VV> EntryStream<K,
VV> flatMapValueToDisposableEntry
(Function<? super V, ? extends Stream<? extends VV>> valueMapper) Deprecated.<KK,
VV> EntryStream<KK, VV> flattMap
(BiFunction<? super K, ? super V, ? extends Stream<? extends Map.Entry<? extends KK, ? extends VV>>> mapper) <KK,
VV> EntryStream<KK, VV> flattMap
(Function<? super Map.Entry<K, V>, ? extends Stream<? extends Map.Entry<? extends KK, ? extends VV>>> mapper) <E extends Exception>
voidforEach
(Throwables.BiConsumer<? super K, ? super V, E> action) <E extends Exception>
voidforEach
(Throwables.Consumer<? super Map.Entry<K, V>, E> action) <E extends Exception>
voidforEachIndexed
(Throwables.IndexedConsumer<? super Map.Entry<K, V>, E> action) EntryStream<K,
List<V>> groupBy()
groupBy
(BinaryOperator<V> mergeFunction) <KK,
VV> EntryStream<KK, List<VV>> groupBy
(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper) <KK,
VV> EntryStream<KK, VV> groupBy
(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper, BinaryOperator<VV> mergeFunction) <KK,
VV> EntryStream<KK, VV> groupBy
(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper, BinaryOperator<VV> mergeFunction, Supplier<? extends Map<KK, VV>> mapFactory) <KK,
VV> EntryStream<KK, List<VV>> groupBy
(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper, Supplier<? extends Map<KK, List<VV>>> mapFactory) <KK,
A, D> EntryStream<KK, D> groupBy
(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Collector<? super Map.Entry<K, V>, A, D> downstream) <KK,
A, D> EntryStream<KK, D> groupBy
(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Collector<? super Map.Entry<K, V>, A, D> downstream, Supplier<? extends Map<KK, D>> mapFactory) EntryStream<K,
List<V>> <A,
D> EntryStream<K, D> <A,
D> EntryStream<K, D> groupTo()
<R,
E extends Exception>
RgroupToAndThen
(Throwables.Function<? super Map<K, List<V>>, ? extends R, E> func) indexed()
This method only runs sequentially, even in parallel stream.intersection
(Collection<?> c)
This method only runs sequentially, even in parallel stream.inversed()
Deprecated.boolean
iterator()
Remember to close this Stream after the iteration is done, if needed.join
(CharSequence delimiter) join
(CharSequence delimiter, CharSequence keyValueDelimiter) join
(CharSequence delimiter, CharSequence prefix, CharSequence suffix) join
(CharSequence delimiter, CharSequence keyValueDelimiter, CharSequence prefix, CharSequence suffix) keys()
last()
limit
(long maxSize) <KK,
VV> EntryStream<KK, VV> map
(BiFunction<? super K, ? super V, ? extends Map.Entry<? extends KK, ? extends VV>> mapper) <KK,
VV> EntryStream<KK, VV> map
(BiFunction<? super K, ? super V, ? extends KK> keyMapper, BiFunction<? super K, ? super V, ? extends VV> valueMapper) <KK,
VV> EntryStream<KK, VV> <KK,
VV> EntryStream<KK, VV> map
(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper) <KK> EntryStream<KK,
V> mapKey
(BiFunction<? super K, ? super V, ? extends KK> keyMapper) <KK> EntryStream<KK,
V> <KK> EntryStream<KK,
V> mapKeyPartial
(BiFunction<? super K, ? super V, u.Optional<? extends KK>> keyMapper) <KK> EntryStream<KK,
V> mapKeyPartial
(Function<? super K, u.Optional<? extends KK>> keyMapper) <KK,
VV> EntryStream<KK, VV> <KK,
VV> EntryStream<KK, VV> mapPartial
(BiFunction<? super K, ? super V, u.Optional<? extends Map.Entry<? extends KK, ? extends VV>>> mapper) <KK,
VV> EntryStream<KK, VV> mapPartial
(Function<? super Map.Entry<K, V>, u.Optional<? extends Map.Entry<? extends KK, ? extends VV>>> mapper) <KK,
VV> EntryStream<KK, VV> mapToDisposableEntry
(BiFunction<? super K, ? super V, ? extends KK> keyMapper, BiFunction<? super K, ? super V, ? extends VV> valueMapper) Deprecated.<KK,
VV> EntryStream<KK, VV> mapToDisposableEntry
(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper) Deprecated.<VV> EntryStream<K,
VV> mapValue
(BiFunction<? super K, ? super V, ? extends VV> valueMapper) <VV> EntryStream<K,
VV> <VV> EntryStream<K,
VV> mapValuePartial
(BiFunction<? super K, ? super V, u.Optional<? extends VV>> valueMapper) <VV> EntryStream<K,
VV> mapValuePartial
(Function<? super V, u.Optional<? extends VV>> valueMapper) max
(Comparator<? super Map.Entry<K, V>> comparator) maxByKey
(Comparator<? super K> keyComparator) maxByValue
(Comparator<? super V> valueComparator) static <K,
V> EntryStream<K, V> merge
(Collection<? extends Map<K, V>> maps, BiFunction<? super Map.Entry<K, V>, ? super Map.Entry<K, V>, MergeResult> nextSelector) static <K,
V> EntryStream<K, V> merge
(Map<K, V> a, Map<K, V> b, BiFunction<? super Map.Entry<K, V>, ? super Map.Entry<K, V>, MergeResult> nextSelector) static <K,
V> EntryStream<K, V> merge
(Map<K, V> a, Map<K, V> b, Map<K, V> c, BiFunction<? super Map.Entry<K, V>, ? super Map.Entry<K, V>, MergeResult> nextSelector) min
(Comparator<? super Map.Entry<K, V>> comparator) minByKey
(Comparator<? super K> keyComparator) minByValue
(Comparator<? super V> valueComparator) <E extends Exception>
booleannMatch
(long atLeast, long atMost, Throwables.BiPredicate<? super K, ? super V, E> predicate) <E extends Exception>
booleannMatch
(long atLeast, long atMost, Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) <E extends Exception>
booleannoneMatch
(Throwables.BiPredicate<? super K, ? super V, E> predicate) <E extends Exception>
booleannoneMatch
(Throwables.Predicate<? super Map.Entry<K, V>, E> predicate) static <E> EntryStream<E,
Long> of
(LongMultiset<E> multiset) static <K,
E, V extends Collection<E>>
EntryStream<K,V> static <E> EntryStream<E,
Integer> static <K,
V> EntryStream<K, V> static <T,
K> EntryStream<K, T> static <T,
K, V> EntryStream<K, V> static <K,
V> EntryStream<K, V> static <T,
K> EntryStream<K, T> static <T,
K, V> EntryStream<K, V> static <K,
V> EntryStream<K, V> static <K,
V> EntryStream<K, V> of
(K k1, V v1) static <K,
V> EntryStream<K, V> of
(K k1, V v1, K k2, V v2) static <K,
V> EntryStream<K, V> of
(K k1, V v1, K k2, V v2, K k3, V v3) static <K,
V> EntryStream<K, V> of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) 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) 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) 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) static <T,
K> EntryStream<K, T> static <T,
K, V> EntryStream<K, V> static <K,
V> EntryStream<K, V> ofNullable
(Map.Entry<K, V> entry) onEach
(BiConsumer<? super K, ? super V> action) Same aspeek
onlyOne()
parallel()
Consider usingsps(Function)
if only next operation need to be parallelized.parallel
(int maxThreadNum) Consider usingsps(int, Function)
if only next operation need to be parallelized.parallel
(int maxThreadNum, BaseStream.Splitor splitor) Returns an equivalent stream that is parallel.parallel
(int maxThreadNum, BaseStream.Splitor splitor, Executor executor) stream.parallel(maxThreadNum, splitor, executor).map(f).filter(p)...; // Replace above line of code with "sps" if only "f" need to be parallelized.// Replace above line of code with "sps" if only "f" need to be parallelized.stream.parallel(parallelSettings).map(f).filter(p)...; // Replace above line of code with "sps" if only "f" need to be parallelized.parallel
(BaseStream.Splitor splitor) stream.parallel(executor).map(f).filter(p)...; // Replace above line of code with "sps" if only "f" need to be parallelized.peek
(BiConsumer<? super K, ? super V> action)
All elements will be loaded to memory and sorted if not yet.prepend
(EntryStream<K, V> stream) prepend
(u.Optional<Map.Entry<K, V>> op) prepend
(M map) void
println()
<SS extends BaseStream>
SSpsp
(Function<? super EntryStream<K, V>, ? extends SS> ops) Temporarily switch the stream to sequence stream for operationops
and then switch back to parallel stream with samemaxThreadNum/splitor/asyncExecutor
.rateLimited
(double permitsPerSecond) rateLimited
(RateLimiter rateLimiter) <E extends Exception>
u.Optional<Map.Entry<K,V>> reduce
(Throwables.BinaryOperator<Map.Entry<K, V>, E> accumulator) reversed()
This method only runs sequentially, even in parallel stream and all elements will be loaded to memory.Deprecated.reverseSorted
(Comparator<? super Map.Entry<K, V>> comparator) rotated
(int distance)
This method only runs sequentially, even in parallel stream and all elements will be loaded to memory.<KK> EntryStream<KK,
V> selectByKey
(Class<KK> clazz) Returns a stream consisting of the elements of this stream which keys are instances of given class.<VV> EntryStream<K,
VV> selectByValue
(Class<VV> clazz) Returns a stream consisting of the elements of this stream which values are instances of given class.shuffled()
This method only runs sequentially, even in parallel stream and all elements will be loaded to memory.
This method only runs sequentially, even in parallel stream and all elements will be loaded to memory.skip
(long n) skipUntil
(BiPredicate<? super K, ? super V> predicate) Stream<EntryStream<K,
V>> sliding
(int windowSize) Stream<EntryStream<K,
V>> sliding
(int windowSize, int increment) Stream.of(1, 2, 3, 4, 5, 6, 7, 8).sliding(3, 1).forEach(Stream::println)
output:
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
[4, 5, 6]
[5, 6, 7]
[6, 7, 8]
============================================================================Stream.of(1, 2, 3, 4, 5, 6, 7, 8).sliding(3, 3).forEach(Stream::println)
output:
[1, 2, 3]
[4, 5, 6]
[7, 8]
============================================================================Stream.of(1, 2, 3, 4, 5, 6, 7, 5).sliding(3, 5).forEach(Stream::println)
output:
[1, 2, 3]
[6, 7, 8]
This method only runs sequentially, even in parallel stream.slidingToList
(int windowSize) slidingToList
(int windowSize, int increment) sorted()
Deprecated.sorted
(Comparator<? super Map.Entry<K, V>> comparator) sortedByDouble
(ToDoubleFunction<? super Map.Entry<K, V>> keyMapper) sortedByInt
(ToIntFunction<? super Map.Entry<K, V>> keyMapper) sortedByKey
(Comparator<? super K> keyComparator) sortedByLong
(ToLongFunction<? super Map.Entry<K, V>> keyMapper) sortedByValue
(Comparator<? super V> valueComparator) Stream<EntryStream<K,
V>> split
(int chunkSize) Returns Stream ofS
with consecutive sub sequences of the elements, each of the same size (the final sequence may be smaller).Stream<EntryStream<K,
V>> Split the stream by the specified predicate.Stream<EntryStream<K,
V>> splitAt
(int where) Split the stream into two pieces atwhere
.Stream<EntryStream<K,
V>> Split the stream into two pieces atwhere
turns totrue
.splitToList
(int chunkSize) Returns Stream ofPL
with consecutive sub sequences of the elements, each of the same size (the final sequence may be smaller).splitToList
(Predicate<? super Map.Entry<K, V>> predicate) Split the stream by the specified predicate.<SS extends BaseStream>
SSsps
(int maxThreadNum, Function<? super EntryStream<K, V>, ? extends SS> ops) Temporarily switch the stream to parallel stream for operationops
and then switch back to sequence stream.<SS extends BaseStream>
SSsps
(Function<? super EntryStream<K, V>, ? extends SS> ops) Temporarily switch the stream to parallel stream for operationops
and then switch back to sequence stream.step
(long step)
This method only runs sequentially, even in parallel stream.takeWhile
(BiPredicate<? super K, ? super V> predicate) Keep the elements until the given predicate returns false.throwIfEmpty
(Supplier<? extends RuntimeException> exceptionSupplier) Object[]
toArray()
<CC extends Collection<Map.Entry<K,
V>>>
CCtoCollection
(Supplier<? extends CC> supplier) toImmutableMap
(BinaryOperator<V> mergeFunction) toList()
toLongMultiset
(Supplier<? extends LongMultiset<Map.Entry<K, V>>> supplier) toMap()
toMap
(BinaryOperator<V> mergeFunction) toMap
(BinaryOperator<V> mergeFunction, Supplier<? extends M> mapFactory) <R,
E extends Exception>
RtoMapAndThen
(Throwables.Function<? super Map<K, V>, ? extends R, E> func) <C extends Collection<V>,
M extends Multimap<K, V, C>>
MtoMultimap
(Supplier<? extends M> mapFactory) toSet()
values()
static <K,
V> EntryStream<K, V> static <K,
V> EntryStream<K, V> static <K,
V> EntryStream<K, V> static <K,
V> EntryStream<K, V> static <K,
V> EntryStream<K, V> zip
(K[] keys, V[] values) static <K,
V> EntryStream<K, V> zip
(K[] keys, V[] values, K valueForNonKey, V valueForNonValue)
-
Method Details
-
keys
-
values
-
entries
-
inversed
-
selectByKey
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:
-
selectByValue
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:
-
filter
Description copied from interface:BaseStream
Returns a stream consisting of the elements of this stream that match the given predicate.- Returns:
-
filter
@ParallelSupported @IntermediateOp public EntryStream<K,V> filter(BiPredicate<? super K, ? super V> predicate) -
filter
public EntryStream<K,V> filter(Predicate<? super Map.Entry<K, V>> predicate, Consumer<? super Map.Entry<K, V>> actionOnDroppedItem) Description copied from interface:BaseStream
Returns a stream consisting of the elements of this stream that match the given predicate.- Returns:
-
filterByKey
@ParallelSupported @IntermediateOp public EntryStream<K,V> filterByKey(Predicate<? super K> keyPredicate) -
filterByValue
@ParallelSupported @IntermediateOp public EntryStream<K,V> filterByValue(Predicate<? super V> valuePredicate) -
takeWhile
Description copied from interface:BaseStream
Keep the elements until the given predicate returns false. The stream should be sorted, which means if x is the first element:predicate.test(x)
returns false, any element y behind x:predicate.test(y)
should returns false. In parallel Streams, the elements after the first element whichpredicate
returns false may be tested by predicate too.
For example:// For sequential stream: Stream.of(1, 2, 3, 4, 5, 6).takeWhile(it -> it < 5).toList() ===> [1, 2, 3, 4] Stream.of(1, 2, 5, 6, 3, 4).takeWhile(it -> it < 5).toList() ===> [1, 2] Stream.of(5, 6, 1, 2, 3, 4).takeWhile(it -> it < 5).toList() ===> [] // For parallel stream: Stream.of(1, 2, 3, 4, 5, 6).parallel().takeWhile(it -> it < 5).toList() ===> [1, 2, 3, 4] // Order could be different since it's in parallel stream. Stream.of(1, 2, 5, 6, 3, 4).parallel().takeWhile(it -> it < 5).toList() ===> [1, 2] // or [1, 2, 3] or [1, 2, 3, 4] // Order could be different since it's in parallel stream. Stream.of(5, 6, 1, 2, 3, 4).parallel().takeWhile(it -> it < 5).toList() ===> any sub set of [1, 2, 3, 4], including [] // Order could be different since it's in parallel stream.
- Returns:
-
takeWhile
@ParallelSupported @IntermediateOp public EntryStream<K,V> takeWhile(BiPredicate<? super K, ? super V> predicate) -
dropWhile
Description copied from interface:BaseStream
Remove the elements until the given predicate returns false. The stream should be sorted, which means if x is the first element:predicate.test(x)
returns true, any element y behind x:predicate.test(y)
should returns true. In parallel Streams, the elements after the first element whichpredicate
returns false may be tested by predicate too.
For example:// For sequential stream: Stream.of(1, 2, 3, 4, 5, 6).dropWhile(it -> it < 4).toList() ===> [4, 5, 6] Stream.of(1, 2, 5, 6, 3, 4).dropWhile(it -> it < 4).toList() ===> [5, 6, 3, 4] Stream.of(5, 6, 1, 2, 3, 4).dropWhile(it -> it < 4).toList() ===> [5, 6, 1, 2, 3, 4] // For parallel stream: Stream.of(1, 2, 3, 4, 5, 6).parallel().dropWhile(it -> it < 4).toList() ===> [4, 5, 6] // Order could be different since it's in parallel stream. Stream.of(1, 2, 5, 6, 3, 4).parallel().dropWhile(it -> it < 4).toList() ===> [5, 6, 4] // or [5, 6, 3, 4] // Order could be different since it's in parallel stream. Stream.of(5, 6, 1, 2, 3, 4).parallel().dropWhile(it -> it < 4).toList() ===> [5, 6] + any sub set of [1, 2, 3, 4] // Order could be different since it's in parallel stream.
- Returns:
-
dropWhile
@ParallelSupported @IntermediateOp public EntryStream<K,V> dropWhile(BiPredicate<? super K, ? super V> predicate) -
dropWhile
public EntryStream<K,V> dropWhile(Predicate<? super Map.Entry<K, V>> predicate, Consumer<? super Map.Entry<K, V>> actionOnDroppedItem) Description copied from interface:BaseStream
Remove the elements until the given predicate returns false. The stream should be sorted, which means if x is the first element:predicate.test(x)
returns true, any element y behind x:predicate.test(y)
should returns true. In parallel Streams, the elements after the first element whichpredicate
returns false may be tested by predicate too.- Returns:
BaseStream.dropWhile(Object)
-
skipUntil
- Returns:
- See Also:
-
skipUntil
@ParallelSupported @IntermediateOp public EntryStream<K,V> skipUntil(BiPredicate<? super K, ? super V> predicate) -
map
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> map(Function<? super Map.Entry<K, V>, ? extends Map.Entry<? extends KK, ? extends VV>> mapper) -
map
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> map(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper) -
map
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> map(BiFunction<? super K, ? super V, ? extends Map.Entry<? extends KK, ? extends VV>> mapper) -
map
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> map(BiFunction<? super K, ? super V, ? extends KK> keyMapper, BiFunction<? super K, ? super V, ? extends VV> valueMapper) -
mapMulti
@Beta @ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> mapMulti(BiConsumer<? super Map.Entry<K, V>, ? super Consumer<Map.Entry<KK, VV>>> mapper) -
mapPartial
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> mapPartial(Function<? super Map.Entry<K, V>, u.Optional<? extends Map.Entry<? extends KK, ? extends VV>>> mapper) -
mapPartial
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> mapPartial(BiFunction<? super K, ? super V, u.Optional<? extends Map.Entry<? extends KK, ? extends VV>>> mapper) -
mapKey
@ParallelSupported @IntermediateOp public <KK> EntryStream<KK,V> mapKey(Function<? super K, ? extends KK> keyMapper) -
mapKey
@ParallelSupported @IntermediateOp public <KK> EntryStream<KK,V> mapKey(BiFunction<? super K, ? super V, ? extends KK> keyMapper) -
mapValue
@ParallelSupported @IntermediateOp public <VV> EntryStream<K,VV> mapValue(Function<? super V, ? extends VV> valueMapper) -
mapValue
@ParallelSupported @IntermediateOp public <VV> EntryStream<K,VV> mapValue(BiFunction<? super K, ? super V, ? extends VV> valueMapper) -
mapKeyPartial
@ParallelSupported @IntermediateOp public <KK> EntryStream<KK,V> mapKeyPartial(Function<? super K, u.Optional<? extends KK>> keyMapper) -
mapKeyPartial
@ParallelSupported @IntermediateOp public <KK> EntryStream<KK,V> mapKeyPartial(BiFunction<? super K, ? super V, u.Optional<? extends KK>> keyMapper) -
mapValuePartial
@ParallelSupported @IntermediateOp public <VV> EntryStream<K,VV> mapValuePartial(Function<? super V, u.Optional<? extends VV>> valueMapper) -
mapValuePartial
@ParallelSupported @IntermediateOp public <VV> EntryStream<K,VV> mapValuePartial(BiFunction<? super K, ? super V, u.Optional<? extends VV>> valueMapper) -
flatMap
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> flatMap(Function<? super Map.Entry<K, V>, ? extends EntryStream<? extends KK, ? extends VV>> mapper) -
flatMap
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> flatMap(BiFunction<? super K, ? super V, ? extends EntryStream<? extends KK, ? extends VV>> mapper) -
flatmap
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> flatmap(Function<? super Map.Entry<K, V>, ? extends Map<? extends KK, ? extends VV>> mapper) -
flatmap
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> flatmap(BiFunction<? super K, ? super V, ? extends Map<? extends KK, ? extends VV>> mapper) -
flattMap
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> flattMap(Function<? super Map.Entry<K, V>, ? extends Stream<? extends Map.Entry<? extends KK, ? extends VV>>> mapper) -
flattMap
@ParallelSupported @IntermediateOp public <KK,VV> EntryStream<KK,VV> flattMap(BiFunction<? super K, ? super V, ? extends Stream<? extends Map.Entry<? extends KK, ? extends VV>>> mapper) -
flatMapKey
@ParallelSupported @IntermediateOp public <KK> EntryStream<KK,V> flatMapKey(Function<? super K, ? extends Stream<? extends KK>> keyMapper) -
flatMapKey
@ParallelSupported @IntermediateOp public <KK> EntryStream<KK,V> flatMapKey(BiFunction<? super K, ? super V, ? extends Stream<? extends KK>> keyMapper) -
flatmapKey
@ParallelSupported @IntermediateOp public <KK> EntryStream<KK,V> flatmapKey(Function<? super K, ? extends Collection<? extends KK>> keyMapper) -
flatmapKey
@ParallelSupported @IntermediateOp public <KK> EntryStream<KK,V> flatmapKey(BiFunction<? super K, ? super V, ? extends Collection<? extends KK>> keyMapper) -
flatMapValue
@ParallelSupported @IntermediateOp public <VV> EntryStream<K,VV> flatMapValue(Function<? super V, ? extends Stream<? extends VV>> valueMapper) -
flatMapValue
@ParallelSupported @IntermediateOp public <VV> EntryStream<K,VV> flatMapValue(BiFunction<? super K, ? super V, ? extends Stream<? extends VV>> valueMapper) -
flatmapValue
@ParallelSupported @IntermediateOp public <VV> EntryStream<K,VV> flatmapValue(Function<? super V, ? extends Collection<? extends VV>> valueMapper) -
flatmapValue
@ParallelSupported @IntermediateOp public <VV> EntryStream<K,VV> flatmapValue(BiFunction<? super K, ? super V, ? extends Collection<? extends VV>> valueMapper) -
groupBy
- Parameters:
keyMapper
-- Returns:
- See Also:
-
groupBy
@SequentialOnly @IntermediateOp @TerminalOpTriggered public EntryStream<K,List<V>> groupBy(Supplier<? extends Map<K, List<V>>> mapFactory) - Parameters:
keyMapper
-mapFactory
-- Returns:
- See Also:
-
groupBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public <KK,VV> EntryStream<KK,List<VV>> groupBy(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper) -
groupBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public <KK,VV> EntryStream<KK,List<VV>> groupBy(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper, Supplier<? extends Map<KK, List<VV>>> mapFactory) - Parameters:
keyMapper
-valueMapper
-mapFactory
-- Returns:
- See Also:
-
groupBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public <A,D> EntryStream<K,D> groupBy(Collector<? super Map.Entry<K, V>, A, D> downstream) - Parameters:
downstream
-- Returns:
- See Also:
-
groupBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public <A,D> EntryStream<K,D> groupBy(Collector<? super Map.Entry<K, V>, A, D> downstream, Supplier<? extends Map<K, D>> mapFactory) - Parameters:
downstream
-mapFactory
-- Returns:
- See Also:
-
groupBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public <KK,A, EntryStream<KK,D> D> groupBy(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Collector<? super Map.Entry<K, V>, A, D> downstream) - Parameters:
keyMapper
-downstream
-mapFactory
-- Returns:
- See Also:
-
groupBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public <KK,A, EntryStream<KK,D> D> groupBy(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Collector<? super Map.Entry<K, V>, A, D> downstream, Supplier<? extends Map<KK, D>> mapFactory) - Parameters:
keyMapper
-downstream
-- Returns:
- See Also:
-
groupBy
@SequentialOnly @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> groupBy(BinaryOperator<V> mergeFunction) - Parameters:
mergeFunction
-- Returns:
-
groupBy
@SequentialOnly @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> groupBy(BinaryOperator<V> mergeFunction, Supplier<? extends Map<K, V>> mapFactory) - Parameters:
mergeFunction
-mapFactory
-- Returns:
-
groupBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public <KK,VV> EntryStream<KK,VV> groupBy(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper, BinaryOperator<VV> mergeFunction) - Parameters:
keyMapper
-valueMapper
-mergeFunction
-- Returns:
- See Also:
-
Collectors#groupBy(Function, Function, BinaryOperator)
-
groupBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public <KK,VV> EntryStream<KK,VV> groupBy(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper, BinaryOperator<VV> mergeFunction, Supplier<? extends Map<KK, VV>> mapFactory) - Parameters:
keyMapper
-valueMapper
-mergeFunction
-mapFactory
-- Returns:
- See Also:
-
Collectors#groupBy(Function, Function, BinaryOperator, Supplier)
-
collapseByKey
@SequentialOnly @IntermediateOp public Stream<List<V>> collapseByKey(BiPredicate<? super K, ? super K> collapsible) - Parameters:
collapsible
-- Returns:
- See Also:
-
collapseByKey
@SequentialOnly @IntermediateOp public <R,A> Stream<R> collapseByKey(BiPredicate<? super K, ? super K> collapsible, Collector<? super V, A, R> collector) Merge series of adjacent elements which satisfy the given predicate using the merger function and return a new stream.
This method only runs sequentially, even in parallel stream.- Parameters:
collapsible
-collector
-- Returns:
-
split
Description copied from interface:BaseStream
Returns Stream ofS
with consecutive sub sequences of the elements, each of the same size (the final sequence may be smaller).- Parameters:
chunkSize
- the desired size of each sub sequence (the last may be smaller).- Returns:
-
splitToList
Description copied from interface:BaseStream
Returns Stream ofPL
with consecutive sub sequences of the elements, each of the same size (the final sequence may be smaller).
This method only runs sequentially, even in parallel stream.- Parameters:
chunkSize
- the desired size of each sub sequence (the last may be smaller).- Returns:
-
split
Description copied from interface:BaseStream
Split the stream by the specified predicate. This stream should be sorted by value which is used to verify the border.
This method only runs sequentially, even in parallel stream.- Returns:
-
splitToList
Description copied from interface:BaseStream
Split the stream by the specified predicate. This method only runs sequentially, even in parallel stream.- Returns:
-
splitAt
Description copied from interface:BaseStream
Split the stream into two pieces atwhere
. The first piece will be loaded into memory.- Returns:
-
splitAt
Description copied from interface:BaseStream
Split the stream into two pieces atwhere
turns totrue
. The first piece will be loaded into memory.Stream.of(1, 3, 2, 4, 2, 5).splitAt(it -> it >= 4).forEach(s -> s.println()); // [1, 3, 2], [4, 2, 5]
- Returns:
-
sliding
Description copied from interface:BaseStream
Stream.of(1, 2, 3, 4, 5, 6, 7, 8).sliding(3, 1).forEach(Stream::println)
output:
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
[4, 5, 6]
[5, 6, 7]
[6, 7, 8]
============================================================================Stream.of(1, 2, 3, 4, 5, 6, 7, 8).sliding(3, 3).forEach(Stream::println)
output:
[1, 2, 3]
[4, 5, 6]
[7, 8]
============================================================================Stream.of(1, 2, 3, 4, 5, 6, 7, 5).sliding(3, 5).forEach(Stream::println)
output:
[1, 2, 3]
[6, 7, 8]
This method only runs sequentially, even in parallel stream.- Returns:
-
slidingToList
- Returns:
- See Also:
-
intersection
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream.- Returns:
- See Also:
-
difference
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream.- Returns:
- See Also:
-
symmetricDifference
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream.- Returns:
- See Also:
-
sorted
Deprecated.Compares keys and then compares values if key is equals.- Returns:
-
sorted
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> sorted(Comparator<? super Map.Entry<K, V>> comparator) -
sortedByKey
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> sortedByKey(Comparator<? super K> keyComparator) -
sortedByValue
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> sortedByValue(Comparator<? super V> valueComparator) -
sortedBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> sortedBy(Function<? super Map.Entry<K, V>, ? extends Comparable> keyMapper) -
sortedByInt
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> sortedByInt(ToIntFunction<? super Map.Entry<K, V>> keyMapper) - Parameters:
keyMapper
-- Returns:
-
sortedByLong
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> sortedByLong(ToLongFunction<? super Map.Entry<K, V>> keyMapper) - Parameters:
keyMapper
-- Returns:
-
sortedByDouble
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> sortedByDouble(ToDoubleFunction<? super Map.Entry<K, V>> keyMapper) - Parameters:
keyMapper
-- Returns:
-
reverseSorted
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> reverseSorted(Comparator<? super Map.Entry<K, V>> comparator) -
indexed
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream.- Returns:
-
distinct
Description copied from interface:BaseStream
Returns a stream consisting of the distinct elements of this stream.- Returns:
-
distinct
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> distinct(BinaryOperator<Map.Entry<K, V>> mergeFunction) -
distinct
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> distinct(Predicate<? super Long> occurrencesFilter) -
distinctByKey
-
distinctByValue
-
distinctBy
@ParallelSupported @IntermediateOp public EntryStream<K,V> distinctBy(Function<? super Map.Entry<K, V>, ?> keyMapper) -
distinctBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> distinctBy(Function<? super Map.Entry<K, V>, ?> keyMapper, BinaryOperator<Map.Entry<K, V>> mergeFunction) - Parameters:
keyMapper
-mergeFunction
-- Returns:
- See Also:
-
distinctBy
@ParallelSupported @IntermediateOp @TerminalOpTriggered public EntryStream<K,V> distinctBy(Function<? super Map.Entry<K, V>, ?> keyMapper, Predicate<? super Long> occurrencesFilter) - Parameters:
keyMapper
-occurrencesFilter
-- Returns:
- See Also:
-
rotated
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream and all elements will be loaded to memory.- Returns:
-
shuffled
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream and all elements will be loaded to memory. -
shuffled
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream and all elements will be loaded to memory.- Returns:
-
reversed
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream and all elements will be loaded to memory.- Returns:
-
reverseSorted
Deprecated. -
cycled
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream and retrieved elements will be saved in memory for next cycle.- Returns:
-
cycled
Description copied from interface:BaseStream
This method only runs sequentially, even in parallel stream and retrieved elements will be saved in memory for next cycle.- Returns:
-
prepend
@SequentialOnly @IntermediateOp public <M extends Map<? extends K,? extends V>> EntryStream<K,V> prepend(M map) -
prepend
-
prepend
-
append
@SequentialOnly @IntermediateOp public <M extends Map<? extends K,? extends V>> EntryStream<K,V> append(M map) -
append
-
append
-
appendIfEmpty
@SequentialOnly @IntermediateOp public <M extends Map<? extends K,? extends V>> EntryStream<K,V> appendIfEmpty(M map) -
appendIfEmpty
-
applyIfNotEmpty
public <R,E extends Exception> u.Optional<R> applyIfNotEmpty(Throwables.Function<? super EntryStream<K, V>, throws E? extends R, E> func) Description copied from interface:BaseStream
This is a terminal operation. That's to say this stream will be closed after this operation.- Returns:
- Throws:
E
-
acceptIfNotEmpty
public <E extends Exception> If.OrElse acceptIfNotEmpty(Throwables.Consumer<? super EntryStream<K, V>, throws EE> action) Description copied from interface:BaseStream
This is a terminal operation. That's to say this stream will be closed after this operation.- Returns:
- Throws:
E
-
skip
- Returns:
-
skip
- Returns:
-
limit
- Returns:
-
step
-
rateLimited
- Returns:
- See Also:
-
peek
-
peek
@ParallelSupported @IntermediateOp public EntryStream<K,V> peek(BiConsumer<? super K, ? super V> action) -
onEach
Description copied from interface:BaseStream
Same aspeek
- Returns:
- See Also:
-
onEach
@ParallelSupported @IntermediateOp public EntryStream<K,V> onEach(BiConsumer<? super K, ? super V> action) -
forEach
@ParallelSupported @TerminalOp public <E extends Exception> void forEach(Throwables.Consumer<? super Map.Entry<K, V>, throws EE> action) - Throws:
E extends Exception
-
forEach
@ParallelSupported @TerminalOp public <E extends Exception> void forEach(Throwables.BiConsumer<? super K, ? super V, throws EE> action) - Throws:
E extends Exception
-
forEachIndexed
@ParallelSupported @TerminalOp public <E extends Exception> void forEachIndexed(Throwables.IndexedConsumer<? super Map.Entry<K, V>, throws EE> action) - Throws:
E extends Exception
-
min
@ParallelSupported @TerminalOp public u.Optional<Map.Entry<K,V>> min(Comparator<? super Map.Entry<K, V>> comparator) -
minByKey
@ParallelSupported @TerminalOp public u.Optional<Map.Entry<K,V>> minByKey(Comparator<? super K> keyComparator) -
minByValue
@ParallelSupported @TerminalOp public u.Optional<Map.Entry<K,V>> minByValue(Comparator<? super V> valueComparator) -
minBy
@ParallelSupported @TerminalOp public u.Optional<Map.Entry<K,V>> minBy(Function<? super Map.Entry<K, V>, ? extends Comparable> keyMapper) -
max
@ParallelSupported @TerminalOp public u.Optional<Map.Entry<K,V>> max(Comparator<? super Map.Entry<K, V>> comparator) -
maxByKey
@ParallelSupported @TerminalOp public u.Optional<Map.Entry<K,V>> maxByKey(Comparator<? super K> keyComparator) -
maxByValue
@ParallelSupported @TerminalOp public u.Optional<Map.Entry<K,V>> maxByValue(Comparator<? super V> valueComparator) -
maxBy
@ParallelSupported @TerminalOp public u.Optional<Map.Entry<K,V>> maxBy(Function<? super Map.Entry<K, V>, ? extends Comparable> keyMapper) -
anyMatch
@ParallelSupported @TerminalOp public <E extends Exception> boolean anyMatch(Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) - Throws:
E extends Exception
-
anyMatch
@ParallelSupported @TerminalOp public <E extends Exception> boolean anyMatch(Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) - Throws:
E extends Exception
-
allMatch
@ParallelSupported @TerminalOp public <E extends Exception> boolean allMatch(Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) - Throws:
E extends Exception
-
allMatch
@ParallelSupported @TerminalOp public <E extends Exception> boolean allMatch(Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) - Throws:
E extends Exception
-
noneMatch
@ParallelSupported @TerminalOp public <E extends Exception> boolean noneMatch(Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) - Throws:
E extends Exception
-
noneMatch
@ParallelSupported @TerminalOp public <E extends Exception> boolean noneMatch(Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) - Throws:
E extends Exception
-
nMatch
@ParallelSupported @TerminalOp public <E extends Exception> boolean nMatch(long atLeast, long atMost, Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) - Throws:
E extends Exception
-
nMatch
@ParallelSupported @TerminalOp public <E extends Exception> boolean nMatch(long atLeast, long atMost, Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) - Throws:
E extends Exception
-
findFirst
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findFirst(Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) - Throws:
E extends Exception
-
findFirst
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findFirst(Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) - Throws:
E extends Exception
-
findFirstOrAny
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findFirstOrAny(Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) Returns the first element matched bypredicateForFirst
if found or the first element if this stream is not empty Otherwise an emptyOptional<Map.Entry<K, V>>
will be returned.- Type Parameters:
E
-- Parameters:
predicate
-- Returns:
- Throws:
E
-
findFirstOrAny
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findFirstOrAny(Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) Returns the first element matched bypredicateForFirst
if found or the first element if this stream is not empty Otherwise an emptyOptional<Map.Entry<K, V>>
will be returned.- Type Parameters:
E
-- Parameters:
predicate
-- Returns:
- Throws:
E
-
findFirstOrLast
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findFirstOrLast(Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) Returns the first element matched bypredicateForFirst
if found or the last element if this stream is not empty Otherwise an emptyOptional<Map.Entry<K, V>>
will be returned.- Type Parameters:
E
-- Parameters:
predicate
-- Returns:
- Throws:
E
-
findFirstOrLast
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findFirstOrLast(Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) Returns the first element matched bypredicateForFirst
if found or the last element if this stream is not empty Otherwise an emptyOptional<Map.Entry<K, V>>
will be returned.- Type Parameters:
E
-- Parameters:
predicate
-- Returns:
- Throws:
E
-
findLast
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findLast(Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) - Throws:
E extends Exception
-
findLast
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findLast(Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) - Throws:
E extends Exception
-
findAny
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findAny(Throwables.Predicate<? super Map.Entry<K, V>, throws EE> predicate) - Throws:
E extends Exception
-
findAny
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> findAny(Throwables.BiPredicate<? super K, ? super V, throws EE> predicate) - Throws:
E extends Exception
-
first
-
last
-
elementAt
- Specified by:
elementAt
in interfaceBaseStream<Map.Entry<K,
V>, Object[], Predicate<? super Map.Entry<K, V>>, Consumer<? super Map.Entry<K, V>>, List<Map.Entry<K, V>>, u.Optional<Map.Entry<K, V>>, Indexed<Map.Entry<K, V>>, ObjIterator<Map.Entry<K, V>>, EntryStream<K, V>> - Parameters:
position
- in current stream(not upstream or origin source). It starts from 0.- Returns:
-
onlyOne
- Returns:
- Throws:
TooManyElementsException
- if there are more than one element in this stream.
-
percentiles
Description copied from interface:BaseStream
All elements will be loaded to memory and sorted if not yet.- Returns:
-
count
public long count() -
iterator
Remember to close this Stream after the iteration is done, if needed.- Returns:
-
biIterator
Remember to close this Stream after the iteration is done, if needed.- Returns:
-
toList
-
toSet
-
toCollection
-
toMultiset
-
toMultiset
-
toLongMultiset
-
toLongMultiset
public LongMultiset<Map.Entry<K,V>> toLongMultiset(Supplier<? extends LongMultiset<Map.Entry<K, V>>> supplier) -
toMap
-
toMap
- Parameters:
mergeFunction
-- Returns:
-
toMap
- Parameters:
mapFactory
-- Returns:
-
toMap
@SequentialOnly @TerminalOp public <M extends Map<K,V>> M toMap(BinaryOperator<V> mergeFunction, Supplier<? extends M> mapFactory) - Parameters:
mergeFunction
-mapFactory
-- Returns:
-
toMapAndThen
@SequentialOnly @TerminalOp public <R,E extends Exception> R toMapAndThen(Throwables.Function<? super Map<K, V>, throws E? extends R, E> func) - Throws:
E extends Exception
-
toImmutableMap
-
toImmutableMap
@SequentialOnly @TerminalOp public ImmutableMap<K,V> toImmutableMap(BinaryOperator<V> mergeFunction) -
toMultimap
- Parameters:
keyMapper
-- Returns:
- See Also:
-
toMultimap
@SequentialOnly @TerminalOp public <C extends Collection<V>,M extends Multimap<K, M toMultimapV, C>> (Supplier<? extends M> mapFactory) - Parameters:
keyMapper
-mapFactory
-- Returns:
- See Also:
-
groupTo
- Parameters:
keyMapper
-- Returns:
- See Also:
-
groupTo
@SequentialOnly @TerminalOp public <M extends Map<K,List<V>>> M groupTo(Supplier<? extends M> mapFactory) - Parameters:
keyMapper
-mapFactory
-- Returns:
- See Also:
-
groupToAndThen
@SequentialOnly @TerminalOp public <R,E extends Exception> R groupToAndThen(Throwables.Function<? super Map<K, List<V>>, throws E? extends R, E> func) - Throws:
E extends Exception
-
reduce
@SequentialOnly @TerminalOp public <E extends Exception> Map.Entry<K,V> reduce(Map.Entry<K, V> identity, Throwables.BinaryOperator<Map.Entry<K, throws EV>, E> accumulator) - Throws:
E extends Exception
-
reduce
@ParallelSupported @TerminalOp public <E extends Exception> u.Optional<Map.Entry<K,V>> reduce(Throwables.BinaryOperator<Map.Entry<K, V>, throws EE> accumulator) - Throws:
E extends Exception
-
collect
@ParallelSupported @TerminalOp public <R> R collect(Supplier<R> supplier, BiConsumer<? super R, ? super Map.Entry<K, V>> accumulator, BiConsumer<R, R> combiner) - Type Parameters:
R
-- Parameters:
supplier
-accumulator
-combiner
-- Returns:
- See Also:
-
collect
@ParallelSupported @TerminalOp public <R> R collect(Supplier<R> supplier, BiConsumer<? super R, ? super Map.Entry<K, V>> accumulator) Only call this method when the returned typeR
is one types:Collection/Map/StringBuilder/Multiset/LongMultiset/Multimap/BooleanList/IntList/.../DoubleList
. Otherwise, please callcollect(Supplier, BiConsumer, BiConsumer)
.- Parameters:
supplier
-accumulator
-- Returns:
- See Also:
-
collect
@ParallelSupported @TerminalOp public <R,A> R collect(Collector<? super Map.Entry<K, V>, A, R> collector) -
collectAndThen
@ParallelSupported @TerminalOp public <R,A, RR collectAndThenRR, E extends Exception> (Collector<? super Map.Entry<K, V>, throws EA, R> downstream, Throwables.Function<? super R, ? extends RR, E> finisher) - Throws:
E extends Exception
-
join
-
join
-
join
@SequentialOnly @TerminalOp public String join(CharSequence delimiter, CharSequence keyValueDelimiter) -
join
@SequentialOnly @TerminalOp public String join(CharSequence delimiter, CharSequence keyValueDelimiter, CharSequence prefix, CharSequence suffix) -
chain
@SequentialOnly @TerminalOp public <KK,VV> EntryStream<KK,VV> chain(Function<? super Stream<Map.Entry<K, V>>, ? extends Stream<Map.Entry<KK, VV>>> transfer) -
isParallel
public boolean isParallel() -
sequential
-
inversedToDisposableEntry
Deprecated.- Returns:
- See Also:
-
mapToDisposableEntry
@SequentialOnly @Deprecated @Beta public <KK,VV> EntryStream<KK,VV> mapToDisposableEntry(Function<? super Map.Entry<K, V>, ? extends KK> keyMapper, Function<? super Map.Entry<K, V>, ? extends VV> valueMapper) Deprecated.To reduce the memory footprint, Only one instance ofDisposableEntry
is created, and the same entry instance is returned and set with different keys/values during iteration of the returned stream. The elements only can be retrieved one by one, can't be modified or saved. The returned Stream doesn't support the operations which require two or more elements at the same time: (e.g. sort/distinct/pairMap/slidingMap/sliding/split/toList/toSet/...). , and can't be parallel stream. Operations: filter/map/toMap/groupBy/groupTo/... are supported.- Parameters:
keyMapper
-valueMapper
-- Returns:
- See Also:
-
mapToDisposableEntry
@SequentialOnly @Deprecated @Beta public <KK,VV> EntryStream<KK,VV> mapToDisposableEntry(BiFunction<? super K, ? super V, ? extends KK> keyMapper, BiFunction<? super K, ? super V, ? extends VV> valueMapper) Deprecated.- Parameters:
keyMapper
-valueMapper
-- Returns:
- See Also:
-
flatMapKeyToDisposableEntry
@SequentialOnly @Deprecated @Beta public <KK> EntryStream<KK,V> flatMapKeyToDisposableEntry(Function<? super K, ? extends Stream<? extends KK>> keyMapper) Deprecated.- Parameters:
keyMapper
-- Returns:
- See Also:
-
flatmapKeyToDisposableEntry
@SequentialOnly @Deprecated @Beta public <KK> EntryStream<KK,V> flatmapKeyToDisposableEntry(Function<? super K, ? extends Collection<? extends KK>> keyMapper) Deprecated.- Parameters:
keyMapper
-- Returns:
- See Also:
-
flatMapValueToDisposableEntry
@SequentialOnly @Deprecated @Beta public <VV> EntryStream<K,VV> flatMapValueToDisposableEntry(Function<? super V, ? extends Stream<? extends VV>> valueMapper) Deprecated.- Parameters:
valueMapper
-- Returns:
- See Also:
-
flatmapValueToDisposableEntry
@SequentialOnly @Deprecated @Beta public <VV> EntryStream<K,VV> flatmapValueToDisposableEntry(Function<? super V, ? extends Collection<? extends VV>> valueMapper) Deprecated.- Parameters:
valueMapper
-- Returns:
- See Also:
-
onClose
- Returns:
-
close
public void close()Description copied from interface:BaseStream
It will be called by terminal operations in final.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceBaseStream<Map.Entry<K,
V>, Object[], Predicate<? super Map.Entry<K, V>>, Consumer<? super Map.Entry<K, V>>, List<Map.Entry<K, V>>, u.Optional<Map.Entry<K, V>>, Indexed<Map.Entry<K, V>>, ObjIterator<Map.Entry<K, V>>, EntryStream<K, V>> - Specified by:
close
in interfaceCloseable
-
empty
-
ofNullable
-
of
-
of
-
of
-
of
-
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) -
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) -
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) -
of
-
of
public static <K,V> EntryStream<K,V> of(Iterator<? extends Map.Entry<? extends K, ? extends V>> iterator) -
of
public static <K,V> EntryStream<K,V> of(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries) -
of
-
of
-
of
-
of
-
of
public static <T,K, EntryStream<K,V> V> of(T[] a, Function<? super T, K> keyMapper, Function<? super T, V> valueMapper) -
of
-
of
public static <T,K, EntryStream<K,V> V> of(Iterable<? extends T> c, Function<? super T, K> keyMapper, Function<? super T, V> valueMapper) -
of
public static <T,K> EntryStream<K,T> of(Iterator<? extends T> iter, Function<? super T, K> keyMapper) -
of
public static <T,K, EntryStream<K,V> V> of(Iterator<? extends T> iter, Function<? super T, K> keyMapper, Function<? super T, V> valueMapper) -
concat
-
concat
-
merge
public static <K,V> EntryStream<K,V> merge(Map<K, V> a, Map<K, V> b, BiFunction<? super Map.Entry<K, V>, ? super Map.Entry<K, V>, MergeResult> nextSelector) -
merge
public static <K,V> EntryStream<K,V> merge(Map<K, V> a, Map<K, V> b, Map<K, V> c, BiFunction<? super Map.Entry<K, V>, ? super Map.Entry<K, V>, MergeResult> nextSelector) -
merge
public static <K,V> EntryStream<K,V> merge(Collection<? extends Map<K, V>> maps, BiFunction<? super Map.Entry<K, V>, ? super Map.Entry<K, V>, MergeResult> nextSelector) -
zip
-
zip
public static <K,V> EntryStream<K,V> zip(K[] keys, V[] values, K valueForNonKey, V valueForNonValue) -
zip
-
zip
public static <K,V> EntryStream<K,V> zip(Iterable<? extends K> keys, Iterable<? extends V> values, K valueForNonKey, V valueForNonValue) -
zip
-
zip
public static <K,V> EntryStream<K,V> zip(Iterator<? extends K> keys, Iterator<? extends V> values, K valueForNonKey, V valueForNonValue) -
rateLimited
- Specified by:
rateLimited
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
- See Also:
-
sliding
- Specified by:
sliding
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
- See Also:
-
slidingToList
- Specified by:
slidingToList
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
- See Also:
-
throwIfEmpty
@SequentialOnly @IntermediateOp public EntryStream<K,V> throwIfEmpty(Supplier<? extends RuntimeException> exceptionSupplier) - Specified by:
throwIfEmpty
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>>
-
toImmutableList
- Specified by:
toImmutableList
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>>
-
toImmutableSet
- Specified by:
toImmutableSet
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>>
-
println
public void println()- Specified by:
println
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>>
-
__
- Specified by:
__
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>>
-
parallel
Description copied from interface:BaseStream
Consider usingsps(Function)
if only next operation need to be parallelized. For example:stream.parallel().map(f).filter(p)...; // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream. stream.sps(s -> s.map(f)).filter(p)...; // Or switch the stream back sequential stream if don't use "sps". stream.parallel().map(f).sequential().filter(p)...;
In most scenarios, there could be only one operation need be parallelized in the stream. Sosps(Function)
is recommended in most of scenarios.- Specified by:
parallel
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
- See Also:
-
parallel
Description copied from interface:BaseStream
Consider usingsps(int, Function)
if only next operation need to be parallelized. For example:stream.parallel(maxThreadNum).map(f).filter(p)...; // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream. stream.sps(maxThreadNum, s -> s.map(f)).filter(p)...; // Or switch the stream back sequential stream if don't use "sps". stream.parallel(maxThreadNum).map(f).sequential().filter(p)...;
In most scenarios, there could be only one operation need be parallelized in the stream. Sosps(int, Function)
is recommended in most of scenarios.- Specified by:
parallel
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Parameters:
maxThreadNum
-- Returns:
- See Also:
-
#maxThreadNumPerOperation()
-
parallel
- Specified by:
parallel
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
- See Also:
-
parallel
Description copied from interface:BaseStream
Returns an equivalent stream that is parallel. May return itself if the stream was already parallel with the samemaxThreadNum
andsplitor
as the specified ones.
When to use parallel Streams?- First of all, do NOT and should NOT use parallel Streams if you don't have any problem with sequential Streams, because using parallel Streams has extra cost.
- Consider using parallel Streams only when N(the number of elements) * Q(cost per element of F, the per-element function (usually a lambda)) is big enough(e.g. IO involved. Network: DB/web service request..., Reading/Writing file...).
- It's easy to test out the differences of performance by sequential Streams and parallel Streams with Profiler:
Profiler.run(1, 1, 3, "sequential", () -> Stream.of(list).operation(F)...).printResult(); Profiler.run(1, 1, 3, "parallel", () -> Stream.of(list).parallel().operation(F)...).printResult();
public void test_perf() { final String[] strs = new String[10_000]; N.fill(strs, N.uuid()); final int m = 10; final Function<String, Long> mapper = str -> { long result = 0; for (int i = 0; i < m; i++) { result += N.sum(str.toCharArray()) + 1; } return result; }; final MutableLong sum = MutableLong.of(0); for (int i = 0, len = strs.length; i < len; i++) { sum.add(mapper.apply(strs[i])); } final int threadNum = 1, loopNum = 100, roundNum = 3; Profiler.run(threadNum, loopNum, roundNum, "For Loop", () -> { long result = 0; for (int i = 0, len = strs.length; i < len; i++) { result += mapper.apply(strs[i]); } assertEquals(sum.longValue(), result); }).printResult(); Profiler.run(threadNum, loopNum, roundNum, "JDK Sequential", () -> assertEquals(sum.longValue(), java.util.stream.Stream.of(strs).map(mapper).mapToLong(e -> e).sum())).printResult(); Profiler.run(threadNum, loopNum, roundNum, "JDK Parallel", () -> assertEquals(sum.longValue(), java.util.stream.Stream.of(strs).parallel().map(mapper).mapToLong(e -> e).sum())).printResult(); Profiler.run(threadNum, loopNum, roundNum, "Abcus Sequential", () -> assertEquals(sum.longValue(), Stream.of(strs).map(mapper).mapToLong(e -> e).sum())) .printResult(); Profiler.run(threadNum, loopNum, roundNum, "Abcus Parallel", () -> assertEquals(sum.longValue(), Stream.of(strs).parallel().map(mapper).mapToLong(e -> e).sum())).printResult(); Profiler.run(threadNum, loopNum, roundNum, "Abcus Parallel by chunck", () -> assertEquals(sum.longValue(), Stream.of(strs).splitToList(100).parallel().map(it -> N.sumLong(it, e -> mapper.apply(e))).mapToLong(e -> e).sum())).printResult(); }
mapper
) is calculated by: value of 'For loop' / N(10_000).m = 1 m = 10 m = 50 m = 100 m = 500 m = 1000 Q 0.00002 0.0002 0.001 0.002 0.01 0.02 For Loop 0.23 2.3 11 22 110 219 JDK Sequential 0.28 2.3 11 22 114 212 JDK Parallel 0.22 1.3 6 12 66 122 Abcus Sequential 0.3 2 11 22 112 212 Abcus Parallel 11 11 11 16 77 128 - Again, do NOT and should NOT use parallel Streams if you don't have any performance problem with sequential Streams, because using parallel Streams has extra cost.
- Again, consider using parallel Streams only when N(the number of elements) * Q(cost per element of F, the per-element function (usually a lambda)) is big enough.
- The implementation of parallel Streams in Abacus is more than 10 times, slower than parallel Streams in JDK when Q is tiny(here is less than 0.0002 milliseconds by the test):
- The implementation of parallel Streams in JDK 8 still can beat the sequential/for loop when Q is tiny(Here is 0.00002 milliseconds by the test). That's amazing, considering the extra cost brought by parallel computation. It's well done.
- The implementation of parallel Streams in Abacus is pretty simple and straight forward. The extra cost(starting threads/synchronization/queue...) brought by parallel Streams in Abacus is too bigger to tiny Q(Here is less than 0.001 milliseconds by the test). But it starts to be faster than sequential Streams when Q is big enough(Here is 0.001 milliseconds by the test) and starts to catch the parallel Streams in JDK when Q is bigger(Here is 0.01 milliseconds by the test).
- Consider using the parallel Streams in Abacus when Q is big enough, specially when IO involved in F. Because one IO operation(e.g. DB/web service request..., Reading/Writing file...) usually takes 1 to 1000 milliseconds, or even longer. By the parallel Streams APIs in Abacus, it's very simple to specify max thread numbers. Sometimes, it's much faster to execute IO/Network requests with a bit more threads. It's fair to say that the parallel Streams in Abacus is high efficient, may same as or faster than the parallel Streams in JDK when Q is big enough, except F is heavy cpu-used operation. Most of the times, the Q is big enough to consider using parallel Stream is because IO/Network is involved in F.
- JDK 7 is supported by the Streams in Abacus. It's perfect to work with retrolambda on Android
- All primitive types are supported by Stream APIs in Abacus except boolean
A bit more about Lambdas/Stream APIs, you may heard that Lambdas/Stream APIs is 5 time slower than imperative programming. It's true when Q and F is VERY, VERY tiny, likef = (int a, int b) -> a + b;
. But if we look into the samples in the article and think about it: it just takes less than 1 milliseconds to get the max value in 100k numbers. There is potential performance issue only if the "get the max value in 100K numbers" call many, many times in your API or single request. Otherwise, the difference between 0.1 milliseconds to 0.5 milliseconds can be totally ignored. Usually we meet performance issue only if Q and F is big enough. However, the performance of Lambdas/Streams APIs is closed to for loop when Q and F is big enough. No matter in which scenario, We don't need and should not concern the performance of Lambdas/Stream APIs.
Although it's is parallel Streams, it doesn't means all the methods are executed in parallel. Because the sequential way is as fast, or even faster than the parallel way for some methods, or is pretty difficult, if not possible, to implement the method by parallel approach. Here are the methods which are executed sequentially even in parallel Streams.
splitXXX/splitAt/splitBy/slidingXXX/collapse, distinct, reverse, rotate, shuffle, indexed, cached, top, kthLargest, count, toArray, toList, toList, toSet, toMultiset, toLongMultiset, intersection(Collection c), difference(Collection c), symmetricDifference(Collection c), forEach(identity, accumulator, predicate), findFirstOrLast, findFirstAndLast- Specified by:
parallel
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Parameters:
maxThreadNum
-splitor
-- Returns:
- See Also:
-
#maxThreadNumPerOperation()
-
parallel
Description copied from interface:BaseStream
// Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream. stream.sps(SP.create(maxThreadNum, executor), s -> s.map(f)).filter(p)...; // Or switch the stream back sequential stream if don't use "sps". stream.parallel(maxThreadNum, executor).map(f).sequential().filter(p)...;- Specified by:
parallel
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Parameters:
maxThreadNum
- if the specified value is bigger than the maximum allowed thread number per operation (min(64, cpu_cores * 8)
) andexecutor
is not specified with a non-null value, maximum allowed thread number per operation will be used. To parallelize this Stream with thread number bigger thanmin(64, cpu_cores * 8)
, please specifyexecutor
with a non-null value.- Returns:
- See Also:
-
parallel
Description copied from interface:BaseStream
stream.parallel(executor).map(f).filter(p)...; // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream. stream.sps(SP.create(executor), s -> s.map(f)).filter(p)...; // Or switch the stream back sequential stream if don't use "sps". stream.parallel(executor).map(f).sequential().filter(p)...;
- Specified by:
parallel
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
- See Also:
-
parallel
Description copied from interface:BaseStream
stream.parallel(maxThreadNum, splitor, executor).map(f).filter(p)...; // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream. stream.sps(SP.create(maxThreadNum, splitor, executor), s -> s.map(f)).filter(p)...; // Or switch the stream back sequential stream if don't use "sps". stream.parallel(maxThreadNum, splitor, executor).map(f).sequential().filter(p)...;
- Specified by:
parallel
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Parameters:
maxThreadNum
- if the specified value is bigger than the maximum allowed thread number per operation (min(64, cpu_cores * 8)
) andexecutor
is not specified with a non-null value, maximum allowed thread number per operation will be used. To parallelize this Stream with thread number bigger thanmin(64, cpu_cores * 8)
, please specifyexecutor
with a non-null value.- Returns:
- See Also:
-
parallel
Description copied from interface:BaseStream
stream.parallel(parallelSettings).map(f).filter(p)...; // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream. stream.sps(SP.create(parallelSettings), s -> s.map(f)).filter(p)...; // Or switch the stream back sequential stream if don't use "sps". stream.parallel(parallelSettings).map(f).sequential().filter(p)...;
- Specified by:
parallel
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
- See Also:
-
sps
Description copied from interface:BaseStream
Temporarily switch the stream to parallel stream for operationops
and then switch back to sequence stream.
stream().parallel().ops(map/filter/...).sequence()
- Specified by:
sps
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
-
sps
public <SS extends BaseStream> SS sps(int maxThreadNum, Function<? super EntryStream<K, V>, ? extends SS> ops) Description copied from interface:BaseStream
Temporarily switch the stream to parallel stream for operationops
and then switch back to sequence stream.
stream().parallel(maxThreadNum).ops(map/filter/...).sequence()
- Specified by:
sps
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
-
psp
Description copied from interface:BaseStream
Temporarily switch the stream to sequence stream for operationops
and then switch back to parallel stream with samemaxThreadNum/splitor/asyncExecutor
.
stream().sequence().ops(map/filter/...).parallel(sameMaxThreadNum, sameSplitor, sameAsyncExecutor)
- Specified by:
psp
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>> - Returns:
-
toArray
- Specified by:
toArray
in interfaceBaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends com.landawn.abacus.util.stream.StreamBase<T, A, P, C, PL, OT, IT, ITER, S>>
-