Interface RemoteStream<T>
- Type Parameters:
T
- the type of the stream elements
- All Superinterfaces:
AutoCloseable
,BaseRemoteStream<T,
,Stream<T>> BaseStream<T,
,Stream<T>> Stream<T>
java.util.stream.Stream
that captures
lambdas used as method arguments as serializable lambdas.- Since:
- 12.2.1
- Author:
- as 2014.08.11
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.stream.Stream
Stream.Builder<T>
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
allMatch
(Remote.Predicate<? super T> predicate) Returns whether all elements of this stream match the provided predicate.boolean
Returns whether all elements of this stream match the provided predicate.default boolean
anyMatch
(Remote.Predicate<? super T> predicate) Returns whether any elements of this stream match the provided predicate.boolean
Returns whether any elements of this stream match the provided predicate.default <R> R
collect
(Remote.Supplier<R> supplier, Remote.BiConsumer<R, ? super T> accumulator, Remote.BiConsumer<R, R> combiner) Performs a mutable reduction operation on the elements of this stream.<R,
A> R collect
(RemoteCollector<? super T, A, R> collector) Performs a mutable reduction operation on the elements of this stream using aCollector
.<R> R
collect
(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner) Performs a mutable reduction operation on the elements of this stream.default <R,
A> R Performs a mutable reduction operation on the elements of this stream using aCollector
.long
count()
Returns the count of elements in this stream.distinct()
Returns a stream consisting of the distinct elements (according toObject.equals(Object)
) of this stream.Returns, if this stream is ordered, a stream consisting of the remaining elements of this stream after dropping the longest prefix of elements that match the given predicate.static <K,
V> RemoteStream <InvocableMap.Entry<K, V>> entrySet
(InvocableMap<K, V> map) Create aRemoteStream
of specified map's entries.default RemoteStream
<T> filter
(Remote.Predicate<? super T> predicate) Returns a stream consisting of the elements of this stream that match the given predicate.Returns a stream consisting of the elements of this stream that match the given predicate.findAny()
Returns anOptional
describing some element of the stream, or an emptyOptional
if the stream is empty.Returns anOptional
describing the first element of this stream, or an emptyOptional
if the stream is empty.default <R> RemoteStream
<R> flatMap
(Remote.Function<? super T, ? extends Stream<? extends R>> mapper) Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.<R> RemoteStream
<R> Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.default RemoteDoubleStream
flatMapToDouble
(Remote.Function<? super T, ? extends DoubleStream> mapper) Returns anDoubleStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.flatMapToDouble
(Function<? super T, ? extends DoubleStream> mapper) Returns anDoubleStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.default RemoteIntStream
flatMapToInt
(Remote.Function<? super T, ? extends IntStream> mapper) Returns anIntStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.flatMapToInt
(Function<? super T, ? extends IntStream> mapper) Returns anIntStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.default RemoteLongStream
flatMapToLong
(Remote.Function<? super T, ? extends LongStream> mapper) Returns anLongStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.flatMapToLong
(Function<? super T, ? extends LongStream> mapper) Returns anLongStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.void
Performs an action for each element of this stream.void
forEachOrdered
(Consumer<? super T> action) Performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order.static <K,
V> RemoteStream <K> keySet
(InvocableMap<K, V> map) Create aRemoteStream
of specified map's keys.limit
(long maxSize) Returns a stream consisting of the elements of this stream, truncated to be no longer thanmaxSize
in length.default <R> RemoteStream
<R> map
(Remote.Function<? super T, ? extends R> mapper) Returns a stream consisting of the results of applying the given function to the elements of this stream.default <R> RemoteStream
<R> map
(ValueExtractor<? super T, ? extends R> mapper) Returns a stream consisting of the results of applying the given extractor to the elements of this stream.<R> RemoteStream
<R> Returns a stream consisting of the results of applying the given function to the elements of this stream.default <R> RemoteStream
<R> mapMulti
(Remote.BiConsumer<? super T, ? super Consumer<R>> mapper) Returns a stream consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.<R> RemoteStream
<R> mapMulti
(BiConsumer<? super T, ? super Consumer<R>> mapper) Returns a stream consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.default RemoteDoubleStream
mapMultiToDouble
(Remote.BiConsumer<? super T, ? super DoubleConsumer> mapper) Returns aDoubleStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.mapMultiToDouble
(BiConsumer<? super T, ? super DoubleConsumer> mapper) Returns aDoubleStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.default RemoteIntStream
mapMultiToInt
(Remote.BiConsumer<? super T, ? super IntConsumer> mapper) Returns anIntStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.mapMultiToInt
(BiConsumer<? super T, ? super IntConsumer> mapper) Returns anIntStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.default RemoteLongStream
mapMultiToLong
(Remote.BiConsumer<? super T, ? super LongConsumer> mapper) Returns aLongStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.mapMultiToLong
(BiConsumer<? super T, ? super LongConsumer> mapper) Returns aLongStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.default RemoteDoubleStream
mapToDouble
(Remote.ToDoubleFunction<? super T> mapper) Returns aDoubleStream
consisting of the results of applying the given function to the elements of this stream.default RemoteDoubleStream
mapToDouble
(ValueExtractor<? super T, ? extends Number> mapper) Returns anDoubleStream
consisting of the results of applying the given extractor to the elements of this stream.mapToDouble
(ToDoubleFunction<? super T> mapper) Returns aDoubleStream
consisting of the results of applying the given function to the elements of this stream.default RemoteIntStream
mapToInt
(Remote.ToIntFunction<? super T> mapper) Returns anIntStream
consisting of the results of applying the given function to the elements of this stream.default RemoteIntStream
mapToInt
(ValueExtractor<? super T, ? extends Number> mapper) Returns anIntStream
consisting of the results of applying the given extractor to the elements of this stream.mapToInt
(ToIntFunction<? super T> mapper) Returns anIntStream
consisting of the results of applying the given function to the elements of this stream.default RemoteLongStream
mapToLong
(Remote.ToLongFunction<? super T> mapper) Returns aLongStream
consisting of the results of applying the given function to the elements of this stream.default RemoteLongStream
mapToLong
(ValueExtractor<? super T, ? extends Number> mapper) Returns anLongStream
consisting of the results of applying the given extractor to the elements of this stream.mapToLong
(ToLongFunction<? super T> mapper) Returns aLongStream
consisting of the results of applying the given function to the elements of this stream.max
(Remote.Comparator<? super T> comparator) Returns the maximum element of this stream according to the providedComparator
.max
(ValueExtractor<? super U, ? extends Comparable> extractor) Returns the maximum element of this stream according to the attribute extracted by the providedValueExtractor
.max
(Comparator<? super T> comparator) Returns the maximum element of this stream according to the providedComparator
.min
(Remote.Comparator<? super T> comparator) Returns the minimum element of this stream according to the providedComparator
.min
(ValueExtractor<? super U, ? extends Comparable> extractor) Returns the minimum element of this stream according to the attribute extracted by the providedValueExtractor
.min
(Comparator<? super T> comparator) Returns the minimum element of this stream according to the providedComparator
.default boolean
noneMatch
(Remote.Predicate<? super T> predicate) Returns whether no elements of this stream match the provided predicate.boolean
Returns whether no elements of this stream match the provided predicate.parallel()
Returns an equivalent stream that is parallel.default RemoteStream
<T> peek
(Remote.Consumer<? super T> action) Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.reduce
(Remote.BinaryOperator<T> accumulator) Performs a reduction on the elements of this stream, using an associative accumulation function, and returns anOptional
describing the reduced value, if any.reduce
(BinaryOperator<T> accumulator) Performs a reduction on the elements of this stream, using an associative accumulation function, and returns anOptional
describing the reduced value, if any.default T
reduce
(T identity, Remote.BinaryOperator<T> accumulator) Performs a reduction on the elements of this stream, using the provided identity value and an associative accumulation function, and returns the reduced value.reduce
(T identity, BinaryOperator<T> accumulator) Performs a reduction on the elements of this stream, using the provided identity value and an associative accumulation function, and returns the reduced value.default <U> U
reduce
(U identity, Remote.BiFunction<U, ? super T, U> accumulator, Remote.BinaryOperator<U> combiner) Performs a reduction on the elements of this stream, using the provided identity, accumulation and combining functions.<U> U
reduce
(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner) Performs a reduction on the elements of this stream, using the provided identity, accumulation and combining functions.Returns an equivalent stream that is sequential.skip
(long n) Returns a stream consisting of the remaining elements of this stream after discarding the firstn
elements of the stream.sorted()
Returns a stream consisting of the elements of this stream, sorted according to natural order.default RemoteStream
<T> sorted
(Remote.Comparator<? super T> comparator) Returns a stream consisting of the elements of this stream, sorted according to the providedComparator
.default RemoteStream
<T> sorted
(Remote.Comparator<? super T> comparator, boolean fInverse) Returns a stream consisting of the elements of this stream, sorted according to the providedComparator
.default <U> RemoteStream
<T> sorted
(ValueExtractor<? super U, ? extends Comparable> extractor) Returns a stream consisting of the elements of this stream, sorted according to attribute extracted by the providedValueExtractor
.default <U> RemoteStream
<T> sorted
(ValueExtractor<? super U, ? extends Comparable> extractor, boolean fInverse) Returns a stream consisting of the elements of this stream, sorted according to attribute extracted by the providedValueExtractor
.sorted
(Comparator<? super T> comparator) Returns a stream consisting of the elements of this stream, sorted according to the providedComparator
.Returns, if this stream is ordered, a stream consisting of the longest prefix of elements taken from this stream that match the given predicate.Object[]
toArray()
Returns an array containing the elements of this stream.<A> A[]
toArray
(IntFunction<A[]> generator) Returns an array containing the elements of this stream, using the providedgenerator
function to allocate the returned array, as well as any additional arrays that might be required for a partitioned execution or for resizing.static <T extends Number>
RemoteDoubleStreamtoDoubleStream
(RemoteStream<T> stream) Convert stream of numbers intoRemoteDoubleStream
.static <T extends Number>
RemoteIntStreamtoIntStream
(RemoteStream<T> stream) Convert stream of numbers intoRemoteIntStream
.toList()
Accumulates the elements of this stream into aList
.static <T extends Number>
RemoteLongStreamtoLongStream
(RemoteStream<T> stream) Convert stream of numbers intoRemoteLongStream
.Returns an equivalent stream that is unordered.static <K,
V> RemoteStream <V> values
(InvocableMap<K, V> map) Create aRemoteStream
of specified map's values.Methods inherited from interface com.tangosol.util.stream.BaseRemoteStream
pipeline
Methods inherited from interface java.util.stream.BaseStream
close, isParallel, iterator, onClose, spliterator
-
Method Details
-
entrySet
Create aRemoteStream
of specified map's entries.- Type Parameters:
K
- the type of map keysV
- the type of map values- Parameters:
map
- the map to create a remote stream for- Returns:
- a
RemoteStream
of specified map's entries
-
keySet
Create aRemoteStream
of specified map's keys.- Type Parameters:
K
- the type of map keysV
- the type of map values- Parameters:
map
- the map to create a remote stream for- Returns:
- a
RemoteStream
of specified map's keys
-
values
Create aRemoteStream
of specified map's values.- Type Parameters:
K
- the type of map keysV
- the type of map values- Parameters:
map
- the map to create a remote stream for- Returns:
- a
RemoteStream
of specified map's values
-
sequential
RemoteStream<T> sequential()Returns an equivalent stream that is sequential. May return itself, either because the stream was already sequential, or because the underlying stream state was modified to be sequential.This is an intermediate operation.
- Specified by:
sequential
in interfaceBaseStream<T,
Stream<T>> - Returns:
- a sequential stream
-
parallel
RemoteStream<T> parallel()Returns an equivalent stream that is parallel. May return itself, either because the stream was already parallel, or because the underlying stream state was modified to be parallel.This is an intermediate operation.
- Specified by:
parallel
in interfaceBaseStream<T,
Stream<T>> - Returns:
- a parallel stream
-
unordered
RemoteStream<T> unordered()Returns an equivalent stream that is unordered. May return itself, either because the stream was already unordered, or because the underlying stream state670G was modified to be unordered.This is an intermediate operation.
- Specified by:
unordered
in interfaceBaseStream<T,
Stream<T>> - Returns:
- an unordered stream
-
filter
Returns a stream consisting of the elements of this stream that match the given predicate.This is an intermediate operation.
-
filter
Returns a stream consisting of the elements of this stream that match the given predicate.This is an intermediate operation.
- Parameters:
predicate
- a non-interfering, stateless predicate to apply to each element to determine if it should be included- Returns:
- the new stream
-
map
Returns a stream consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
-
map
Returns a stream consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
- Type Parameters:
R
- the type of resulting stream elements- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
map
Returns a stream consisting of the results of applying the given extractor to the elements of this stream.This is an intermediate operation.
- Type Parameters:
R
- the type of resulting stream elements- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToInt
Returns anIntStream
consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
-
mapToInt
Returns anIntStream
consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToInt
Returns anIntStream
consisting of the results of applying the given extractor to the elements of this stream.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToLong
Returns aLongStream
consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
-
mapToLong
Returns aLongStream
consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToLong
Returns anLongStream
consisting of the results of applying the given extractor to the elements of this stream.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToDouble
Returns aDoubleStream
consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
- Specified by:
mapToDouble
in interfaceStream<T>
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToDouble
Returns aDoubleStream
consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToDouble
Returns anDoubleStream
consisting of the results of applying the given extractor to the elements of this stream.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
flatMap
Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
-
flatMap
default <R> RemoteStream<R> flatMap(Remote.Function<? super T, ? extends Stream<? extends R>> mapper) Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
- Type Parameters:
R
- The element type of the new stream- Parameters:
mapper
- a non-interfering, stateless function to apply to each element which produces a stream of new values- Returns:
- the new stream
-
flatMapToInt
Returns anIntStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
- Specified by:
flatMapToInt
in interfaceStream<T>
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element which produces a stream of new values- Returns:
- the new stream
- See Also:
-
flatMapToInt
Returns anIntStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element which produces a stream of new values- Returns:
- the new stream
- See Also:
-
flatMapToLong
Returns anLongStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
- Specified by:
flatMapToLong
in interfaceStream<T>
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element which produces a stream of new values- Returns:
- the new stream
- See Also:
-
flatMapToLong
Returns anLongStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element which produces a stream of new values- Returns:
- the new stream
- See Also:
-
flatMapToDouble
Returns anDoubleStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
- Specified by:
flatMapToDouble
in interfaceStream<T>
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element which produces a stream of new values- Returns:
- the new stream
- See Also:
-
flatMapToDouble
default RemoteDoubleStream flatMapToDouble(Remote.Function<? super T, ? extends DoubleStream> mapper) Returns anDoubleStream
consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream isclosed
after its contents have been placed into this stream. (If a mapped stream isnull
an empty stream is used, instead.)This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element which produces a stream of new values- Returns:
- the new stream
- See Also:
-
mapMulti
Returns a stream consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. Replacement is performed by applying the provided mapping function to each element in conjunction with a consumer argument that accepts replacement elements. The mapping function calls the consumer zero or more times to provide the replacement elements.This is an intermediate operation.
If the consumer argument is used outside the scope of its application to the mapping function, the results are undefined.
-
mapMulti
Returns a stream consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. Replacement is performed by applying the provided mapping function to each element in conjunction with a consumer argument that accepts replacement elements. The mapping function calls the consumer zero or more times to provide the replacement elements.This is an intermediate operation.
If the consumer argument is used outside the scope of its application to the mapping function, the results are undefined.
- Parameters:
mapper
- a non-interfering, stateless function that generates replacement elements- Returns:
- the new stream
- Since:
- 22.09
-
mapMultiToInt
Returns anIntStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. Replacement is performed by applying the provided mapping function to each element in conjunction with a consumer argument that accepts replacement elements. The mapping function calls the consumer zero or more times to provide the replacement elements.This is an intermediate operation.
If the consumer argument is used outside the scope of its application to the mapping function, the results are undefined.
- Specified by:
mapMultiToInt
in interfaceStream<T>
- Parameters:
mapper
- a non-interfering, stateless function that generates replacement elements- Returns:
- the new stream
- Since:
- 22.09
-
mapMultiToInt
Returns anIntStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. Replacement is performed by applying the provided mapping function to each element in conjunction with a consumer argument that accepts replacement elements. The mapping function calls the consumer zero or more times to provide the replacement elements.This is an intermediate operation.
If the consumer argument is used outside the scope of its application to the mapping function, the results are undefined.
- Parameters:
mapper
- a non-interfering, stateless function that generates replacement elements- Returns:
- the new stream
- Since:
- 22.09
-
mapMultiToLong
Returns aLongStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. Replacement is performed by applying the provided mapping function to each element in conjunction with a consumer argument that accepts replacement elements. The mapping function calls the consumer zero or more times to provide the replacement elements.This is an intermediate operation.
If the consumer argument is used outside the scope of its application to the mapping function, the results are undefined.
- Specified by:
mapMultiToLong
in interfaceStream<T>
- Parameters:
mapper
- a non-interfering, stateless function that generates replacement elements- Returns:
- the new stream
- Since:
- 22.09
-
mapMultiToLong
Returns aLongStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. Replacement is performed by applying the provided mapping function to each element in conjunction with a consumer argument that accepts replacement elements. The mapping function calls the consumer zero or more times to provide the replacement elements.This is an intermediate operation.
If the consumer argument is used outside the scope of its application to the mapping function, the results are undefined.
- Parameters:
mapper
- a non-interfering, stateless function that generates replacement elements- Returns:
- the new stream
- Since:
- 22.09
-
mapMultiToDouble
Returns aDoubleStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. Replacement is performed by applying the provided mapping function to each element in conjunction with a consumer argument that accepts replacement elements. The mapping function calls the consumer zero or more times to provide the replacement elements.This is an intermediate operation.
If the consumer argument is used outside the scope of its application to the mapping function, the results are undefined.
- Specified by:
mapMultiToDouble
in interfaceStream<T>
- Parameters:
mapper
- a non-interfering, stateless function that generates replacement elements- Returns:
- the new stream
- Since:
- 22.09
-
mapMultiToDouble
default RemoteDoubleStream mapMultiToDouble(Remote.BiConsumer<? super T, ? super DoubleConsumer> mapper) Returns aDoubleStream
consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. Replacement is performed by applying the provided mapping function to each element in conjunction with a consumer argument that accepts replacement elements. The mapping function calls the consumer zero or more times to provide the replacement elements.This is an intermediate operation.
If the consumer argument is used outside the scope of its application to the mapping function, the results are undefined.
- Parameters:
mapper
- a non-interfering, stateless function that generates replacement elements- Returns:
- the new stream
- Since:
- 22.09
-
peek
Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.This is an intermediate operation.
For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.
-
peek
Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.This is an intermediate operation.
For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.
- Parameters:
action
- a non-interfering action to perform on the elements as they are consumed from the stream- Returns:
- the new stream
-
limit
Returns a stream consisting of the elements of this stream, truncated to be no longer thanmaxSize
in length.This is a short-circuiting stateful intermediate operation.
- Specified by:
limit
in interfaceStream<T>
- Parameters:
maxSize
- the number of elements the stream should be limited to- Returns:
- the new stream
- Throws:
IllegalArgumentException
- ifmaxSize
is negative
-
skip
Returns a stream consisting of the remaining elements of this stream after discarding the firstn
elements of the stream. If this stream contains fewer thann
elements then an empty stream will be returned.This is a stateful intermediate operation.
- Specified by:
skip
in interfaceStream<T>
- Parameters:
n
- the number of leading elements to skip- Returns:
- the new stream
- Throws:
IllegalArgumentException
- ifn
is negative
-
takeWhile
Returns, if this stream is ordered, a stream consisting of the longest prefix of elements taken from this stream that match the given predicate. Otherwise returns, if this stream is unordered, a stream consisting of a subset of elements taken from this stream that match the given predicate.If this stream is ordered then the longest prefix is a contiguous sequence of elements of this stream that match the given predicate. The first element of the sequence is the first element of this stream, and the element immediately following the last element of the sequence does not match the given predicate.
If this stream is unordered, and some (but not all) elements of this stream match the given predicate, then the behavior of this operation is nondeterministic; it is free to take any subset of matching elements (which includes the empty set).
Independent of whether this stream is ordered or unordered if all elements of this stream match the given predicate then this operation takes all elements (the result is the same as the input), or if no elements of the stream match the given predicate then no elements are taken (the result is an empty stream).
This is a short-circuiting stateful intermediate operation.
- Specified by:
takeWhile
in interfaceStream<T>
- Parameters:
predicate
- a non-interfering, stateless predicate to apply to elements to determine the longest prefix of elements.- Returns:
- the new stream
- Since:
- 9
- API Note:
- While
takeWhile()
is generally a cheap operation on sequential stream pipelines, it can be quite expensive on ordered parallel pipelines, since the operation is constrained to return not just any valid prefix, but the longest prefix of elements in the encounter order. Using an unordered stream source (such asStream.generate(Supplier)
) or removing the ordering constraint withunordered()
may result in significant speedups oftakeWhile()
in parallel pipelines, if the semantics of your situation permit. If consistency with encounter order is required, and you are experiencing poor performance or memory utilization withtakeWhile()
in parallel pipelines, switching to sequential execution withsequential()
may improve performance. - Implementation Requirements:
- The default implementation obtains the
spliterator
of this stream, wraps that spliterator so as to support the semantics of this operation on traversal, and returns a new stream associated with the wrapped spliterator. The returned stream preserves the execution characteristics of this stream (namely parallel or sequential execution as perBaseStream.isParallel()
) but the wrapped spliterator may choose to not support splitting. When the returned stream is closed, the close handlers for both the returned and this stream are invoked.
-
dropWhile
Returns, if this stream is ordered, a stream consisting of the remaining elements of this stream after dropping the longest prefix of elements that match the given predicate. Otherwise returns, if this stream is unordered, a stream consisting of the remaining elements of this stream after dropping a subset of elements that match the given predicate.If this stream is ordered then the longest prefix is a contiguous sequence of elements of this stream that match the given predicate. The first element of the sequence is the first element of this stream, and the element immediately following the last element of the sequence does not match the given predicate.
If this stream is unordered, and some (but not all) elements of this stream match the given predicate, then the behavior of this operation is nondeterministic; it is free to drop any subset of matching elements (which includes the empty set).
Independent of whether this stream is ordered or unordered if all elements of this stream match the given predicate then this operation drops all elements (the result is an empty stream), or if no elements of the stream match the given predicate then no elements are dropped (the result is the same as the input).
This is a stateful intermediate operation.
- Specified by:
dropWhile
in interfaceStream<T>
- Parameters:
predicate
- a non-interfering, stateless predicate to apply to elements to determine the longest prefix of elements.- Returns:
- the new stream
- Since:
- 9
- API Note:
- While
dropWhile()
is generally a cheap operation on sequential stream pipelines, it can be quite expensive on ordered parallel pipelines, since the operation is constrained to return not just any valid prefix, but the longest prefix of elements in the encounter order. Using an unordered stream source (such asStream.generate(Supplier)
) or removing the ordering constraint withunordered()
may result in significant speedups ofdropWhile()
in parallel pipelines, if the semantics of your situation permit. If consistency with encounter order is required, and you are experiencing poor performance or memory utilization withdropWhile()
in parallel pipelines, switching to sequential execution withsequential()
may improve performance. - Implementation Requirements:
- The default implementation obtains the
spliterator
of this stream, wraps that spliterator so as to support the semantics of this operation on traversal, and returns a new stream associated with the wrapped spliterator. The returned stream preserves the execution characteristics of this stream (namely parallel or sequential execution as perBaseStream.isParallel()
) but the wrapped spliterator may choose to not support splitting. When the returned stream is closed, the close handlers for both the returned and this stream are invoked.
-
distinct
Returns a stream consisting of the distinct elements (according toObject.equals(Object)
) of this stream.For ordered streams, the selection of distinct elements is stable (for duplicated elements, the element appearing first in the encounter order is preserved.) For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
-
sorted
RemoteStream<T> sorted()Returns a stream consisting of the elements of this stream, sorted according to natural order. If the elements of this stream are notComparable
, ajava.lang.ClassCastException
may be thrown when the terminal operation is executed.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
-
sorted
Returns a stream consisting of the elements of this stream, sorted according to the providedComparator
.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
-
sorted
Returns a stream consisting of the elements of this stream, sorted according to the providedComparator
.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Parameters:
comparator
- a non-interfering, statelessComparator
to be used to compare stream elements- Returns:
- the new stream
-
sorted
Returns a stream consisting of the elements of this stream, sorted according to the providedComparator
.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Parameters:
comparator
- a non-interfering, statelessComparator
to be used to compare stream elementsfInverse
- a flag specifying whether to invert the sort order- Returns:
- the new stream
-
sorted
Returns a stream consisting of the elements of this stream, sorted according to attribute extracted by the providedValueExtractor
.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Type Parameters:
U
- a super type of the value to extract from- Parameters:
extractor
- a non-interfering, statelessValueExtractor
to be used to extract the attribute that should be used to compare stream elements- Returns:
- the new stream
-
sorted
default <U> RemoteStream<T> sorted(ValueExtractor<? super U, ? extends Comparable> extractor, boolean fInverse) Returns a stream consisting of the elements of this stream, sorted according to attribute extracted by the providedValueExtractor
.For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
- Type Parameters:
U
- the super type of value to extract from- Parameters:
extractor
- a non-interfering, statelessValueExtractor
to be used to extract the attribute that should be used to compare stream elementsfInverse
- a flag specifying whether to invert natural sort order- Returns:
- the new stream
-
forEach
Performs an action for each element of this stream.This is a terminal operation.
-
forEachOrdered
Performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order.This is a terminal operation.
This operation processes the elements one at a time, in encounter order if one exists. Performing the action for one element happens-before performing the action for subsequent elements, but for any given element, the action may be performed in whatever thread the library chooses.
- Specified by:
forEachOrdered
in interfaceStream<T>
- Parameters:
action
- a non-interfering action to perform on the elements- See Also:
-
toArray
Object[] toArray()Returns an array containing the elements of this stream.This is a terminal operation.
-
toArray
Returns an array containing the elements of this stream, using the providedgenerator
function to allocate the returned array, as well as any additional arrays that might be required for a partitioned execution or for resizing.This is a terminal operation.
- Specified by:
toArray
in interfaceStream<T>
- Parameters:
generator
- a function which produces a new array of the desired type and the provided length- Returns:
- an array containing the elements in this stream
- Throws:
ArrayStoreException
- if the runtime type of the array returned from the array generator is not a supertype of the runtime type of every element in this stream
-
reduce
Performs a reduction on the elements of this stream, using the provided identity value and an associative accumulation function, and returns the reduced value. This is equivalent to:T result = identity; for (T element : this stream) result = accumulator.apply(result, element) return result;
but is not constrained to execute sequentially.
The
identity
value must be an identity for the accumulator function. This means that for allt
,accumulator.apply(identity, t)
is equal tot
. Theaccumulator
function must be an associative function.This is a terminal operation.
-
reduce
Performs a reduction on the elements of this stream, using the provided identity value and an associative accumulation function, and returns the reduced value. This is equivalent to:T result = identity; for (T element : this stream) result = accumulator.apply(result, element) return result;
but is not constrained to execute sequentially.
The
identity
value must be an identity for the accumulator function. This means that for allt
,accumulator.apply(identity, t)
is equal tot
. Theaccumulator
function must be an associative function.This is a terminal operation.
- Parameters:
identity
- the identity value for the accumulating functionaccumulator
- an associative, non-interfering, stateless function for combining two values- Returns:
- the result of the reduction
-
reduce
Performs a reduction on the elements of this stream, using an associative accumulation function, and returns anOptional
describing the reduced value, if any. This is equivalent to:boolean foundAny = false; T result = null; for (T element : this stream) { if (!foundAny) { foundAny = true; result = element; } else result = accumulator.apply(result, element); } return foundAny ? Optional.of(result) : Optional.empty();
but is not constrained to execute sequentially.
The
accumulator
function must be an associative function.This is a terminal operation.
- Specified by:
reduce
in interfaceStream<T>
- Parameters:
accumulator
- an associative, non-interfering, stateless function for combining two values- Returns:
- an
Optional
describing the result of the reduction - Throws:
NullPointerException
- if the result of the reduction is null- See Also:
-
reduce
Performs a reduction on the elements of this stream, using an associative accumulation function, and returns anOptional
describing the reduced value, if any. This is equivalent to:boolean foundAny = false; T result = null; for (T element : this stream) { if (!foundAny) { foundAny = true; result = element; } else result = accumulator.apply(result, element); } return foundAny ? Optional.of(result) : Optional.empty();
but is not constrained to execute sequentially.
The
accumulator
function must be an associative function.This is a terminal operation.
- Parameters:
accumulator
- an associative, non-interfering, stateless function for combining two values- Returns:
- an
Optional
describing the result of the reduction - Throws:
NullPointerException
- if the result of the reduction is null- See Also:
-
reduce
Performs a reduction on the elements of this stream, using the provided identity, accumulation and combining functions. This is equivalent to:U result = identity; for (T element : this stream) result = accumulator.apply(result, element) return result;
but is not constrained to execute sequentially.
The
identity
value must be an identity for the combiner function. This means that for allu
,combiner(identity, u)
is equal tou
. Additionally, thecombiner
function must be compatible with theaccumulator
function; for allu
andt
, the following must hold:combiner.apply(u, accumulator.apply(identity, t)) == accumulator.apply(u, t)
This is a terminal operation.
- Specified by:
reduce
in interfaceStream<T>
- Parameters:
identity
- the identity value for the combiner functionaccumulator
- an associative, non-interfering, stateless function for incorporating an additional element into a resultcombiner
- an associative, non-interfering, stateless function for combining two values, which must be compatible with the accumulator function- Returns:
- the result of the reduction
- See Also:
-
reduce
default <U> U reduce(U identity, Remote.BiFunction<U, ? super T, U> accumulator, Remote.BinaryOperator<U> combiner) Performs a reduction on the elements of this stream, using the provided identity, accumulation and combining functions. This is equivalent to:U result = identity; for (T element : this stream) result = accumulator.apply(result, element) return result;
but is not constrained to execute sequentially.
The
identity
value must be an identity for the combiner function. This means that for allu
,combiner(identity, u)
is equal tou
. Additionally, thecombiner
function must be compatible with theaccumulator
function; for allu
andt
, the following must hold:combiner.apply(u, accumulator.apply(identity, t)) == accumulator.apply(u, t)
This is a terminal operation.
- Type Parameters:
U
- the type of stream elements- Parameters:
identity
- the identity value for the combiner functionaccumulator
- an associative, non-interfering, stateless function for incorporating an additional element into a resultcombiner
- an associative, non-interfering, stateless function for combining two values, which must be compatible with the accumulator function- Returns:
- the result of the reduction
- See Also:
-
collect
Performs a mutable reduction operation on the elements of this stream. A mutable reduction is one in which the reduced value is a mutable result container, such as anArrayList
, and elements are incorporated by updating the state of the result rather than by replacing the result. This produces a result equivalent to:R result = supplier.get(); for (T element : this stream) accumulator.accept(result, element); return result;
Like
reduce(Object, Remote.BinaryOperator)
,collect
operations can be parallelized without requiring additional synchronization.This is a terminal operation.
- Specified by:
collect
in interfaceStream<T>
- Parameters:
supplier
- a function that creates a new result container. For a parallel execution, this function may be called multiple times and must return a fresh value each time.accumulator
- an associative, non-interfering, stateless function for incorporating an additional element into a resultcombiner
- an associative, non-interfering, stateless function for combining two values, which must be compatible with the accumulator function- Returns:
- the result of the reduction
-
collect
default <R> R collect(Remote.Supplier<R> supplier, Remote.BiConsumer<R, ? super T> accumulator, Remote.BiConsumer<R, R> combiner) Performs a mutable reduction operation on the elements of this stream. A mutable reduction is one in which the reduced value is a mutable result container, such as anArrayList
, and elements are incorporated by updating the state of the result rather than by replacing the result. This produces a result equivalent to:R result = supplier.get(); for (T element : this stream) accumulator.accept(result, element); return result;
Like
reduce(Object, Remote.BinaryOperator)
,collect
operations can be parallelized without requiring additional synchronization.This is a terminal operation.
- Type Parameters:
R
- the result type- Parameters:
supplier
- a function that creates a new result container. For a parallel execution, this function may be called multiple times and must return a fresh value each time.accumulator
- an associative, non-interfering, stateless function for incorporating an additional element into a resultcombiner
- an associative, non-interfering, stateless function for combining two values, which must be compatible with the accumulator function- Returns:
- the result of the reduction
-
collect
Performs a mutable reduction operation on the elements of this stream using aCollector
. ACollector
encapsulates the functions used as arguments tocollect(Remote.Supplier, Remote.BiConsumer, Remote.BiConsumer)
, allowing for reuse of collection strategies and composition of collect operations such as multiple-level grouping or partitioning.If the stream is parallel, and the
Collector
isconcurrent
, and either the stream is unordered or the collector isunordered
, then a concurrent reduction will be performed (seeRemoteCollector
for details on concurrent reduction.)This is a terminal operation.
-
collect
Performs a mutable reduction operation on the elements of this stream using aCollector
. ACollector
encapsulates the functions used as arguments tocollect(Remote.Supplier, Remote.BiConsumer, Remote.BiConsumer)
, allowing for reuse of collection strategies and composition of collect operations such as multiple-level grouping or partitioning.If the stream is parallel, and the
Collector
isconcurrent
, and either the stream is unordered or the collector isunordered
, then a concurrent reduction will be performed (seeRemoteCollector
for details on concurrent reduction.)This is a terminal operation.
- Type Parameters:
R
- the type of the resultA
- the intermediate accumulation type of the Collector- Parameters:
collector
- theCollector
describing the reduction- Returns:
- the result of the reduction
- See Also:
-
toList
Accumulates the elements of this stream into aList
. The elements in the list will be in this stream's encounter order, if one exists. The returned List is unmodifiable; calls to any mutator method will always causeUnsupportedOperationException
to be thrown. There are no guarantees on the implementation type or serializability of the returned List.The returned instance may be value-based. Callers should make no assumptions about the identity of the returned instances. Identity-sensitive operations on these instances (reference equality (
==
), identity hash code, and synchronization) are unreliable and should be avoided.This is a terminal operation.
-
min
Returns the minimum element of this stream according to the providedComparator
. This is a special case of a reduction.This is a terminal operation.
-
min
Returns the minimum element of this stream according to the providedComparator
. This is a special case of a reduction.This is a terminal operation.
- Parameters:
comparator
- a non-interfering, statelessComparator
to compare elements of this stream- Returns:
- an
Optional
describing the minimum element of this stream, or an emptyOptional
if the stream is empty
-
min
Returns the minimum element of this stream according to the attribute extracted by the providedValueExtractor
. This is a special case of a reduction.This is a terminal operation.
- Type Parameters:
U
- a super type of the value to extract from- Parameters:
extractor
- a non-interfering, statelessValueExtractor
to be used to extract the attribute that should be used to compare stream elements- Returns:
- an
Optional
describing the minimum element of this stream, or an emptyOptional
if the stream is empty
-
max
Returns the maximum element of this stream according to the providedComparator
. This is a special case of a reduction.This is a terminal operation.
-
max
Returns the maximum element of this stream according to the providedComparator
. This is a special case of a reduction.This is a terminal operation.
- Parameters:
comparator
- a non-interfering, statelessComparator
to compare elements of this stream- Returns:
- an
Optional
describing the maximum element of this stream, or an emptyOptional
if the stream is empty
-
max
Returns the maximum element of this stream according to the attribute extracted by the providedValueExtractor
. This is a special case of a reduction.This is a terminal operation.
- Type Parameters:
U
- a super type of the value to extract from- Parameters:
extractor
- a non-interfering, statelessValueExtractor
to be used to extract the attribute that should be used to compare stream elements- Returns:
- an
Optional
describing the maximum element of this stream, or an emptyOptional
if the stream is empty
-
count
long count()Returns the count of elements in this stream. This is a special case of a reduction and is equivalent to:return mapToLong(e -> 1L).sum();
This is a terminal operation.
-
anyMatch
Returns whether any elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result.This is a short-circuiting terminal operation.
-
anyMatch
Returns whether any elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result.This is a short-circuiting terminal operation.
- Parameters:
predicate
- a non-interfering, stateless predicate to apply to elements of this stream- Returns:
true
if any elements of the stream match the provided predicate, otherwisefalse
-
allMatch
Returns whether all elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result.This is a short-circuiting terminal operation.
-
allMatch
Returns whether all elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result.This is a short-circuiting terminal operation.
- Parameters:
predicate
- a non-interfering, stateless predicate to apply to elements of this stream- Returns:
true
if either all elements of the stream match the provided predicate or the stream is empty, otherwisefalse
-
noneMatch
Returns whether no elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result.This is a short-circuiting terminal operation.
-
noneMatch
Returns whether no elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result.This is a short-circuiting terminal operation.
- Parameters:
predicate
- a non-interfering, stateless predicate to apply to elements of this stream- Returns:
true
if either no elements of the stream match the provided predicate or the stream is empty, otherwisefalse
-
findFirst
Returns anOptional
describing the first element of this stream, or an emptyOptional
if the stream is empty. If the stream has no encounter order, then any element may be returned.This is a short-circuiting terminal operation.
- Specified by:
findFirst
in interfaceStream<T>
- Returns:
- an
Optional
describing the first element of this stream, or an emptyOptional
if the stream is empty - Throws:
NullPointerException
- if the element selected is null
-
findAny
Returns anOptional
describing some element of the stream, or an emptyOptional
if the stream is empty.This is a short-circuiting terminal operation.
The behavior of this operation is explicitly nondeterministic; it is free to select any element in the stream. This is to allow for maximal performance in parallel operations; the cost is that multiple invocations on the same source may not return the same result. (If a stable result is desired, use
findFirst()
instead.)- Specified by:
findAny
in interfaceStream<T>
- Returns:
- an
Optional
describing some element of this stream, or an emptyOptional
if the stream is empty - Throws:
NullPointerException
- if the element selected is null- See Also:
-
toIntStream
Convert stream of numbers intoRemoteIntStream
.- Type Parameters:
T
- the type of input stream elements- Parameters:
stream
- the stream of numbers- Returns:
- a
RemoteIntStream
instance
-
toLongStream
Convert stream of numbers intoRemoteLongStream
.- Type Parameters:
T
- the type of input stream elements- Parameters:
stream
- the stream of numbers- Returns:
- a
RemoteLongStream
instance
-
toDoubleStream
Convert stream of numbers intoRemoteDoubleStream
.- Type Parameters:
T
- the type of input stream elements- Parameters:
stream
- the stream of numbers- Returns:
- a
RemoteDoubleStream
instance
-