|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.collections15.functors.transformer.ChainedTransformer<I,M,O>
public class ChainedTransformer<I,M,O>
Transformer
implementation that chains two specified
Transformer
s together. The principal restriction on the chaining
together of two Transformer
s into a chain is that the generic
output type of the first Transformer
must match the generic
input type of the second Transformer
. For example:
Transformer<A, B> t1; Transformer<B, C> t2; ... Transformer<A, C> chained = ChainedTransformer.getInstance(t1, t2);The
transform()
method of a ChainedTransformer
works by transforming an input object using the first
Transformer
, resulting in an intermediate object. This is then
transformed by the second Transformer
, resulting in the returned
output object.
The methods prepend(net.sf.collections15.Transformer)
and append(net.sf.collections15.Transformer super O, T>)
can be used to add
additional Transformer
s to the chain, allowing multiple
Transformer
s to be chained together in a typesafe manner. In
this way, a tree of Transformers
can be built up, whereby the
leaves of the tree form a typesafe chain of Transformer
s The
input type of the first leaf Transformer
is I
, and
the output type of the last leaf Transformer
is O
.
The transform process takes an input object, transforms it using the first
leaf Transformer
, and passes the result on to the next leaf.
This process repeats along the chain of leaves, until the last leaf
Transformer
in the chain produces the final output object.
Here's an example, showing the use of the static factory method, and both the
prepend
and append
methods:
Transformer<A, B> t1; Transformer<B, C> t2; Transformer<C, D> t3; Transformer<D, E> t4; ... Transformer<A, E> chained = ChainedTransformer.getInstance(t2, t3) .append(t4).prepend(t1);
Constructor Summary | |
---|---|
protected |
ChainedTransformer(Transformer<? super I,? extends M> firstTransformer,
Transformer<? super M,? extends O> secondTransformer)
Creates a new instance that chains together the two specified Transformer s. |
Method Summary | ||
---|---|---|
|
append(Transformer<? super O,T> transformer)
Appends a specified Transformer to the end of the chain,
resulting in a new ChainedTransformer that transforms an
input object through the existing Transformer s in this
chain, and then transforms the result through the specified
Transformer . |
|
static
|
getInstance(Transformer<? super I,? extends M> firstTransformer,
Transformer<? super M,? extends O> secondTransformer)
Returns a new ChainedTransformer instance that chains
together the two specified Transformer s. |
|
|
prepend(Transformer<T,? extends I> transformer)
Prepends a specified Transformer to the start of the chain,
resulting in a new ChainedTransformer that transforms an
input object through the specified Transformer , and then
transforms the result through the existing Transformer s in
this chain. |
|
O |
transform(I input)
Transforms the input object by transforming it using the first Transformer , and then transforming the result using the
second Transformer , returning the resulting output object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected ChainedTransformer(Transformer<? super I,? extends M> firstTransformer, Transformer<? super M,? extends O> secondTransformer)
Transformer
s.
firstTransformer
- The first Transformer
in the
chain.secondTransformer
- The second Transformer
in the
chain.
java.lang.IllegalArgumentException
- Thrown if either Transformer
is null
.Method Detail |
---|
public static <I,M,O> ChainedTransformer<I,M,O> getInstance(Transformer<? super I,? extends M> firstTransformer, Transformer<? super M,? extends O> secondTransformer)
ChainedTransformer
instance that chains
together the two specified Transformer
s.
firstTransformer
- The first Transformer
in the
chain.secondTransformer
- The second Transformer
in the
chain.
ChainedTransformer
instance that chains
together the two specified Transformer
s.
java.lang.IllegalArgumentException
- Thrown if either Transformer
is null
.public <T> ChainedTransformer<I,O,T> append(Transformer<? super O,T> transformer)
Transformer
to the end of the chain,
resulting in a new ChainedTransformer
that transforms an
input object through the existing Transformer
s in this
chain, and then transforms the result through the specified
Transformer
.
transformer
- The Transformer
to append to the chain.
ChainedTransformer
that transforms an input
object through the existing Transformer
s in this
chain, and then transforms the result through the specified
Transformer
.
java.lang.IllegalArgumentException
- Thrown if the specified Transformer
is null
.public <T> ChainedTransformer<T,I,O> prepend(Transformer<T,? extends I> transformer)
Transformer
to the start of the chain,
resulting in a new ChainedTransformer
that transforms an
input object through the specified Transformer
, and then
transforms the result through the existing Transformer
s in
this chain.
transformer
- The Transformer
to prepend to the chain.
ChainedTransformer
that transforms an input
object through the specified Transformer
, and then
transforms the result through the existing Transformer
s
in this chain.
java.lang.IllegalArgumentException
- Thrown if the specified Transformer
is null
.public O transform(I input)
Transformer
, and then transforming the result using the
second Transformer
, returning the resulting output object.
transform
in interface Transformer<I,O>
input
- The object to be transformed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |