Class StreamGatherersExamples
Before gatherers, custom intermediate stream operations were difficult to
express. Simple operations such as map and filter work on
one element at a time, while a terminal collect operation runs only
after the stream has reached the end. That left a gap for operations that
need to emit values while still flowing through the pipeline. Developers
often had to leave the stream pipeline or force the problem into a terminal
collector. Gatherers fill that gap by letting streams model operations such
as fixed windows and running scans as intermediate operations.
A gatherer is useful when each emitted output may depend on more than one input element, or on state accumulated while the stream is flowing. That is why windowing and scanning are good teaching examples.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
StreamGatherersExamples
public StreamGatherersExamples()
-
-
Method Details
-
fixedWindows
Groups values into fixed-size windows. Windowing is an intermediate operation becausegather(...)changes how elements flow through the pipeline before the finaltoList()terminal operation runs.- Parameters:
values- values to windowsize- window size- Returns:
- fixed-size windows, with a smaller final window when needed
-
runningSum
-