java.lang.Object | +--org.apache.commons.collections.TransformerUtils
This class is not normally instantiated. |
static Transformer | asTransformer(Closure closure) Creates a Transformer that calls a Closure each time the transformer is used. |
static Transformer | asTransformer(Predicate predicate) Creates a Transformer that calls a Predicate each time the transformer is used. |
static Transformer | asTransformer(Factory factory) Creates a Transformer that calls a Factory each time the transformer is used. |
static Transformer | chainedTransformer(Transformer transformer1, Transformer transformer2) Create a new Transformer that calls two transformers, passing the result of the first into the second. |
static Transformer | chainedTransformer(Transformer transformers) Create a new Transformer that calls each transformer in turn, passing the result into the next transformer. |
static Transformer | chainedTransformer(Collection transformers) Create a new Transformer that calls each transformer in turn, passing the result into the next transformer. |
static Transformer | Gets a transformer that returns a clone of the input object. |
static Transformer | constantTransformer(Object constantToReturn) Creates a Transformer that will return the same object each time the transformer is used. |
static Transformer | Gets a transformer that always throws an exception. |
static Transformer | Gets a Transformer that expects an input Class object that it will instantiate. |
static Transformer | instantiateTransformer(Class[] paramTypes, Object[] args) Creates a Transformer that expects an input Class object that it will instantiate. |
static Transformer | invokerTransformer(String methodName) Gets a Transformer that invokes a method on the input object. |
static Transformer | invokerTransformer(String methodName, Class[] paramTypes, Object[] args) Gets a Transformer that invokes a method on the input object. |
static Transformer | mapTransformer(Map map) Creates a Transformer that uses the passed in Map to transform the input object (as a simple lookup). |
static Transformer | Gets a transformer that returns the input object. |
static Transformer | Gets a transformer that always returns null. |
static Transformer | Gets a transformer that returns a java.lang.String representation of the input object. |
static Transformer | switchMapTransformer(Map objectsAndTransformers) Create a new Transformer that uses the input object as a key to find the transformer to call. |
static Transformer | switchTransformer(Predicate predicate, Transformer trueTransformer, Transformer falseTransformer) Create a new Transformer that calls one of two transformers depending on the specified predicate. |
static Transformer | switchTransformer(Predicate predicates, Transformer transformers) Create a new Transformer that calls one of the transformers depending on the predicates. |
static Transformer | switchTransformer(Predicate predicates, Transformer transformers, Transformer defaultTransformer) Create a new Transformer that calls one of the transformers depending on the predicates. |
static Transformer | switchTransformer(Map predicatesAndTransformers) Create a new Transformer that calls one of the transformers depending on the predicates. |
public TransformerUtils()
public static Transformer asTransformer(Closure closure)
- if the closure is nullpublic static Transformer asTransformer(Factory factory)
- if the factory is nullpublic static Transformer asTransformer(Predicate predicate)
- if the predicate is nullpublic static Transformer chainedTransformer(Collection transformers)
- if the transformers collection is null
- if any transformer in the collection is nullpublic static Transformer chainedTransformer(Transformer transformer1, Transformer transformer2)
- if either transformer is nullpublic static Transformer chainedTransformer(Transformer transformers)
- if the transformers array is null
- if any transformer in the array is nullpublic static Transformer cloneTransformer()
public static Transformer constantTransformer(Object constantToReturn)
public static Transformer exceptionTransformer()
public static Transformer instantiateTransformer()
public static Transformer instantiateTransformer(Class[] paramTypes, Object[] args)
- if the paramTypes and args don't matchpublic static Transformer invokerTransformer(String methodName, Class[] paramTypes, Object[] args)
- if the method name is null
- if the paramTypes and args don't matchpublic static Transformer invokerTransformer(String methodName)
TransformerUtils.invokerTransformer("getName");
will call the getName/code> method on the input object to
determine the transformer result.
- if the methodName is null.public static Transformer mapTransformer(Map map)
- if the map is nullpublic static Transformer nopTransformer()
public static Transformer nullTransformer()
public static Transformer stringValueTransformer()
java.lang.String
representation of the input object. This is achieved via the
toString
method, null
returns 'null'.
public static Transformer switchMapTransformer(Map objectsAndTransformers)
- if the map is null
- if the map is empty
- if any transformer in the map is nullpublic static Transformer switchTransformer(Map predicatesAndTransformers)
- if the map is null
- if the map is empty
- if any transformer in the map is null
- if the map elements are of the wrong typepublic static Transformer switchTransformer(Predicate predicate, Transformer trueTransformer, Transformer falseTransformer)
- if the predicate is null
- if either transformer is nullpublic static Transformer switchTransformer(Predicate predicates, Transformer transformers, Transformer defaultTransformer)
- if the either array is null
- if the either array has 0 elements
- if any element in the arrays is null
- if the arrays are different sizespublic static Transformer switchTransformer(Predicate predicates, Transformer transformers)
- if the either array is null
- if the either array has 0 elements
- if any element in the arrays is null
- if the arrays are different sizes
TransformerUtils
provides reference implementations and utilities for the Transformer functor interface. The supplied transformers are:- Invoker - returns the result of a method call on the input object
- Clone - returns a clone of the input object
- Constant - always returns the same object
- Closure - performs a Closure and returns the input object
- Predicate - returns the result of the predicate as a Boolean
- Factory - returns a new object from a factory
- Chained - chains two or more transformers together
- Switch - calls one transformer based on one or more predicates
- SwitchMap - calls one transformer looked up from a Map
- Instantiate - the Class input object is instantiated
- Map - returns an object from a supplied Map
- Null - always returns null
- NOP - returns the input object, which should be immutable
- Exception - always throws an exception
- StringValue - returns a
All the supplied transformers are Serializable.java.lang.String
representation of the input object