public abstract class GroupingObjectStream<C,E> extends AbstractObjectStream<C>
Base class for streams that group the output of another 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.
|
iterator
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
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 Closeable
close
in interface AutoCloseable
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.