|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.collections.functors.SwitchTransformer
public class SwitchTransformer
Transformer implementation calls the transformer whose predicate returns true, like a switch statement.
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(java.util.Map predicatesAndTransformers)
Create a new Transformer that calls one of the transformers depending on the predicates. |
static Transformer |
getInstance(Predicate[] predicates,
Transformer[] transformers,
Transformer defaultTransformer)
Factory method that performs validation and copies the parameter arrays. |
Predicate[] |
getPredicates()
Gets the predicates, do not modify the array. |
Transformer[] |
getTransformers()
Gets the transformers, do not modify the array. |
java.lang.Object |
transform(java.lang.Object input)
Transforms the input to result by calling the transformer whose matching predicate returns true. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SwitchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer)
getInstance
if you want that.
predicates
- array of predicates, not cloned, no nullstransformers
- matching array of transformers, not cloned, no nullsdefaultTransformer
- the transformer to use if no match, null means return nullMethod Detail |
---|
public static Transformer getInstance(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer)
predicates
- array of predicates, cloned, no nullstransformers
- matching array of transformers, cloned, no nullsdefaultTransformer
- the transformer to use if no match, null means return null
chained
transformer
java.lang.IllegalArgumentException
- if array is null
java.lang.IllegalArgumentException
- if any element in the array is nullpublic static Transformer getInstance(java.util.Map predicatesAndTransformers)
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.
predicatesAndTransformers
- a map of predicates to transformers
switch
transformer
java.lang.IllegalArgumentException
- if the map is null
java.lang.IllegalArgumentException
- if any transformer in the map is null
java.lang.ClassCastException
- if the map elements are of the wrong typepublic java.lang.Object transform(java.lang.Object input)
transform
in interface Transformer
input
- the input object to transform
public Predicate[] getPredicates()
public Transformer[] getTransformers()
public Transformer getDefaultTransformer()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |