public abstract class SingleEntryUpcaster<T> extends Object implements Upcaster<T>
Upcaster
that eases the common process of upcasting one intermediate
representation to another representation by applying a simple mapping function to the input stream of intermediate
representations.Constructor and Description |
---|
SingleEntryUpcaster() |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
canUpcast(T intermediateRepresentation)
Checks if this upcaster can upcast the given
intermediateRepresentation . |
protected abstract T |
doUpcast(T intermediateRepresentation)
Upcasts the given
intermediateRepresentation . |
Stream<T> |
upcast(Stream<T> intermediateRepresentations)
Apply this upcaster to a stream of
intermediateRepresentations and return the altered stream. |
public Stream<T> upcast(Stream<T> intermediateRepresentations)
Upcaster
intermediateRepresentations
and return the altered stream.
To upcast an object an upcaster should apply a mapping function to the input stream (Stream.map(java.util.function.Function)
). To remove an object from the stream the upcaster should filter the
input stream (Stream.filter(java.util.function.Predicate)
). To split an input object into more than one
objects use Stream.flatMap(java.util.function.Function)
.
In some cases the upcasting result of an Upcaster may depend on more than one input object. In that case an Upcaster may store state in the method during upcasting or even read ahead in the stream.
protected abstract boolean canUpcast(T intermediateRepresentation)
intermediateRepresentation
. If the upcaster cannot upcast
the representation the doUpcast(Object)
is not invoked.intermediateRepresentation
- the intermediate object representation to upcasttrue
if the representation can be upcast, false
otherwiseprotected abstract T doUpcast(T intermediateRepresentation)
intermediateRepresentation
. This method is only invoked if canUpcast(Object)
returned true
for the given representation.
Note that the returned representation should not be null
. To remove an intermediateRepresentation
add a filter to the input stream.
intermediateRepresentation
- the representation of the object to upcastCopyright © 2010–2019. All rights reserved.