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>
public interface RemoteStream<T> extends Stream<T>, BaseRemoteStream<T,Stream<T>>
This interface is an extension ofjava.util.stream.Stream
that captures lambdas used as method arguments as serializable lambdas.- Since:
- 12.2.1
- Author:
- as 2014.08.11
- See Also:
RemoteIntStream
,RemoteLongStream
,RemoteDoubleStream
, com.tangosol.util.stream
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.util.stream.Stream
Stream.Builder<T extends Object>
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default boolean
allMatch(Remote.Predicate<? super T> predicate)
Returns whether all elements of this stream match the provided predicate.boolean
allMatch(Predicate<? super T> predicate)
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
anyMatch(Predicate<? super T> predicate)
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>
Rcollect(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>
Rcollect(Collector<? super T,A,R> collector)
Performs a mutable reduction operation on the elements of this stream using aCollector
.long
count()
Returns the count of elements in this stream.Stream<T>
distinct()
Returns a stream consisting of the distinct elements (according toObject.equals(Object)
) of this stream.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.RemoteStream<T>
filter(Predicate<? super T> predicate)
Returns a stream consisting of the elements of this stream that match the given predicate.Optional<T>
findAny()
Returns anOptional
describing some element of the stream, or an emptyOptional
if the stream is empty.Optional<T>
findFirst()
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>
flatMap(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.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.RemoteDoubleStream
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.RemoteIntStream
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.RemoteLongStream
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
forEach(Consumer<? super T> action)
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.Stream<T>
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>
map(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 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.RemoteDoubleStream
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.RemoteIntStream
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.RemoteLongStream
mapToLong(ToLongFunction<? super T> mapper)
Returns aLongStream
consisting of the results of applying the given function to the elements of this stream.default Optional<T>
max(Remote.Comparator<? super T> comparator)
Returns the maximum element of this stream according to the providedComparator
.default <U> Optional<T>
max(ValueExtractor<? super U,? extends Comparable> extractor)
Returns the maximum element of this stream according to the attribute extracted by the providedValueExtractor
.Optional<T>
max(Comparator<? super T> comparator)
Returns the maximum element of this stream according to the providedComparator
.default Optional<T>
min(Remote.Comparator<? super T> comparator)
Returns the minimum element of this stream according to the providedComparator
.default <U> Optional<T>
min(ValueExtractor<? super U,? extends Comparable> extractor)
Returns the minimum element of this stream according to the attribute extracted by the providedValueExtractor
.Optional<T>
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
noneMatch(Predicate<? super T> predicate)
Returns whether no elements of this stream match the provided predicate.RemoteStream<T>
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.RemoteStream<T>
peek(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.default Optional<T>
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.Optional<T>
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.T
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.RemoteStream<T>
sequential()
Returns an equivalent stream that is sequential.Stream<T>
skip(long n)
Returns a stream consisting of the remaining elements of this stream after discarding the firstn
elements of the stream.RemoteStream<T>
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
.RemoteStream<T>
sorted(Comparator<? super T> comparator)
Returns a stream consisting of the elements of this stream, sorted according to the providedComparator
.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
.static <T extends Number>
RemoteLongStreamtoLongStream(RemoteStream<T> stream)
Convert stream of numbers intoRemoteLongStream
.RemoteStream<T>
unordered()
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 Detail
-
entrySet
static <K,V> RemoteStream<InvocableMap.Entry<K,V>> entrySet(InvocableMap<K,V> map)
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
static <K,V> RemoteStream<K> keySet(InvocableMap<K,V> map)
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
static <K,V> RemoteStream<V> values(InvocableMap<K,V> map)
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
RemoteStream<T> filter(Predicate<? super T> predicate)
Returns a stream consisting of the elements of this stream that match the given predicate.This is an intermediate operation.
-
filter
default RemoteStream<T> filter(Remote.Predicate<? super T> predicate)
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
<R> RemoteStream<R> map(Function<? super T,? extends R> mapper)
Returns a stream consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
-
map
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.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
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.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
RemoteIntStream mapToInt(ToIntFunction<? super T> mapper)
Returns anIntStream
consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
-
mapToInt
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.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToInt
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.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToLong
RemoteLongStream mapToLong(ToLongFunction<? super T> mapper)
Returns aLongStream
consisting of the results of applying the given function to the elements of this stream.This is an intermediate operation.
-
mapToLong
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.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToLong
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.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToDouble
RemoteDoubleStream mapToDouble(ToDoubleFunction<? super T> mapper)
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
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.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
mapToDouble
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.This is an intermediate operation.
- Parameters:
mapper
- a non-interfering, stateless function to apply to each element- Returns:
- the new stream
-
flatMap
<R> RemoteStream<R> flatMap(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.
-
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
RemoteIntStream 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. 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:
flatMap(Function)
-
flatMapToInt
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. 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:
flatMap(Function)
-
flatMapToLong
RemoteLongStream 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. 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:
flatMap(Function)
-
flatMapToLong
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. 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:
flatMap(Function)
-
flatMapToDouble
RemoteDoubleStream 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. 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:
flatMap(Function)
-
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:
flatMap(Function)
-
peek
RemoteStream<T> peek(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.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
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.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
Stream<T> limit(long maxSize)
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
Stream<T> skip(long n)
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
-
distinct
Stream<T> 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
RemoteStream<T> sorted(Comparator<? super T> comparator)
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
default RemoteStream<T> sorted(Remote.Comparator<? super T> comparator)
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
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
.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
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
.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
void forEach(Consumer<? super T> action)
Performs an action for each element of this stream.This is a terminal operation.
-
forEachOrdered
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.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:
forEach(Consumer)
-
toArray
Object[] toArray()
Returns an array containing the elements of this stream.This is a terminal operation.
-
toArray
<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.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
T 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. 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
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. 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
Optional<T> 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. 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(Object, Remote.BinaryOperator)
,min(Comparator)
,max(Comparator)
-
reduce
default Optional<T> 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. 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(Object, Remote.BinaryOperator)
,min(Comparator)
,max(Comparator)
-
reduce
<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. 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(Remote.BinaryOperator)
,reduce(Object, Remote.BinaryOperator)
-
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:
reduce(Remote.BinaryOperator)
,reduce(Object, Remote.BinaryOperator)
-
collect
<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. 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
default <R,A> R collect(Collector<? super T,A,R> collector)
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.
- Specified by:
collect
in interfaceStream<T>
- Parameters:
collector
- theCollector
describing the reduction- Returns:
- the result of the reduction
- See Also:
collect(Remote.Supplier, Remote.BiConsumer, Remote.BiConsumer)
-
collect
<R,A> R collect(RemoteCollector<? super T,A,R> collector)
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:
collect(Remote.Supplier, Remote.BiConsumer, Remote.BiConsumer)
-
min
Optional<T> min(Comparator<? super T> comparator)
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
default Optional<T> min(Remote.Comparator<? super T> comparator)
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
default <U> Optional<T> min(ValueExtractor<? super U,? extends Comparable> extractor)
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
Optional<T> max(Comparator<? super T> comparator)
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
default Optional<T> max(Remote.Comparator<? super T> comparator)
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
default <U> Optional<T> max(ValueExtractor<? super U,? extends Comparable> extractor)
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
boolean anyMatch(Predicate<? super T> predicate)
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
default boolean anyMatch(Remote.Predicate<? super T> predicate)
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
boolean allMatch(Predicate<? super T> predicate)
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
default boolean allMatch(Remote.Predicate<? super T> predicate)
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
boolean noneMatch(Predicate<? super T> predicate)
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
default boolean noneMatch(Remote.Predicate<? super T> predicate)
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
Optional<T> 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
Optional<T> 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:
findFirst()
-
toIntStream
static <T extends Number> RemoteIntStream toIntStream(RemoteStream<T> stream)
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
static <T extends Number> RemoteLongStream toLongStream(RemoteStream<T> stream)
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
static <T extends Number> RemoteDoubleStream toDoubleStream(RemoteStream<T> stream)
Convert stream of numbers intoRemoteDoubleStream
.- Type Parameters:
T
- the type of input stream elements- Parameters:
stream
- the stream of numbers- Returns:
- a
RemoteDoubleStream
instance
-
-