public abstract class SingleEntryMultiUpcaster<T> extends Object implements Upcaster<T>
Upcaster
that eases the common process of upcasting one intermediate
representation to several other representations by applying a simple flat mapping function to the input stream of
intermediate representations.Constructor and Description |
---|
SingleEntryMultiUpcaster() |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
canUpcast(T intermediateRepresentation)
Checks if this upcaster can upcast the given
intermediateRepresentation . |
protected abstract Stream<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(T)
is not invoked.intermediateRepresentation
- the intermediate object representation to upcasttrue
if the representation can be upcast, false
otherwiseprotected abstract Stream<T> doUpcast(T intermediateRepresentation)
intermediateRepresentation
.
This method is only invoked if #canUpcast(T)
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 upcastStream
with generic type T
Copyright © 2010–2018. All rights reserved.