public abstract class GroupingObjectStream<C,E> extends AbstractObjectStream<C>
Base class for streams that group the output of another stream.
stream
Modifier | Constructor and Description |
---|---|
protected |
GroupingObjectStream(ObjectStream<? extends E> base) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
clearGroup()
Clear the accumulated group.
|
void |
close()
No-op implementation of the
ObjectStream.close() method. |
protected abstract C |
finishGroup()
Finish the current group and return it.
|
protected abstract boolean |
handleItem(E item)
Handle an item from the base stream.
|
C |
readObject()
Read the next object from this stream.
|
allMatch, anyMatch, collect, collect, count, distinct, filter, findAny, findFirst, flatMap, flatMapToDouble, flatMapToInt, flatMapToLong, forEach, forEachOrdered, isParallel, iterator, limit, map, mapToDouble, mapToInt, mapToLong, max, min, noneMatch, onClose, parallel, peek, reduce, reduce, reduce, sequential, skip, sorted, sorted, spliterator, toArray, toArray, unordered
protected GroupingObjectStream(@WillCloseWhenClosed ObjectStream<? extends E> base)
@Nullable public C readObject()
ObjectStream
Read the next object from this stream.
null
if at the end of the stream.public void close()
AbstractObjectStream
No-op implementation of the ObjectStream.close()
method.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.util.stream.BaseStream<C,java.util.stream.Stream<C>>
close
in interface ObjectStream<C>
close
in class AbstractObjectStream<C>
protected abstract void clearGroup()
Clear the accumulated group. Called by close()
.
protected abstract boolean handleItem(@Nonnull E item)
Handle an item from the base stream. Each item of the base stream is passed to this method. The method builds up the underlying aggregate.
item
- The item to handle.true
if the item has been accepted and added to the group; false
if it cannot be added to the current group. If it cannot be added to the current group, the stream will call finishGroup()
to finish the group, and then call this method again with item
(at which point it is required to return true
).@Nonnull protected abstract C finishGroup()
Finish the current group and return it. After this method has been called, #handleItem(E)
should add items to a new group. This method will not be called unless #handleItem(E)
has been called at least once since the last group was finished.