T
- the type of the stream elementspublic interface DistributedStream<T> extends java.util.stream.Stream<T>
Stream
that supports distributed stream
operations by replacing functional interfaces with their serializable
equivalents.java.util.stream.Stream.Builder<T>
Modifier and Type | Method and Description |
---|---|
default boolean |
allMatch(DistributedPredicate<? super T> predicate)
Returns whether all elements of this stream match the provided predicate.
|
boolean |
allMatch(java.util.function.Predicate<? super T> predicate) |
default boolean |
anyMatch(DistributedPredicate<? super T> predicate)
Returns whether any elements of this stream match the provided
predicate.
|
boolean |
anyMatch(java.util.function.Predicate<? super T> predicate) |
<R> R |
collect(DistributedCollector.Reducer<? super T,R> reducer)
Terminate the stream using a reduction performed by
DistributedCollector.Reducer
and return the resulting value. |
default <R,A> R |
collect(DistributedCollector<? super T,A,R> collector)
Performs a mutable
reduction operation on the elements of this stream using a
DistributedCollector . |
default <R> R |
collect(DistributedSupplier<R> supplier,
DistributedBiConsumer<R,? super T> accumulator,
DistributedBiConsumer<R,R> combiner)
Performs a mutable
reduction operation on the elements of this stream.
|
<R> R |
collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super T> accumulator,
java.util.function.BiConsumer<R,R> combiner) |
DistributedStream<T> |
configure(JobConfig jobConfig) |
DistributedStream<T> |
distinct() |
default DistributedStream<T> |
filter(DistributedPredicate<? super T> predicate)
Returns a stream consisting of the elements of this stream that match
the given predicate.
|
DistributedStream<T> |
filter(java.util.function.Predicate<? super T> predicate) |
default <R> DistributedStream<R> |
flatMap(DistributedFunction<? super T,? extends java.util.stream.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> DistributedStream<R> |
flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper) |
default DistributedDoubleStream |
flatMapToDouble(DistributedFunction<? super T,? extends java.util.stream.DoubleStream> mapper)
Returns an
DoubleStream 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. |
DistributedDoubleStream |
flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper) |
default DistributedIntStream |
flatMapToInt(DistributedFunction<? super T,? extends java.util.stream.IntStream> mapper)
Returns an
IntStream 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. |
DistributedIntStream |
flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper) |
default DistributedLongStream |
flatMapToLong(DistributedFunction<? super T,? extends java.util.stream.LongStream> mapper)
Returns an
LongStream 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. |
DistributedLongStream |
flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper) |
static <T> DistributedStream<T> |
fromSource(JetInstance instance,
ProcessorMetaSupplier metaSupplier)
Returns a distributed
Stream with given processors as its source. |
DistributedStream<T> |
limit(long maxSize) |
default <R> DistributedStream<R> |
map(DistributedFunction<? super T,? extends R> mapper)
Returns a stream consisting of the results of applying the given
function to the elements of this stream.
|
<R> DistributedStream<R> |
map(java.util.function.Function<? super T,? extends R> mapper) |
default DistributedDoubleStream |
mapToDouble(DistributedToDoubleFunction<? super T> mapper)
Returns a
DistributedDoubleStream consisting of the results of applying the
given function to the elements of this stream. |
DistributedDoubleStream |
mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper) |
default DistributedIntStream |
mapToInt(DistributedToIntFunction<? super T> mapper)
Returns an
DistributedIntStream consisting of the results of applying the
given function to the elements of this stream. |
DistributedIntStream |
mapToInt(java.util.function.ToIntFunction<? super T> mapper) |
default DistributedLongStream |
mapToLong(DistributedToLongFunction<? super T> mapper)
Returns a
DistributedLongStream consisting of the results of applying the
given function to the elements of this stream. |
DistributedLongStream |
mapToLong(java.util.function.ToLongFunction<? super T> mapper) |
Optional<T> |
max(Comparator<? super T> comparator) |
default Optional<T> |
max(DistributedComparator<? super T> comparator)
Returns the maximum element of this stream according to the provided
DistributedComparator . |
Optional<T> |
min(Comparator<? super T> comparator) |
default Optional<T> |
min(DistributedComparator<? super T> comparator)
Returns the minimum element of this stream according to the provided
DistributedComparator . |
default boolean |
noneMatch(DistributedPredicate<? super T> predicate)
Returns whether no elements of this stream match the provided predicate.
|
boolean |
noneMatch(java.util.function.Predicate<? super T> predicate) |
DistributedStream<T> |
parallel() |
DistributedStream<T> |
peek(java.util.function.Consumer<? super T> action) |
default DistributedStream<T> |
peek(DistributedConsumer<? 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.
|
Optional<T> |
reduce(java.util.function.BinaryOperator<T> accumulator) |
default Optional<T> |
reduce(DistributedBinaryOperator<T> accumulator)
Performs a reduction on the
elements of this stream, using an
associative accumulation
function, and returns an
Optional describing the reduced value,
if any. |
T |
reduce(T identity,
java.util.function.BinaryOperator<T> accumulator) |
default T |
reduce(T identity,
DistributedBinaryOperator<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.
|
<U> U |
reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.BinaryOperator<U> combiner) |
default <U> U |
reduce(U identity,
DistributedBiFunction<U,? super T,U> accumulator,
DistributedBinaryOperator<U> combiner)
Performs a reduction on the
elements of this stream, using the provided identity, accumulation and
combining functions.
|
DistributedStream<T> |
sequential() |
DistributedStream<T> |
skip(long n) |
DistributedStream<T> |
sorted() |
DistributedStream<T> |
sorted(Comparator<? super T> comparator) |
default DistributedStream<T> |
sorted(DistributedComparator<? super T> comparator)
Returns a stream consisting of the elements of this stream, sorted
according to the provided
Comparator . |
DistributedStream<T> |
unordered() |
builder, collect, concat, count, empty, findAny, findFirst, forEach, forEachOrdered, generate, iterate, of, of, toArray, toArray
close, isParallel, iterator, onClose, spliterator
static <T> DistributedStream<T> fromSource(JetInstance instance, ProcessorMetaSupplier metaSupplier)
Stream
with given processors as its source.default DistributedStream<T> filter(DistributedPredicate<? super T> predicate)
This is an intermediate operation.
predicate
- a non-interfering, stateless predicate to apply to each element
to determine if it
should be includeddefault <R> DistributedStream<R> map(DistributedFunction<? super T,? extends R> mapper)
This is an intermediate operation.
R
- The element type of the new streammapper
- a non-interfering, stateless function to apply to each elementdefault DistributedIntStream mapToInt(DistributedToIntFunction<? super T> mapper)
DistributedIntStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapper
- a non-interfering, stateless function to apply to each elementdefault DistributedLongStream mapToLong(DistributedToLongFunction<? super T> mapper)
DistributedLongStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapper
- a non-interfering, stateless function to apply to each elementdefault DistributedDoubleStream mapToDouble(DistributedToDoubleFunction<? super T> mapper)
DistributedDoubleStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapper
- a non-interfering, stateless function to apply to each elementdefault <R> DistributedStream<R> flatMap(DistributedFunction<? super T,? extends java.util.stream.Stream<? extends R>> mapper)
closed
after its contents
have been placed into this stream. (If a mapped stream is null
an empty stream is used, instead.)
This is an intermediate operation.
R
- The element type of the new streammapper
- a non-interfering, stateles function to apply to each element which produces
a stream of new valuesdefault DistributedIntStream flatMapToInt(DistributedFunction<? super T,? extends java.util.stream.IntStream> mapper)
IntStream
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 is closed
after its
contents have been placed into this stream. (If a mapped stream is
null
an empty stream is used, instead.)
This is an intermediate operation.
mapper
- a non-interfering, stateless function to apply to each element which produces
a stream of new valuesflatMap(Function)
default DistributedLongStream flatMapToLong(DistributedFunction<? super T,? extends java.util.stream.LongStream> mapper)
LongStream
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 is closed
after its
contents have been placed into this stream. (If a mapped stream is
null
an empty stream is used, instead.)
This is an intermediate operation.
mapper
- a non-interfering, stateless function to apply to each element which produces
a stream of new valuesflatMap(Function)
default DistributedDoubleStream flatMapToDouble(DistributedFunction<? super T,? extends java.util.stream.DoubleStream> mapper)
DoubleStream
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 is closed
after its
contents have placed been into this stream. (If a mapped stream is
null
an empty stream is used, instead.)
This is an intermediate operation.
mapper
- a non-interfering, stateless function to apply to each element which
produces a stream of new valuesflatMap(Function)
DistributedStream<T> distinct()
distinct
in interface java.util.stream.Stream<T>
DistributedStream<T> sorted()
sorted
in interface java.util.stream.Stream<T>
default DistributedStream<T> sorted(DistributedComparator<? super T> comparator)
Comparator
.
For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made.
This is a stateful intermediate operation.
comparator
- a non-interfering, stateless
DistributedComparator
to be used to compare stream elementsdefault DistributedStream<T> peek(DistributedConsumer<? super T> action)
This is an intermediate operation.
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.
action
- a
non-interfering action to perform on the elements as
they are consumed from the streamDistributedStream<T> limit(long maxSize)
limit
in interface java.util.stream.Stream<T>
DistributedStream<T> skip(long n)
skip
in interface java.util.stream.Stream<T>
default T reduce(T identity, DistributedBinaryOperator<T> accumulator)
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 all t
,
accumulator.apply(identity, t)
is equal to t
.
The accumulator
function must be an
associative function.
This is a terminal operation.
identity
- the identity value for the accumulating functionaccumulator
- an associative, non-interfering, stateless
function for combining two valuesdefault Optional<T> reduce(DistributedBinaryOperator<T> accumulator)
Optional
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.
accumulator
- an associative, non-interfering, stateless
function for combining two valuesOptional
describing the result of the reductionNullPointerException
- if the result of the reduction is nullreduce(Object, DistributedBinaryOperator)
,
min(DistributedComparator)
,
max(DistributedComparator)
default <U> U reduce(U identity, DistributedBiFunction<U,? super T,U> accumulator, DistributedBinaryOperator<U> combiner)
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 all u
, combiner(identity, u)
is equal to u
. Additionally, the combiner
function
must be compatible with the accumulator
function; for all
u
and t
, the following must hold:
combiner.apply(u, accumulator.apply(identity, t)) == accumulator.apply(u, t)
This is a terminal operation.
U
- The type of the resultidentity
- 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 functionreduce(DistributedBinaryOperator)
,
reduce(Object, DistributedBinaryOperator)
default <R> R collect(DistributedSupplier<R> supplier, DistributedBiConsumer<R,? super T> accumulator, DistributedBiConsumer<R,R> combiner)
ArrayList
, 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, DistributedBinaryOperator)
, collect
operations
can be parallelized without requiring additional synchronization.
This is a terminal operation.
R
- type of the resultsupplier
- 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 functiondefault <R,A> R collect(DistributedCollector<? super T,A,R> collector)
DistributedCollector
. A DistributedCollector
encapsulates the functions used as arguments to
collect(DistributedSupplier, DistributedBiConsumer, DistributedBiConsumer)
,
allowing for reuse of collection strategies and composition of collect operations such as
multiple-level grouping or partitioning.
This is a terminal operation.
When executed in parallel, multiple intermediate results may be
instantiated, populated, and merged so as to maintain isolation of
mutable data structures. Therefore, even when executed in parallel
with non-thread-safe data structures (such as ArrayList
), no
additional synchronization is needed for a parallel reduction.
R
- the type of the resultA
- the intermediate accumulation type of the DistributedCollector
collector
- the DistributedCollector
describing the reductioncollect(Supplier, BiConsumer, BiConsumer)
,
Collectors
<R> R collect(DistributedCollector.Reducer<? super T,R> reducer)
DistributedCollector.Reducer
and return the resulting value.
A DistributedCollector.Reducer
is specific to Jet, and is responsible for building
and executing the underlying DAG. It can't be used as a downstream collector in a
collector cascade.R
- type of the return valuereducer
- the reducerdefault Optional<T> min(DistributedComparator<? super T> comparator)
DistributedComparator
. This is a special case of a
reduction.
This is a terminal operation.
comparator
- a non-interfering, stateless
DistributedComparator
to compare elements of this streamOptional
describing the minimum element of this stream,
or an empty Optional
if the stream is emptyNullPointerException
- if the minimum element is nulldefault Optional<T> max(DistributedComparator<? super T> comparator)
DistributedComparator
. This is a special case of a
reduction.
This is a terminal operation.
comparator
- a non-interfering,
stateless
DistributedComparator
to compare elements of this streamOptional
describing the maximum element of this stream,
or an empty Optional
if the stream is emptyNullPointerException
- if the maximum element is nulldefault boolean anyMatch(DistributedPredicate<? super T> predicate)
false
is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
predicate
- a non-interfering, stateless
predicate to apply to elements of this streamtrue
if any elements of the stream match the provided
predicate, otherwise false
default boolean allMatch(DistributedPredicate<? super T> predicate)
true
is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
predicate
- a non-interfering, stateless
predicate to apply to elements of this streamtrue
if either all elements of the stream match the
provided predicate or the stream is empty, otherwise false
default boolean noneMatch(DistributedPredicate<? super T> predicate)
true
is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
predicate
- a non-interfering,
stateless
predicate to apply to elements of this streamtrue
if either no elements of the stream match the
provided predicate or the stream is empty, otherwise false
DistributedStream<T> sequential()
sequential
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
DistributedStream<T> parallel()
parallel
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
DistributedStream<T> unordered()
unordered
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
DistributedStream<T> filter(java.util.function.Predicate<? super T> predicate)
filter
in interface java.util.stream.Stream<T>
<R> DistributedStream<R> map(java.util.function.Function<? super T,? extends R> mapper)
map
in interface java.util.stream.Stream<T>
DistributedIntStream mapToInt(java.util.function.ToIntFunction<? super T> mapper)
mapToInt
in interface java.util.stream.Stream<T>
DistributedLongStream mapToLong(java.util.function.ToLongFunction<? super T> mapper)
mapToLong
in interface java.util.stream.Stream<T>
DistributedDoubleStream mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper)
mapToDouble
in interface java.util.stream.Stream<T>
<R> DistributedStream<R> flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper)
flatMap
in interface java.util.stream.Stream<T>
DistributedIntStream flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper)
flatMapToInt
in interface java.util.stream.Stream<T>
DistributedLongStream flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper)
flatMapToLong
in interface java.util.stream.Stream<T>
DistributedDoubleStream flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper)
flatMapToDouble
in interface java.util.stream.Stream<T>
DistributedStream<T> sorted(Comparator<? super T> comparator)
sorted
in interface java.util.stream.Stream<T>
DistributedStream<T> peek(java.util.function.Consumer<? super T> action)
peek
in interface java.util.stream.Stream<T>
T reduce(T identity, java.util.function.BinaryOperator<T> accumulator)
reduce
in interface java.util.stream.Stream<T>
Optional<T> reduce(java.util.function.BinaryOperator<T> accumulator)
reduce
in interface java.util.stream.Stream<T>
<U> U reduce(U identity, java.util.function.BiFunction<U,? super T,U> accumulator, java.util.function.BinaryOperator<U> combiner)
reduce
in interface java.util.stream.Stream<T>
<R> R collect(java.util.function.Supplier<R> supplier, java.util.function.BiConsumer<R,? super T> accumulator, java.util.function.BiConsumer<R,R> combiner)
collect
in interface java.util.stream.Stream<T>
Optional<T> min(Comparator<? super T> comparator)
min
in interface java.util.stream.Stream<T>
Optional<T> max(Comparator<? super T> comparator)
max
in interface java.util.stream.Stream<T>
boolean anyMatch(java.util.function.Predicate<? super T> predicate)
anyMatch
in interface java.util.stream.Stream<T>
boolean allMatch(java.util.function.Predicate<? super T> predicate)
allMatch
in interface java.util.stream.Stream<T>
boolean noneMatch(java.util.function.Predicate<? super T> predicate)
noneMatch
in interface java.util.stream.Stream<T>
DistributedStream<T> configure(JobConfig jobConfig)
jobConfig
- Job configuration which will be used while executing underlying DAGCopyright © 2017 Hazelcast, Inc.. All Rights Reserved.