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