TransformerUtils provides reference implementations and
utilities for the Transformer functor interface. The supplied transformers are:
java.lang.String representation of the input object
Since v4.1 only transformers which are considered to be safe are Serializable. Transformers considered to be unsafe for serialization are:
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static < the input/output type T> Transformer | Returns: the transformerthe closure to run each time in the transformer, not null closure)Creates a Transformer that calls a Closure each time the transformer is used. |
| public static < the input type T> Transformer | Returns: the transformerthe predicate to run each time in the transformer, not null predicate)Creates a Transformer that calls a Predicate each time the transformer is used. |
| public static < the input type I, the output type O> Transformer | Returns: the transformerthe factory to run each time in the transformer, not null factory)Creates a Transformer that calls a Factory each time the transformer is used. |
| public static < the input/output type T> Transformer | Returns: the transformeran array of transformers to chain transformers)Create a new Transformer that calls each transformer in turn, passing the result into the next transformer. |
| public static < the input/output type T> Transformer | Returns: the transformera collection of transformers to chain transformers)Create a new Transformer that calls each transformer in turn, passing the result into the next transformer. |
| public static < the input/output type T> Transformer | Returns: the transformerGets a transformer that returns a clone of the input object. |
| public static < the input type I, the output type O> Transformer | Returns: the transformer.the constant object to return each time in the transformer constantToReturn)Creates a Transformer that will return the same object each time the transformer is used. |
| public static < the input type I, the output type O> Transformer | |
| public static < the input / output type T> Transformer | Returns: the transformerthe predicate to switch on predicate, final Transformer<? super T, ? extends T> the transformer called if the predicate is true trueTransformer)Create a new Transformer that calls the transformer if the predicate is true, otherwise the input object is returned unchanged. |
| public static < the input type I, the output type O> Transformer | Returns: the transformerthe predicate to switch on predicate, final Transformer<? super I, ? extends O> the transformer called if the predicate is true trueTransformer, final Transformer<? super I, ? extends O> the transformer called if the predicate is false falseTransformer)Create a new Transformer that calls one of two transformers depending on the specified predicate. |
| public static < the output type T> Transformer | Returns: the transformerGets a Transformer that expects an input Class object that it will instantiate. |
| public static < the output type T> Transformer | Returns: the transformerparameter types for the constructor, can be null paramTypes, final Object[] the arguments to pass to the constructor, can be null args)Creates a Transformer that expects an input Class object that it will instantiate. |
| public static < the input type I, the output type O> Transformer | Returns: the transformerthe method name to call on the input object, may not be null methodName)Gets a Transformer that invokes a method on the input object. |
| public static < the input type I, the output type O> Transformer | Returns: the transformerthe name of the method methodName, final Class<?>[] the parameter types paramTypes, final Object[] the arguments args)Gets a Transformer that invokes a method on the input object. |
| public static < the input type I, the output type O> Transformer | mapTransformer(final Map<? super I, ? extends O>
the map to use to transform the objects map)Creates a Transformer that uses the passed in Map to transform the input object (as a simple lookup). |
| public static < the input/output type T> Transformer | |
| public static < the input type I, the output type O> Transformer | |
| public static < the input type T> Transformer | Returns: the transformerGets a transformer that returns a |
| public static < the input type I, the output type O> Transformer | Returns: the transformera map of objects to transformers objectsAndTransformers)Create a new Transformer that uses the input object as a key to find the transformer to call. |
| public static < the input type I, the output type O> Transformer | Returns: the transformerthe predicate to switch on predicate, final Transformer<? super I, ? extends O> the transformer called if the predicate is true trueTransformer, final Transformer<? super I, ? extends O> the transformer called if the predicate is false falseTransformer)
Deprecated
as of 4.1, use
Create a new Transformer that calls one of two transformers depending
on the specified predicate.
ifTransformer(Predicate, Transformer, Transformer)
|
| public static < the input type I, the output type O> Transformer | Returns: the transformeran array of predicates to check predicates, final Transformer<? super I, ? extends O>[] an array of transformers to call transformers)Create a new Transformer that calls one of the transformers depending on the predicates. |
| public static < the input type I, the output type O> Transformer | Returns: the transformeran array of predicates to check predicates, final Transformer<? super I, ? extends O>[] an array of transformers to call transformers, final Transformer<? super I, ? extends O> the default to call if no predicate matches, null means return null defaultTransformer)Create a new Transformer that calls one of the transformers depending on the predicates. |
| public static < the input type I, the output type O> Transformer | Returns: the transformera map of predicates to transformers predicatesAndTransformers)Create a new Transformer that calls one of the transformers depending on the predicates. |
| TransformerUtils | back to summary |
|---|---|
| private TransformerUtils() This class is not normally instantiated. | |
| asTransformer | back to summary |
|---|---|
| public static <T> Transformer Creates a Transformer that calls a Closure each time the transformer is used. The transformer returns the input object.
| |
| asTransformer | back to summary |
|---|---|
| public static <T> Transformer Creates a Transformer that calls a Predicate each time the transformer is used. The transformer will return either Boolean.TRUE or Boolean.FALSE.
| |
| asTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Creates a Transformer that calls a Factory each time the transformer is used. The transformer will return the value returned by the factory.
| |
| chainedTransformer | back to summary |
|---|---|
| public static <T> Transformer Create a new Transformer that calls each transformer in turn, passing the result into the next transformer.
| |
| chainedTransformer | back to summary |
|---|---|
| public static <T> Transformer 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.
| |
| cloneTransformer | back to summary |
|---|---|
| public static <T> Transformer Gets a transformer that returns a clone of the input object. The input object will be cloned using one of these techniques (in order):
| |
| constantTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Creates a Transformer that will return the same object each time the transformer is used.
| |
| exceptionTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Gets a transformer that always throws an exception. This could be useful during testing as a placeholder.
| |
| ifTransformer | back to summary |
|---|---|
| public static <T> Transformer Create a new Transformer that calls the transformer if the predicate is true, otherwise the input object is returned unchanged.
| |
| ifTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Create a new Transformer that calls one of two transformers depending on the specified predicate.
| |
| instantiateTransformer | back to summary |
|---|---|
| public static <T> Transformer Gets a Transformer that expects an input Class object that it will instantiate.
| |
| instantiateTransformer | back to summary |
|---|---|
| public static <T> Transformer Creates a Transformer that expects an input Class object that it will instantiate. The constructor used is determined by the arguments specified to this method.
| |
| invokerTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Gets a Transformer that invokes a method on the input object.
The method must have no parameters. If the input object is
For example,
| |
| invokerTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Gets a Transformer that invokes a method on the input object.
The method parameters are specified. If the input object is
| |
| mapTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Creates a Transformer that uses the passed in Map to transform the input object (as a simple lookup).
| |
| nopTransformer | back to summary |
|---|---|
| public static <T> Transformer Gets a transformer that returns the input object. The input object should be immutable to maintain the contract of Transformer (although this is not checked).
| |
| nullTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Gets a transformer that always returns null.
| |
| stringValueTransformer | back to summary |
|---|---|
| public static <T> Transformer Gets a transformer that returns a
| |
| switchMapTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Create a new Transformer that uses the input object as a key to find the transformer to call. The Map consists of object keys and Transformer values. A transformer is called if the input object equals the key. If there is no match, the default transformer is called. The default transformer is set in the map using a null key. If no default is set, null will be returned in a default case.
| |
| switchTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Deprecated as of 4.1, use Create a new Transformer that calls one of two transformers depending on the specified predicate.
| |
| switchTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Create a new Transformer that calls one of the transformers depending on the predicates. The transformer at array location 0 is called if the predicate at array location 0 returned true. Each predicate is evaluated until one returns true. If no predicates evaluate to true, null is returned.
| |
| switchTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Create a new Transformer that calls one of the transformers depending on the predicates. The transformer at array location 0 is called if the predicate at array location 0 returned true. Each predicate is evaluated until one returns true. If no predicates evaluate to true, the default transformer is called. If the default transformer is null, null is returned.
| |
| switchTransformer | back to summary |
|---|---|
| public static <I, O> Transformer Create a new Transformer that calls one of the transformers depending on the predicates. The Map consists of Predicate keys and Transformer values. A transformer is called if its matching predicate returns true. Each predicate is evaluated until one returns true. If no predicates evaluate to true, the default transformer is called. The default transformer is set in the map with a null key. If no default transformer is set, null will be returned in a default case. The ordering is that of the iterator() method on the entryset collection of the map.
| |