Interface Gatherer<T,A,R>
- Type Parameters:
T- the type of input elements to the gatherer operationA- the potentially mutable state type of the gatherer operation (often hidden as an implementation detail)R- the type of output elements from the gatherer operation
public interface Gatherer<T,A,R>
An intermediate operation that transforms a stream of input elements into a
stream of output elements, optionally applying a final action when the end of
the upstream is reached. The transformation may be stateless or stateful,
and may buffer input before producing any output.
Gatherer operations can be performed either sequentially, or be parallelized -- if a combiner function is supplied.
There are many examples of gathering operations, including but not
limited to:
grouping elements into batches (windowing functions);
de-duplicating consecutively similar elements; incremental accumulation
functions (prefix scan); incremental reordering functions, etc. The class
Gatherers provides implementations of common
gathering operations.
- Since:
- 24
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA Downstream object is the next stage in a pipeline of operations, to which elements can be sent.static interfaceAn Integrator receives elements and processes them, optionally using the supplied state, and optionally sends incremental results downstream. -
Method Summary
Modifier and TypeMethodDescriptionReturns a composed Gatherer which connects the output of this Gatherer to the input of that Gatherer.default BinaryOperator<A> combiner()A function which accepts two intermediate states and combines them into one.static <A> BinaryOperator<A> Returns a combiner which is the default combiner of a Gatherer.static <A,R> BiConsumer <A, Gatherer.Downstream<? super R>> Returns afinisherwhich is the default finisher of aGatherer.static <A> Supplier<A> Returns an initializer which is the default initializer of a Gatherer.default BiConsumer<A, Gatherer.Downstream<? super R>> finisher()A function which accepts the final intermediate state and aGatherer.Downstreamobject, allowing to perform a final action at the end of input elements.A function that produces an instance of the intermediate state used for this gathering operation.A function which integrates provided elements, potentially using the provided intermediate state, optionally producing output to the providedGatherer.Downstream.static <T,A, R> Gatherer <T, A, R> of(Supplier<A> initializer, Gatherer.Integrator<A, T, R> integrator, BinaryOperator<A> combiner, BiConsumer<A, Gatherer.Downstream<? super R>> finisher) Returns a new, parallelizable,Gathererdescribed by the giveninitializer,integrator,combinerandfinisher.of(Gatherer.Integrator<Void, T, R> integrator) Returns a new, parallelizable, and statelessGathererdescribed by the givenintegrator.of(Gatherer.Integrator<Void, T, R> integrator, BiConsumer<Void, Gatherer.Downstream<? super R>> finisher) Returns a new, parallelizable, and statelessGathererdescribed by the givenintegratorandfinisher.static <T,A, R> Gatherer <T, A, R> ofSequential(Supplier<A> initializer, Gatherer.Integrator<A, T, R> integrator) Returns a new, sequential,Gathererdescribed by the giveninitializerandintegrator.static <T,A, R> Gatherer <T, A, R> ofSequential(Supplier<A> initializer, Gatherer.Integrator<A, T, R> integrator, BiConsumer<A, Gatherer.Downstream<? super R>> finisher) Returns a new, sequential,Gathererdescribed by the giveninitializer,integrator, andfinisher.ofSequential(Gatherer.Integrator<Void, T, R> integrator) Returns a new, sequential, and statelessGathererdescribed by the givenintegrator.ofSequential(Gatherer.Integrator<Void, T, R> integrator, BiConsumer<Void, Gatherer.Downstream<? super R>> finisher) Returns a new, sequential, and statelessGathererdescribed by the givenintegratorandfinisher.
-
Method Details
-
initializer
-
integrator
Gatherer.Integrator<A,T, integrator()R> A function which integrates provided elements, potentially using the provided intermediate state, optionally producing output to the providedGatherer.Downstream.- Returns:
- a function which integrates provided elements, potentially using the provided state, optionally producing output to the provided Downstream
-
combiner
A function which accepts two intermediate states and combines them into one.- Returns:
- a function which accepts two intermediate states and combines them into one
-
finisher
A function which accepts the final intermediate state and aGatherer.Downstreamobject, allowing to perform a final action at the end of input elements.- Returns:
- a function which transforms the intermediate result to the final result(s) which are then passed on to the provided Downstream
-
andThen
Returns a composed Gatherer which connects the output of this Gatherer to the input of that Gatherer.- Type Parameters:
RR- The type of output of that Gatherer- Parameters:
that- the other gatherer- Returns:
- returns a composed Gatherer which connects the output of this Gatherer as input that Gatherer
- Throws:
NullPointerException- if the argument isnull
-
defaultInitializer
Returns an initializer which is the default initializer of a Gatherer. The returned initializer identifies that the owner Gatherer is stateless.- Type Parameters:
A- the type of the state of the returned initializer- Returns:
- the instance of the default initializer
- See Also:
-
defaultCombiner
Returns a combiner which is the default combiner of a Gatherer. The returned combiner identifies that the owning Gatherer must only be evaluated sequentially.- Type Parameters:
A- the type of the state of the returned combiner- Returns:
- the instance of the default combiner
- See Also:
-
defaultFinisher
Returns afinisherwhich is the default finisher of aGatherer. The returned finisher identifies that the owning Gatherer performs no additional actions at the end of input.- Type Parameters:
A- the type of the state of the returned finisherR- the type of the Downstream of the returned finisher- Returns:
- the instance of the default finisher
- See Also:
-
ofSequential
Returns a new, sequential, and statelessGathererdescribed by the givenintegrator.- Type Parameters:
T- the type of input elements for the new gathererR- the type of results for the new gatherer- Parameters:
integrator- the integrator function for the new gatherer- Returns:
- the new
Gatherer - Throws:
NullPointerException- if the argument isnull
-
ofSequential
static <T,R> Gatherer<T,Void, ofSequentialR> (Gatherer.Integrator<Void, T, R> integrator, BiConsumer<Void, Gatherer.Downstream<? super R>> finisher) Returns a new, sequential, and statelessGathererdescribed by the givenintegratorandfinisher.- Type Parameters:
T- the type of input elements for the new gathererR- the type of results for the new gatherer- Parameters:
integrator- the integrator function for the new gathererfinisher- the finisher function for the new gatherer- Returns:
- the new
Gatherer - Throws:
NullPointerException- if any argument isnull
-
ofSequential
static <T,A, Gatherer<T,R> A, ofSequentialR> (Supplier<A> initializer, Gatherer.Integrator<A, T, R> integrator) Returns a new, sequential,Gathererdescribed by the giveninitializerandintegrator.- Type Parameters:
T- the type of input elements for the new gathererA- the type of state for the new gathererR- the type of results for the new gatherer- Parameters:
initializer- the initializer function for the new gathererintegrator- the integrator function for the new gatherer- Returns:
- the new
Gatherer - Throws:
NullPointerException- if any argument isnull
-
ofSequential
static <T,A, Gatherer<T,R> A, ofSequentialR> (Supplier<A> initializer, Gatherer.Integrator<A, T, R> integrator, BiConsumer<A, Gatherer.Downstream<? super R>> finisher) Returns a new, sequential,Gathererdescribed by the giveninitializer,integrator, andfinisher.- Type Parameters:
T- the type of input elements for the new gathererA- the type of state for the new gathererR- the type of results for the new gatherer- Parameters:
initializer- the initializer function for the new gathererintegrator- the integrator function for the new gathererfinisher- the finisher function for the new gatherer- Returns:
- the new
Gatherer - Throws:
NullPointerException- if any argument isnull
-
of
Returns a new, parallelizable, and statelessGathererdescribed by the givenintegrator.- Type Parameters:
T- the type of input elements for the new gathererR- the type of results for the new gatherer- Parameters:
integrator- the integrator function for the new gatherer- Returns:
- the new
Gatherer - Throws:
NullPointerException- if any argument isnull
-
of
static <T,R> Gatherer<T,Void, ofR> (Gatherer.Integrator<Void, T, R> integrator, BiConsumer<Void, Gatherer.Downstream<? super R>> finisher) Returns a new, parallelizable, and statelessGathererdescribed by the givenintegratorandfinisher.- Type Parameters:
T- the type of input elements for the new gathererR- the type of results for the new gatherer- Parameters:
integrator- the integrator function for the new gathererfinisher- the finisher function for the new gatherer- Returns:
- the new
Gatherer - Throws:
NullPointerException- if any argument isnull
-
of
static <T,A, Gatherer<T,R> A, ofR> (Supplier<A> initializer, Gatherer.Integrator<A, T, R> integrator, BinaryOperator<A> combiner, BiConsumer<A, Gatherer.Downstream<? super R>> finisher) Returns a new, parallelizable,Gathererdescribed by the giveninitializer,integrator,combinerandfinisher.- Type Parameters:
T- the type of input elements for the new gathererA- the type of state for the new gathererR- the type of results for the new gatherer- Parameters:
initializer- the initializer function for the new gathererintegrator- the integrator function for the new gatherercombiner- the combiner function for the new gathererfinisher- the finisher function for the new gatherer- Returns:
- the new
Gatherer - Throws:
NullPointerException- if any argument isnull
-