@Experimental("This API is still being designed and may change in the future")
public interface Gatherers
Factory interface for creating
Gatherer instances.
This interface provides various static methods to create different types of gatherers.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classDefault implementation of theGathererinterface. -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic <I> Gatherer.Builder<I> builder()Creates a newGathererbuilder.static <I> Gatherer<I, I, I> fold(Supplier<I> initialAccumulatorSupplier, BiFunction<I, I, I> accumulatorFunction) Creates a newGathererthat performs a fold operation.static <I,ACC, O>
Gatherer<I, ACC, O> of(Supplier<ACC> initialAccumulatorSupplier, BiFunction<ACC, I, ACC> accumulatorFunction, BiFunction<ACC, Boolean, Optional<Gatherer.Extraction<ACC, O>>> extractor, Function<ACC, Optional<O>> finalizer) Creates a newGathererwith the specified components.static <I> Gatherer<I, I, I> scan(Supplier<I> initialAccumulatorSupplier, BiFunction<I, I, I> accumulatorFunction) Creates a newGathererthat performs a scan operation.slidingWindow(int size) Creates a newGathererthat performs a sliding window operation.window(int size) Creates a newGathererthat performs a windowing operation.
-
Method Details
-
of
static <I,ACC, Gatherer<I,O> ACC, ofO> (Supplier<ACC> initialAccumulatorSupplier, BiFunction<ACC, I, ACC> accumulatorFunction, BiFunction<ACC, Boolean, Optional<Gatherer.Extraction<ACC, O>>> extractor, Function<ACC, Optional<O>> finalizer) Creates a newGathererwith the specified components.- 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- Parameters:
initialAccumulatorSupplier- the supplier for the initial accumulatoraccumulatorFunction- the function to accumulate items into the accumulatorextractor- the function to extract items from the accumulatorfinalizer- the function to extract the final item from the accumulator- Returns:
- a new
Gatherer
-
scan
static <I> Gatherer<I,I, scanI> (Supplier<I> initialAccumulatorSupplier, BiFunction<I, I, I> accumulatorFunction) Creates a newGathererthat performs a scan operation. The scan operation applies a function to each item emitted by the upstream, using the result of the previous application as the first argument to the function. The initial value is provided by the initialAccumulatorSupplier.Each intermediate result is emitted downstream.
- Type Parameters:
I- the type of the items emitted by the upstream and downstream- Parameters:
initialAccumulatorSupplier- the supplier for the initial accumulatoraccumulatorFunction- the function to accumulate items- Returns:
- a new
Gathererthat performs a scan operation
-
fold
static <I> Gatherer<I,I, foldI> (Supplier<I> initialAccumulatorSupplier, BiFunction<I, I, I> accumulatorFunction) Creates a newGathererthat performs a fold operation. The fold operation applies a function to each item emitted by the upstream, using the result of the previous application as the first argument to the function. The initial value is provided by the initialAccumulatorSupplier.Only emits the final result when the upstream completes.
- Type Parameters:
I- the type of the items emitted by the upstream and downstream- Parameters:
initialAccumulatorSupplier- the supplier for the initial accumulatoraccumulatorFunction- the function to accumulate items- Returns:
- a new
Gathererthat performs a fold operation
-
window
Creates a newGathererthat performs a windowing operation. The windowing operation collects items emitted by the upstream into non-overlapping windows of the specified size. When a window is full, it is emitted downstream and a new window is started. If the upstream completes before a window is full, the current window is emitted if it is not empty.- Type Parameters:
I- the type of the items emitted by the upstream- Parameters:
size- the size of the window- Returns:
- a new
Gathererthat performs a windowing operation
-
slidingWindow
Creates a newGathererthat performs a sliding window operation. The sliding window operation collects items emitted by the upstream into overlapping windows of the specified size. When a window is full, it is emitted downstream and a new window is started with all but the first item from the previous window. If the upstream completes before a window is full, the current window is emitted if it is not empty.- Type Parameters:
I- the type of the items emitted by the upstream- Parameters:
size- the size of the window- Returns:
- a new
Gathererthat performs a sliding window operation
-
builder
Creates a newGathererbuilder.- Type Parameters:
I- the type of the items emitted by the upstream- Returns:
- the builder
-