org.apache.commons.collections.functors
Class ChainedTransformer<I,O>

java.lang.Object
  extended by org.apache.commons.collections.functors.ChainedTransformer<I,O>
All Implemented Interfaces:
Serializable, Transformer<I,O>

public class ChainedTransformer<I,O>
extends Object
implements Transformer<I,O>, Serializable

Transformer implementation that chains the specified transformers together.

The input object is passed to the first transformer. The transformed result is passed to the second transformer and so on.

Since:
Commons Collections 3.0
Version:
$Revision: 1.1.1.1 $ $Date: 2005/05/23 04:34:15 $
Author:
Matt Hall, John Watkinson, Stephen Colebourne
See Also:
Serialized Form

Constructor Summary
ChainedTransformer(Transformer[] transformers)
          Constructor that performs no validation.
 
Method Summary
static
<I,O> Transformer<I,O>
getInstance(Collection<Transformer> transformers)
          Create a new Transformer that calls each transformer in turn, passing the result into the next transformer.
static
<I,O> Transformer<I,O>
getInstance(Transformer[] transformers)
          Factory method that performs validation and copies the parameter array.
static
<I,M,O> Transformer<I,O>
getInstance(Transformer<I,? extends M> transformer1, Transformer<? super M,O> transformer2)
          Factory method that performs validation.
 Transformer[] getTransformers()
          Gets the transformers, do not modify the array.
 O transform(I object)
          Transforms the input to result via each decorated transformer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChainedTransformer

public ChainedTransformer(Transformer[] transformers)
Constructor that performs no validation. Use getInstance if you want that.

Parameters:
transformers - the transformers to chain, not copied, no nulls
Method Detail

getInstance

public static <I,O> Transformer<I,O> getInstance(Transformer[] transformers)
Factory method that performs validation and copies the parameter array.

Parameters:
transformers - the transformers to chain, copied, no nulls
Returns:
the chained transformer
Throws:
IllegalArgumentException - if the transformers array is null
IllegalArgumentException - if any transformer in the array is null

getInstance

public static <I,O> Transformer<I,O> getInstance(Collection<Transformer> transformers)
Create a new Transformer that calls each transformer in turn, passing the result into the next transformer. The ordering is that of the iterator() method on the collection.

Parameters:
transformers - a collection of transformers to chain
Returns:
the chained transformer
Throws:
IllegalArgumentException - if the transformers collection is null
IllegalArgumentException - if any transformer in the collection is null

getInstance

public static <I,M,O> Transformer<I,O> getInstance(Transformer<I,? extends M> transformer1,
                                                   Transformer<? super M,O> transformer2)
Factory method that performs validation.

Parameters:
transformer1 - the first transformer, not null
transformer2 - the second transformer, not null
Returns:
the chained transformer
Throws:
IllegalArgumentException - if either transformer is null

transform

public O transform(I object)
Transforms the input to result via each decorated transformer

Specified by:
transform in interface Transformer<I,O>
Parameters:
object - the input object passed to the first transformer
Returns:
the transformed result

getTransformers

public Transformer[] getTransformers()
Gets the transformers, do not modify the array.

Returns:
the transformers
Since:
Commons Collections 3.1


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.