org.apache.commons.collections.functors
public class SwitchTransformer extends Object implements Transformer, Serializable
Since: Commons Collections 3.0
Version: $Revision: 393105 $ $Date: 2006-04-10 23:23:11 +0100 (Mon, 10 Apr 2006) $
Constructor Summary | |
---|---|
SwitchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer)
Constructor that performs no validation.
|
Method Summary | |
---|---|
Transformer | getDefaultTransformer()
Gets the default transformer.
|
static Transformer | getInstance(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer)
Factory method that performs validation and copies the parameter arrays.
|
static Transformer | getInstance(Map predicatesAndTransformers)
Create a new Transformer that calls one of the transformers depending
on the predicates.
|
Predicate[] | getPredicates()
Gets the predicates, do not modify the array.
|
Transformer[] | getTransformers()
Gets the transformers, do not modify the array.
|
Object | transform(Object input)
Transforms the input to result by calling the transformer whose matching
predicate returns true.
|
getInstance
if you want that.
Parameters: predicates array of predicates, not cloned, no nulls transformers matching array of transformers, not cloned, no nulls defaultTransformer the transformer to use if no match, null means return null
Returns: the default transformer
Since: Commons Collections 3.1
Parameters: predicates array of predicates, cloned, no nulls transformers matching array of transformers, cloned, no nulls defaultTransformer the transformer to use if no match, null means return null
Returns: the chained
transformer
Throws: IllegalArgumentException if array is null IllegalArgumentException if any element in the array is null
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. The ordering is that of the iterator() method on the entryset collection of the map.
Parameters: predicatesAndTransformers a map of predicates to transformers
Returns: the switch
transformer
Throws: IllegalArgumentException if the map is null IllegalArgumentException if any transformer in the map is null ClassCastException if the map elements are of the wrong type
Returns: the predicates
Since: Commons Collections 3.1
Returns: the transformers
Since: Commons Collections 3.1
Parameters: input the input object to transform
Returns: the transformed result