- Type Parameters:
I- the type of the items emitted by the upstreamACC- the type of the accumulatorO- the type of the items emitted to the downstream
- All Known Implementing Classes:
Gatherers.DefaultGatherer
@Experimental("This API is still being designed and may change in the future")
public interface Gatherer<I,ACC,O>
A Gatherer operator transforms a stream of items by accumulating them into an accumulator and extracting
items from that accumulator when certain conditions are met.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classBuilder for creating aGatherer.static final recordAn extraction result containing the next accumulator and the next item to emit.static classThe second step in the builder to gather items emitted by aMultiinto an accumulator.static classThe third step in the builder to gather items emitted by aMultiinto an accumulator.static classThe first step in the builder to gather items emitted by aMultiinto an accumulator. -
Method Summary
Modifier and TypeMethodDescriptionaccumulate(ACC accumulator, I item) Accumulates an item into the accumulator.Creates a new accumulator.Extracts an item from the accumulator.Finalizes the accumulator and extracts the final item, if any.
-
Method Details
-
accumulator
ACC accumulator()Creates a new accumulator.- Returns:
- a new accumulator
-
accumulate
Accumulates an item into the accumulator.- Parameters:
accumulator- the current accumulatoritem- the item to accumulate- Returns:
- the updated accumulator
-
extract
Extracts an item from the accumulator.- Parameters:
accumulator- the current accumulatorupstreamCompleted- whether the upstream has completed- Returns:
- an Optional containing a Extraction with the updated accumulator and the extracted item, or an empty Optional if no item can be extracted
-
finalize
Finalizes the accumulator and extracts the final item, if any. This method is called when the upstream has completed and no more items can be extracted using the extract method.- Parameters:
accumulator- the current accumulator- Returns:
- an Optional containing the final item, or an empty Optional if no final item can be extracted
-