T
- the type of entry to be upcasted as T
C
- the type of context used as C
public abstract class ContextAwareSingleEntryMultiUpcaster<T,C> 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.
Additionally, it's a context aware implementation, which enables it to store and reuse context information from one
entry to another during upcasting.Constructor and Description |
---|
ContextAwareSingleEntryMultiUpcaster() |
Modifier and Type | Method and Description |
---|---|
protected abstract C |
buildContext()
Builds a context of generic type
C to be used when processing the stream of intermediate object
representations T . |
protected abstract boolean |
canUpcast(T intermediateRepresentation,
C context)
Checks if this upcaster can upcast the given
intermediateRepresentation . |
protected abstract Stream<T> |
doUpcast(T intermediateRepresentation,
C context)
Upcasts the given
intermediateRepresentation . |
Stream<T> |
upcast(Stream<T> intermediateRepresentations)
Apply this upcaster to a stream of
intermediateRepresentations and return the altered stream. |
public ContextAwareSingleEntryMultiUpcaster()
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, C context)
intermediateRepresentation
.
If the upcaster cannot upcast the representation the doUpcast(Object, Object)
is not invoked.
The context
can be used to store or retrieve entry specific information required to make the
canUpcast(Object, Object)
check.intermediateRepresentation
- the intermediate object representation to upcast as T
context
- the context for this upcaster as C
true
if the representation can be upcast, false
otherwiseprotected abstract Stream<T> doUpcast(T intermediateRepresentation, C context)
intermediateRepresentation
. This method is only invoked if canUpcast(Object,
Object)
returned true
for the given representation. The context
can be used to store or retrieve
entry specific information required to perform the upcasting process.
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 upcast as T
context
- the context for this upcaster as C
Stream
with generic type T
protected abstract C buildContext()
C
to be used when processing the stream of intermediate object
representations T
.C
Copyright © 2010–2018. All rights reserved.