Package com.landawn.abacus.util.stream
Class FloatStream
- java.lang.Object
-
- com.landawn.abacus.util.stream.FloatStream
-
- All Implemented Interfaces:
BaseStream<Float,float[],FloatPredicate,FloatConsumer,FloatList,u.OptionalFloat,IndexedFloat,FloatIterator,FloatStream>
,AutoCloseable
- Direct Known Subclasses:
FloatStream.FloatStreamEx
public abstract class FloatStream extends Object
The Stream will be automatically closed after execution(A terminal method is executed/triggered).- See Also:
BaseStream
,Stream
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FloatStream.FloatStreamEx
-
Nested classes/interfaces inherited from interface com.landawn.abacus.util.stream.BaseStream
BaseStream.Splitor
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <SS extends BaseStream>
SS__(Function<? super FloatStream,SS> transfer)
abstract <E extends Exception>
booleanallMatch(Throwables.FloatPredicate<E> predicate)
abstract <E extends Exception>
booleananyMatch(Throwables.FloatPredicate<E> predicate)
abstract FloatStream
append(float... a)
abstract FloatStream
appendIfEmpty(float... a)
abstract DoubleStream
asDoubleStream()
abstract u.OptionalDouble
average()
abstract Stream<Float>
boxed()
S
carry(C action)
Same aspeek
void
close()
abstract Stream<FloatList>
collapse(FloatBiPredicate collapsible)
Merge series of adjacent elements which satisfy the given predicate using the merger function and return a new stream.abstract FloatStream
collapse(FloatBiPredicate collapsible, FloatBinaryOperator mergeFunction)
Merge series of adjacent elements which satisfy the given predicate using the merger function and return a new stream.abstract <R> R
collect(Supplier<R> supplier, ObjFloatConsumer<? super R> accumulator)
abstract <R> R
collect(Supplier<R> supplier, ObjFloatConsumer<? super R> accumulator, BiConsumer<R,R> combiner)
static FloatStream
concat(float[]... a)
static FloatStream
concat(FloatIterator... a)
static FloatStream
concat(FloatStream... a)
static FloatStream
concat(Collection<? extends FloatStream> c)
static FloatStream
empty()
abstract <E extends Exception>
u.OptionalFloatfindAny(Throwables.FloatPredicate<E> predicate)
abstract <E extends Exception>
u.OptionalFloatfindFirst(Throwables.FloatPredicate<E> predicate)
abstract <E extends Exception,E2 extends Exception>
u.OptionalFloatfindFirstOrLast(Throwables.FloatPredicate<E> predicateForFirst, Throwables.FloatPredicate<E> predicateForLast)
abstract <E extends Exception>
u.OptionalFloatfindLast(Throwables.FloatPredicate<E> predicate)
Consider using:stream.reversed().findFirst(predicate)
for better performance if possible.abstract FloatStream
flatMap(FloatFunction<? extends FloatStream> mapper)
abstract <T> Stream<T>
flatMappToObj(FloatFunction<T[]> mapper)
abstract DoubleStream
flatMapToDouble(FloatFunction<? extends DoubleStream> mapper)
abstract IntStream
flatMapToInt(FloatFunction<? extends IntStream> mapper)
abstract LongStream
flatMapToLong(FloatFunction<? extends LongStream> mapper)
abstract <T> Stream<T>
flatMapToObj(FloatFunction<? extends Stream<T>> mapper)
static FloatStream
flatten(float[][] a)
static FloatStream
flatten(float[][][] a)
static FloatStream
flatten(float[][] a, boolean vertically)
static FloatStream
flatten(float[][] a, float valueForNone, boolean vertically)
abstract FloatStream
flattMap(FloatFunction<float[]> mapper)
abstract <T> Stream<T>
flattMapToObj(FloatFunction<? extends Collection<T>> mapper)
abstract <E extends Exception>
voidforEach(Throwables.FloatConsumer<E> action)
abstract <E extends Exception>
voidforEachIndexed(Throwables.IndexedFloatConsumer<E> action)
static FloatStream
generate(FloatSupplier s)
boolean
isParallel()
static FloatStream
iterate(float init, BooleanSupplier hasNext, FloatUnaryOperator f)
static FloatStream
iterate(float init, FloatPredicate hasNext, FloatUnaryOperator f)
static FloatStream
iterate(float init, FloatUnaryOperator f)
static FloatStream
iterate(BooleanSupplier hasNext, FloatSupplier next)
FloatIterator
iterator()
Remember to close this Stream after the iteration is done, if needed.String
join(CharSequence delimiter)
abstract u.OptionalFloat
kthLargest(int k)
abstract FloatStream
map(FloatUnaryOperator mapper)
abstract DoubleStream
mapToDouble(FloatToDoubleFunction mapper)
abstract IntStream
mapToInt(FloatToIntFunction mapper)
abstract LongStream
mapToLong(FloatToLongFunction mapper)
abstract <U> Stream<U>
mapToObj(FloatFunction<? extends U> mapper)
abstract u.OptionalFloat
max()
static FloatStream
merge(float[] a, float[] b, float[] c, FloatBiFunction<MergeResult> nextSelector)
static FloatStream
merge(float[] a, float[] b, FloatBiFunction<MergeResult> nextSelector)
static FloatStream
merge(FloatIterator a, FloatIterator b, FloatIterator c, FloatBiFunction<MergeResult> nextSelector)
static FloatStream
merge(FloatIterator a, FloatIterator b, FloatBiFunction<MergeResult> nextSelector)
abstract FloatStream
merge(FloatStream b, FloatBiFunction<MergeResult> nextSelector)
static FloatStream
merge(FloatStream a, FloatStream b, FloatBiFunction<MergeResult> nextSelector)
static FloatStream
merge(FloatStream a, FloatStream b, FloatStream c, FloatBiFunction<MergeResult> nextSelector)
static FloatStream
merge(Collection<? extends FloatStream> c, FloatBiFunction<MergeResult> nextSelector)
abstract u.OptionalFloat
min()
abstract <E extends Exception>
booleannoneMatch(Throwables.FloatPredicate<E> predicate)
static FloatStream
of(float... a)
static FloatStream
of(float[] a, int startIndex, int endIndex)
static FloatStream
of(FloatIterator iterator)
static FloatStream
of(Supplier<FloatList> supplier)
Lazy evaluation.static FloatStream
of(Float[] a)
static FloatStream
of(Float[] a, int startIndex, int endIndex)
static FloatStream
of(Collection<Float> c)
S
parallel()
S
parallel(int maxThreadNum)
S
parallel(int maxThreadNum, BaseStream.Splitor splitor)
Returns an equivalent stream that is parallel.S
parallel(int maxThreadNum, BaseStream.Splitor splitor, Executor executor)
S
parallel(int maxThreadNum, Executor executor)
S
parallel(BaseStream.Splitor splitor)
S
parallel(Executor executor)
static FloatStream
parallelMerge(Collection<? extends FloatStream> c, FloatBiFunction<MergeResult> nextSelector)
static FloatStream
parallelMerge(Collection<? extends FloatStream> c, FloatBiFunction<MergeResult> nextSelector, int maxThreadNum)
abstract FloatStream
prepend(float... a)
void
println()
static FloatStream
random()
abstract FloatStream
rangeMap(FloatBiPredicate sameRange, FloatBinaryOperator mapper)
Note: copied from StreamEx: https://github.com/amaembo/streamex
Returns a stream consisting of results of applying the given function to the ranges created from the source elements.abstract <T> Stream<T>
rangeMapToObj(FloatBiPredicate sameRange, FloatBiFunction<T> mapper)
Note: copied from StreamEx: https://github.com/amaembo/streamex
Returns a stream consisting of results of applying the given function to the ranges created from the source elements.abstract float
reduce(float identity, FloatBinaryOperator op)
abstract u.OptionalFloat
reduce(FloatBinaryOperator op)
static FloatStream
repeat(float element, long n)
abstract FloatStream
scan(float init, FloatBinaryOperator accumulator)
Returns aStream
produced by iterative application of a accumulation function to an initial elementinit
and next element of the current stream.abstract FloatStream
scan(float init, FloatBinaryOperator accumulator, boolean initIncluded)
abstract FloatStream
scan(FloatBinaryOperator accumulator)
Returns aStream
produced by iterative application of a accumulation function to an initial elementinit
and next element of the current stream.S
sequential()
S
shuffled()
This method only run sequentially, even in parallel stream and all elements will be loaded to memory.FloatStream
skipUntil(FloatPredicate predicate)
Stream<S>
sliding(int windowSize)
Stream<PL>
slidingToList(int windowSize)
abstract double
sum()
abstract FloatSummaryStatistics
summarize()
abstract Pair<FloatSummaryStatistics,u.Optional<Map<Percentage,Float>>>
summarizeAndPercentiles()
abstract FloatList
toFloatList()
ImmutableList<T>
toImmutableList()
ImmutableSet<T>
toImmutableSet()
abstract <K,V>
Map<K,V>toMap(FloatFunction<? extends K> keyMapper, FloatFunction<? extends V> valueMapper)
abstract <K,V>
Map<K,V>toMap(FloatFunction<? extends K> keyMapper, FloatFunction<? extends V> valueMapper, BinaryOperator<V> mergeFunction)
abstract <K,V,M extends Map<K,V>>
MtoMap(FloatFunction<? extends K> keyMapper, FloatFunction<? extends V> valueMapper, BinaryOperator<V> mergeFunction, Supplier<? extends M> mapFactory)
abstract <K,V,M extends Map<K,V>>
MtoMap(FloatFunction<? extends K> keyMapper, FloatFunction<? extends V> valueMapper, Supplier<? extends M> mapFactory)
abstract <K,A,D>
Map<K,D>toMap(FloatFunction<? extends K> keyMapper, Collector<Float,A,D> downstream)
abstract <K,A,D,M extends Map<K,D>>
MtoMap(FloatFunction<? extends K> keyMapper, Collector<Float,A,D> downstream, Supplier<? extends M> mapFactory)
abstract FloatStream
top(int n)
This method only run sequentially, even in parallel stream.abstract FloatStream
top(int n, Comparator<? super Float> comparator)
This method only run sequentially, even in parallel stream.static FloatStream
zip(float[] a, float[] b, float[] c, float valueForNoneA, float valueForNoneB, float valueForNoneC, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" iterators until all of them runs out of values.static FloatStream
zip(float[] a, float[] b, float[] c, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" arrays until one of them runs out of values.static FloatStream
zip(float[] a, float[] b, float valueForNoneA, float valueForNoneB, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" iterators until all of them runs out of values.static FloatStream
zip(float[] a, float[] b, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" arrays until one of them runs out of values.static FloatStream
zip(FloatIterator a, FloatIterator b, float valueForNoneA, float valueForNoneB, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" iterators until all of them runs out of values.static FloatStream
zip(FloatIterator a, FloatIterator b, FloatIterator c, float valueForNoneA, float valueForNoneB, float valueForNoneC, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" iterators until all of them runs out of values.static FloatStream
zip(FloatIterator a, FloatIterator b, FloatIterator c, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" iterators until one of them runs out of values.static FloatStream
zip(FloatIterator a, FloatIterator b, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" iterators until one of them runs out of values.static FloatStream
zip(FloatStream a, FloatStream b, float valueForNoneA, float valueForNoneB, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" iterators until all of them runs out of values.static FloatStream
zip(FloatStream a, FloatStream b, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" streams until one of them runs out of values.static FloatStream
zip(FloatStream a, FloatStream b, FloatStream c, float valueForNoneA, float valueForNoneB, float valueForNoneC, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" iterators until all of them runs out of values.static FloatStream
zip(FloatStream a, FloatStream b, FloatStream c, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" streams until one of them runs out of values.static FloatStream
zip(Collection<? extends FloatStream> c, float[] valuesForNone, FloatNFunction<Float> zipFunction)
Zip together the iterators until all of them runs out of values.static FloatStream
zip(Collection<? extends FloatStream> c, FloatNFunction<Float> zipFunction)
Zip together the iterators until one of them runs out of values.abstract FloatStream
zipWith(FloatStream b, float valueForNoneA, float valueForNoneB, FloatBinaryOperator zipFunction)
abstract FloatStream
zipWith(FloatStream b, FloatBinaryOperator zipFunction)
abstract FloatStream
zipWith(FloatStream b, FloatStream c, float valueForNoneA, float valueForNoneB, float valueForNoneC, FloatTernaryOperator zipFunction)
abstract FloatStream
zipWith(FloatStream b, FloatStream c, FloatTernaryOperator zipFunction)
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.landawn.abacus.util.stream.BaseStream
acceptIfNotEmpty, append, appendIfEmpty, applyIfNotEmpty, count, difference, distinct, dropWhile, dropWhile, filter, filter, first, indexed, intersection, join, last, limit, onClose, onlyOne, peek, percentiles, prepend, removeIf, removeIf, reversed, reverseSorted, rotated, shuffled, skip, skip, sliding, slidingToList, sorted, split, split, splitAt, splitBy, splitToList, splitToList, step, symmetricDifference, takeWhile, toArray, toCollection, toList, toLongMultiset, toLongMultiset, toMultiset, toMultiset, toSet
-
-
-
-
Method Detail
-
skipUntil
@ParallelSupported @IntermediateOp @Beta public FloatStream skipUntil(FloatPredicate predicate)
-
map
public abstract FloatStream map(FloatUnaryOperator mapper)
-
mapToInt
public abstract IntStream mapToInt(FloatToIntFunction mapper)
-
mapToLong
public abstract LongStream mapToLong(FloatToLongFunction mapper)
-
mapToDouble
public abstract DoubleStream mapToDouble(FloatToDoubleFunction mapper)
-
mapToObj
public abstract <U> Stream<U> mapToObj(FloatFunction<? extends U> mapper)
-
flatMap
public abstract FloatStream flatMap(FloatFunction<? extends FloatStream> mapper)
-
flattMap
public abstract FloatStream flattMap(FloatFunction<float[]> mapper)
-
flatMapToInt
public abstract IntStream flatMapToInt(FloatFunction<? extends IntStream> mapper)
-
flatMapToLong
public abstract LongStream flatMapToLong(FloatFunction<? extends LongStream> mapper)
-
flatMapToDouble
public abstract DoubleStream flatMapToDouble(FloatFunction<? extends DoubleStream> mapper)
-
flatMapToObj
public abstract <T> Stream<T> flatMapToObj(FloatFunction<? extends Stream<T>> mapper)
-
flattMapToObj
public abstract <T> Stream<T> flattMapToObj(FloatFunction<? extends Collection<T>> mapper)
-
flatMappToObj
public abstract <T> Stream<T> flatMappToObj(FloatFunction<T[]> mapper)
-
rangeMap
@SequentialOnly public abstract FloatStream rangeMap(FloatBiPredicate sameRange, FloatBinaryOperator mapper)
Note: copied from StreamEx: https://github.com/amaembo/streamex
Returns a stream consisting of results of applying the given function to the ranges created from the source elements. This is a quasi-intermediate partial reduction operation.- Parameters:
sameRange
- a non-interfering, stateless predicate to apply to the leftmost and next elements which returns true for elements which belong to the same range.mapper
- a non-interfering, stateless function to apply to the range borders and produce the resulting element. If value was not merged to the interval, then mapper will receive the same value twice, otherwise it will receive the leftmost and the rightmost values which were merged to the range.- Returns:
- See Also:
collapse(FloatBiPredicate, FloatBinaryOperator)
,Stream.rangeMap(BiPredicate, BiFunction)
-
rangeMapToObj
@SequentialOnly public abstract <T> Stream<T> rangeMapToObj(FloatBiPredicate sameRange, FloatBiFunction<T> mapper)
Note: copied from StreamEx: https://github.com/amaembo/streamex
Returns a stream consisting of results of applying the given function to the ranges created from the source elements. This is a quasi-intermediate partial reduction operation.- Parameters:
sameRange
- a non-interfering, stateless predicate to apply to the leftmost and next elements which returns true for elements which belong to the same range.mapper
- a non-interfering, stateless function to apply to the range borders and produce the resulting element. If value was not merged to the interval, then mapper will receive the same value twice, otherwise it will receive the leftmost and the rightmost values which were merged to the range.- Returns:
- See Also:
Stream.rangeMap(BiPredicate, BiFunction)
-
collapse
@SequentialOnly public abstract Stream<FloatList> collapse(FloatBiPredicate collapsible)
Merge series of adjacent elements which satisfy the given predicate using the merger function and return a new stream.
This method only run sequentially, even in parallel stream.- Parameters:
collapsible
-- Returns:
-
collapse
@SequentialOnly public abstract FloatStream collapse(FloatBiPredicate collapsible, FloatBinaryOperator mergeFunction)
Merge series of adjacent elements which satisfy the given predicate using the merger function and return a new stream.
This method only run sequentially, even in parallel stream.- Parameters:
collapsible
-mergeFunction
-- Returns:
-
scan
@SequentialOnly public abstract FloatStream scan(FloatBinaryOperator accumulator)
Returns aStream
produced by iterative application of a accumulation function to an initial elementinit
and next element of the current stream. Produces aStream
consisting ofinit
,acc(init, value1)
,acc(acc(init, value1), value2)
, etc.This is an intermediate operation.
Example:
accumulator: (a, b) -> a + b stream: [1, 2, 3, 4, 5] result: [1, 3, 6, 10, 15]
This method only run sequentially, even in parallel stream.- Parameters:
accumulator
- the accumulation function- Returns:
-
scan
@SequentialOnly public abstract FloatStream scan(float init, FloatBinaryOperator accumulator)
Returns aStream
produced by iterative application of a accumulation function to an initial elementinit
and next element of the current stream. Produces aStream
consisting ofinit
,acc(init, value1)
,acc(acc(init, value1), value2)
, etc.This is an intermediate operation.
Example:
init:10 accumulator: (a, b) -> a + b stream: [1, 2, 3, 4, 5] result: [11, 13, 16, 20, 25]
This method only run sequentially, even in parallel stream.- Parameters:
init
- the initial value. it's only used once byaccumulator
to calculate the fist element in the returned stream. It will be ignored if this stream is empty and won't be the first element of the returned stream.accumulator
- the accumulation function- Returns:
-
scan
@SequentialOnly public abstract FloatStream scan(float init, FloatBinaryOperator accumulator, boolean initIncluded)
- Parameters:
init
-accumulator
-initIncluded
-- Returns:
-
prepend
public abstract FloatStream prepend(float... a)
-
append
public abstract FloatStream append(float... a)
-
appendIfEmpty
public abstract FloatStream appendIfEmpty(float... a)
-
top
@SequentialOnly public abstract FloatStream top(int n)
This method only run sequentially, even in parallel stream.- Parameters:
n
-- Returns:
-
top
@SequentialOnly public abstract FloatStream top(int n, Comparator<? super Float> comparator)
This method only run sequentially, even in parallel stream.- Parameters:
n
-- Returns:
-
toFloatList
public abstract FloatList toFloatList()
-
toMap
public abstract <K,V> Map<K,V> toMap(FloatFunction<? extends K> keyMapper, FloatFunction<? extends V> valueMapper)
- Parameters:
keyMapper
-valueMapper
-- Returns:
- See Also:
Collectors.toMap(Function, Function)
-
toMap
public abstract <K,V,M extends Map<K,V>> M toMap(FloatFunction<? extends K> keyMapper, FloatFunction<? extends V> valueMapper, Supplier<? extends M> mapFactory)
- Parameters:
keyMapper
-valueMapper
-mapFactory
-- Returns:
- See Also:
Collectors.toMap(Function, Function, Supplier)
-
toMap
public abstract <K,V> Map<K,V> toMap(FloatFunction<? extends K> keyMapper, FloatFunction<? extends V> valueMapper, BinaryOperator<V> mergeFunction)
- Parameters:
keyMapper
-valueMapper
-mergeFunction
-- Returns:
- See Also:
Collectors.toMap(Function, Function, BinaryOperator)
-
toMap
public abstract <K,V,M extends Map<K,V>> M toMap(FloatFunction<? extends K> keyMapper, FloatFunction<? extends V> valueMapper, BinaryOperator<V> mergeFunction, Supplier<? extends M> mapFactory)
- Parameters:
keyMapper
-valueMapper
-mergeFunction
-mapFactory
-- Returns:
- See Also:
Collectors.toMap(Function, Function, BinaryOperator, Supplier)
-
toMap
public abstract <K,A,D> Map<K,D> toMap(FloatFunction<? extends K> keyMapper, Collector<Float,A,D> downstream)
- Parameters:
keyMapper
-downstream
-- Returns:
- See Also:
Collectors.groupingBy(Function, Collector)
-
toMap
public abstract <K,A,D,M extends Map<K,D>> M toMap(FloatFunction<? extends K> keyMapper, Collector<Float,A,D> downstream, Supplier<? extends M> mapFactory)
- Parameters:
keyMapper
-downstream
-mapFactory
-- Returns:
- See Also:
Collectors.groupingBy(Function, Collector, Supplier)
-
reduce
public abstract float reduce(float identity, FloatBinaryOperator op)
-
reduce
public abstract u.OptionalFloat reduce(FloatBinaryOperator op)
-
collect
public abstract <R> R collect(Supplier<R> supplier, ObjFloatConsumer<? super R> accumulator, BiConsumer<R,R> combiner)
-
collect
public abstract <R> R collect(Supplier<R> supplier, ObjFloatConsumer<? super R> accumulator)
-
forEach
@ParallelSupported @TerminalOp public abstract <E extends Exception> void forEach(Throwables.FloatConsumer<E> action) throws E extends Exception
- Throws:
E extends Exception
-
forEachIndexed
@ParallelSupported @TerminalOp public abstract <E extends Exception> void forEachIndexed(Throwables.IndexedFloatConsumer<E> action) throws E extends Exception
- Throws:
E extends Exception
-
anyMatch
public abstract <E extends Exception> boolean anyMatch(Throwables.FloatPredicate<E> predicate) throws E extends Exception
- Throws:
E extends Exception
-
allMatch
public abstract <E extends Exception> boolean allMatch(Throwables.FloatPredicate<E> predicate) throws E extends Exception
- Throws:
E extends Exception
-
noneMatch
public abstract <E extends Exception> boolean noneMatch(Throwables.FloatPredicate<E> predicate) throws E extends Exception
- Throws:
E extends Exception
-
findFirst
public abstract <E extends Exception> u.OptionalFloat findFirst(Throwables.FloatPredicate<E> predicate) throws E extends Exception
- Throws:
E extends Exception
-
findLast
public abstract <E extends Exception> u.OptionalFloat findLast(Throwables.FloatPredicate<E> predicate) throws E extends Exception
Consider using:stream.reversed().findFirst(predicate)
for better performance if possible.- Type Parameters:
E
-- Parameters:
predicate
-- Returns:
- Throws:
E
E extends Exception
-
findFirstOrLast
public abstract <E extends Exception,E2 extends Exception> u.OptionalFloat findFirstOrLast(Throwables.FloatPredicate<E> predicateForFirst, Throwables.FloatPredicate<E> predicateForLast) throws E extends Exception, E2 extends Exception
- Throws:
E extends Exception
-
findAny
public abstract <E extends Exception> u.OptionalFloat findAny(Throwables.FloatPredicate<E> predicate) throws E extends Exception
- Throws:
E extends Exception
-
min
public abstract u.OptionalFloat min()
-
max
public abstract u.OptionalFloat max()
-
kthLargest
public abstract u.OptionalFloat kthLargest(int k)
- Parameters:
k
-- Returns:
- OptionalByte.empty() if there is no element or count less than k, otherwise the kth largest element.
-
sum
public abstract double sum()
-
average
public abstract u.OptionalDouble average()
-
summarize
public abstract FloatSummaryStatistics summarize()
-
summarizeAndPercentiles
public abstract Pair<FloatSummaryStatistics,u.Optional<Map<Percentage,Float>>> summarizeAndPercentiles()
-
merge
public abstract FloatStream merge(FloatStream b, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
b
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
zipWith
public abstract FloatStream zipWith(FloatStream b, FloatBinaryOperator zipFunction)
-
zipWith
public abstract FloatStream zipWith(FloatStream b, FloatStream c, FloatTernaryOperator zipFunction)
-
zipWith
public abstract FloatStream zipWith(FloatStream b, float valueForNoneA, float valueForNoneB, FloatBinaryOperator zipFunction)
-
zipWith
public abstract FloatStream zipWith(FloatStream b, FloatStream c, float valueForNoneA, float valueForNoneB, float valueForNoneC, FloatTernaryOperator zipFunction)
-
asDoubleStream
public abstract DoubleStream asDoubleStream()
-
iterator
@SequentialOnly public FloatIterator iterator()
Remember to close this Stream after the iteration is done, if needed.- Returns:
-
__
@SequentialOnly @Beta public <SS extends BaseStream> SS __(Function<? super FloatStream,SS> transfer)
-
empty
public static FloatStream empty()
-
of
@SafeVarargs public static FloatStream of(float... a)
-
of
public static FloatStream of(float[] a, int startIndex, int endIndex)
-
of
public static FloatStream of(Float[] a)
-
of
public static FloatStream of(Float[] a, int startIndex, int endIndex)
-
of
public static FloatStream of(Collection<Float> c)
-
of
public static FloatStream of(FloatIterator iterator)
-
of
public static FloatStream of(Supplier<FloatList> supplier)
Lazy evaluation.- Parameters:
supplier
-- Returns:
-
flatten
public static FloatStream flatten(float[][] a)
-
flatten
public static FloatStream flatten(float[][] a, boolean vertically)
-
flatten
public static FloatStream flatten(float[][] a, float valueForNone, boolean vertically)
-
flatten
public static FloatStream flatten(float[][][] a)
-
repeat
public static FloatStream repeat(float element, long n)
-
random
public static FloatStream random()
-
iterate
public static FloatStream iterate(BooleanSupplier hasNext, FloatSupplier next)
-
iterate
public static FloatStream iterate(float init, BooleanSupplier hasNext, FloatUnaryOperator f)
-
iterate
public static FloatStream iterate(float init, FloatPredicate hasNext, FloatUnaryOperator f)
- Parameters:
init
-hasNext
- test if has next by hasNext.test(init) for first time and hasNext.test(f.apply(previous)) for remaining.f
-- Returns:
-
iterate
public static FloatStream iterate(float init, FloatUnaryOperator f)
-
generate
public static FloatStream generate(FloatSupplier s)
-
concat
@SafeVarargs public static FloatStream concat(float[]... a)
-
concat
@SafeVarargs public static FloatStream concat(FloatIterator... a)
-
concat
@SafeVarargs public static FloatStream concat(FloatStream... a)
-
concat
public static FloatStream concat(Collection<? extends FloatStream> c)
-
zip
public static FloatStream zip(float[] a, float[] b, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" arrays until one of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-- Returns:
-
zip
public static FloatStream zip(float[] a, float[] b, float[] c, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" arrays until one of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-c
-- Returns:
-
zip
public static FloatStream zip(FloatIterator a, FloatIterator b, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" iterators until one of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-- Returns:
-
zip
public static FloatStream zip(FloatIterator a, FloatIterator b, FloatIterator c, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" iterators until one of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-- Returns:
-
zip
public static FloatStream zip(FloatStream a, FloatStream b, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" streams until one of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-- Returns:
-
zip
public static FloatStream zip(FloatStream a, FloatStream b, FloatStream c, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" streams until one of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-- Returns:
-
zip
public static FloatStream zip(Collection<? extends FloatStream> c, FloatNFunction<Float> zipFunction)
Zip together the iterators until one of them runs out of values. Each array of values is combined into a single value using the supplied zipFunction function.- Parameters:
c
-zipFunction
-- Returns:
-
zip
public static FloatStream zip(float[] a, float[] b, float valueForNoneA, float valueForNoneB, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" iterators until all of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-valueForNoneA
- value to fill if "a" runs out of values first.valueForNoneB
- value to fill if "b" runs out of values first.zipFunction
-- Returns:
-
zip
public static FloatStream zip(float[] a, float[] b, float[] c, float valueForNoneA, float valueForNoneB, float valueForNoneC, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" iterators until all of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-c
-valueForNoneA
- value to fill if "a" runs out of values.valueForNoneB
- value to fill if "b" runs out of values.valueForNoneC
- value to fill if "c" runs out of values.zipFunction
-- Returns:
-
zip
public static FloatStream zip(FloatIterator a, FloatIterator b, float valueForNoneA, float valueForNoneB, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" iterators until all of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-valueForNoneA
- value to fill if "a" runs out of values first.valueForNoneB
- value to fill if "b" runs out of values first.zipFunction
-- Returns:
-
zip
public static FloatStream zip(FloatIterator a, FloatIterator b, FloatIterator c, float valueForNoneA, float valueForNoneB, float valueForNoneC, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" iterators until all of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-c
-valueForNoneA
- value to fill if "a" runs out of values.valueForNoneB
- value to fill if "b" runs out of values.valueForNoneC
- value to fill if "c" runs out of values.zipFunction
-- Returns:
-
zip
public static FloatStream zip(FloatStream a, FloatStream b, float valueForNoneA, float valueForNoneB, FloatBinaryOperator zipFunction)
Zip together the "a" and "b" iterators until all of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-valueForNoneA
- value to fill if "a" runs out of values first.valueForNoneB
- value to fill if "b" runs out of values first.zipFunction
-- Returns:
-
zip
public static FloatStream zip(FloatStream a, FloatStream b, FloatStream c, float valueForNoneA, float valueForNoneB, float valueForNoneC, FloatTernaryOperator zipFunction)
Zip together the "a", "b" and "c" iterators until all of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.- Parameters:
a
-b
-c
-valueForNoneA
- value to fill if "a" runs out of values.valueForNoneB
- value to fill if "b" runs out of values.valueForNoneC
- value to fill if "c" runs out of values.zipFunction
-- Returns:
-
zip
public static FloatStream zip(Collection<? extends FloatStream> c, float[] valuesForNone, FloatNFunction<Float> zipFunction)
Zip together the iterators until all of them runs out of values. Each array of values is combined into a single value using the supplied zipFunction function.- Parameters:
c
-valuesForNone
- value to fill for any iterator runs out of values.zipFunction
-- Returns:
-
merge
public static FloatStream merge(float[] a, float[] b, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
a
-b
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
merge
public static FloatStream merge(float[] a, float[] b, float[] c, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
a
-b
-c
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
merge
public static FloatStream merge(FloatIterator a, FloatIterator b, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
a
-b
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
merge
public static FloatStream merge(FloatIterator a, FloatIterator b, FloatIterator c, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
a
-b
-c
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
merge
public static FloatStream merge(FloatStream a, FloatStream b, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
a
-b
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
merge
public static FloatStream merge(FloatStream a, FloatStream b, FloatStream c, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
a
-b
-c
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
merge
public static FloatStream merge(Collection<? extends FloatStream> c, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
c
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
parallelMerge
public static FloatStream parallelMerge(Collection<? extends FloatStream> c, FloatBiFunction<MergeResult> nextSelector)
- Parameters:
c
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.- Returns:
-
parallelMerge
public static FloatStream parallelMerge(Collection<? extends FloatStream> c, FloatBiFunction<MergeResult> nextSelector, int maxThreadNum)
- Parameters:
c
-nextSelector
- first parameter is selected ifNth.FIRST
is returned, otherwise the second parameter is selected.maxThreadNum
-- Returns:
-
carry
public S carry(C action)
Description copied from interface:BaseStream
Same aspeek
- Specified by:
carry
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
- See Also:
BaseStream.peek(Object)
-
sliding
public Stream<S> sliding(int windowSize)
- Specified by:
sliding
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
- See Also:
BaseStream.sliding(int, int)
-
slidingToList
public Stream<PL> slidingToList(int windowSize)
- Specified by:
slidingToList
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
- See Also:
BaseStream.sliding(int, int)
-
shuffled
public S shuffled()
Description copied from interface:BaseStream
This method only run sequentially, even in parallel stream and all elements will be loaded to memory.- Specified by:
shuffled
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
-
toImmutableList
public ImmutableList<T> toImmutableList()
- Specified by:
toImmutableList
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
-
toImmutableSet
public ImmutableSet<T> toImmutableSet()
- Specified by:
toImmutableSet
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
-
join
public String join(CharSequence delimiter)
- Specified by:
join
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,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,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
-
isParallel
public boolean isParallel()
- Specified by:
isParallel
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
-
sequential
public S sequential()
- Specified by:
sequential
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
-
parallel
public S parallel()
- Specified by:
parallel
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
-
parallel
public S parallel(int maxThreadNum)
- Specified by:
parallel
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
-
parallel
public S parallel(BaseStream.Splitor splitor)
- Specified by:
parallel
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Returns:
-
parallel
public S parallel(int maxThreadNum, BaseStream.Splitor splitor)
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 = 1; final Function
mapper = str -> { long result = 0; for (int i = 0; i < m; i++) { result += 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().longValue())).printResult(); Profiler.run(threadNum, loopNum, roundNum, "Abcus Parallel", () -> assertEquals(sum.longValue(), Stream.of(strs).parallel().map(mapper).mapToLong(e -> e).sum().longValue())).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,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Parameters:
maxThreadNum
- Default value is the number of cpu-cores. Steps/operations will be executed sequentially ifmaxThreadNum
is 1.splitor
- The target array is split by ranges for multiple threads if splitor issplitor.ARRAY
and target stream composed by array. It looks like:
Otherwise, each thread will get the elements from the target array/iterator in the stream one by one with the target array/iterator synchronized. It looks like:for (int i = 0; i < maxThreadNum; i++) { final int sliceIndex = i; futureList.add(asyncExecutor.execute(new Runnable() { public void run() { int cursor = fromIndex + sliceIndex * sliceSize; final int to = toIndex - cursor > sliceSize ? cursor + sliceSize : toIndex; while (cursor < to) { action.accept(elements[cursor++]); } } })); }
Usingfor (int i = 0; i < maxThreadNum; i++) { futureList.add(asyncExecutor.execute(new Runnable() { public void run() { T next = null; while (true) { synchronized (elements) { if (cursor.intValue() < toIndex) { next = elements[cursor.getAndIncrement()]; } else { break; } } action.accept(next); } } })); }
splitor.ARRAY
only when F (the per-element function (usually a lambda)) is very tiny and the cost of synchronization on the target array/iterator is too big to it. For the F involving IO or taking 'long' to complete, choosesplitor.ITERATOR
. Default value issplitor.ITERATOR
.- Returns:
- See Also:
MergeResult
,com.landawn.abacus.util.Profiler#run(int, int, int, String, Runnable)
, Understanding Parallel Stream Performance in Java SE 8, When to use parallel Streams
-
parallel
public S parallel(int maxThreadNum, BaseStream.Splitor splitor, Executor executor)
- Specified by:
parallel
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
executor
- should be able to executemaxThreadNum
*following up operations
in parallel.- Returns:
-
parallel
public S parallel(int maxThreadNum, Executor executor)
- Specified by:
parallel
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
executor
- should be able to executemaxThreadNum
*following up operations
in parallel.- Returns:
-
parallel
public S parallel(Executor executor)
- Specified by:
parallel
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
- Parameters:
executor
- should be able to executemaxThreadNum
*following up operations
in parallel.- Returns:
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceBaseStream<T,A,P,C,PL,OT,IT,ITER,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
-
-