|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.collections.functors.SwitchTransformer<I,O>
public class SwitchTransformer<I,O>
Transformer implementation calls the transformer whose predicate returns true, like a switch statement.
Constructor Summary | |
---|---|
SwitchTransformer(Predicate<? super I>[] predicates,
Transformer<? super I,? extends O>[] transformers,
Transformer<? super I,? extends O> defaultTransformer)
Constructor that performs no validation. |
Method Summary | ||
---|---|---|
Transformer<? super I,? extends O> |
getDefaultTransformer()
Gets the default transformer. |
|
static
|
getInstance(Map<Predicate<? super I>,Transformer<? super I,? extends O>> predicatesAndTransformers)
Create a new Transformer that calls one of the transformers depending on the predicates. |
|
static
|
getInstance(Predicate<? super I>[] predicates,
Transformer<? super I,? extends O>[] transformers,
Transformer<? super I,? extends O> defaultTransformer)
Factory method that performs validation and copies the parameter arrays. |
|
Predicate<? super I>[] |
getPredicates()
Gets the predicates, do not modify the array. |
|
Transformer<? super I,? extends O>[] |
getTransformers()
Gets the transformers, do not modify the array. |
|
O |
transform(I 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<? super I>[] predicates, Transformer<? super I,? extends O>[] transformers, Transformer<? super I,? extends O> 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 nopMethod Detail |
---|
public static <I,O> Transformer<I,O> getInstance(Predicate<? super I>[] predicates, Transformer<? super I,? extends O>[] transformers, Transformer<? super I,? extends O> defaultTransformer)
predicates
- array of predicates, cloned, no nullstransformers
- matching array of transformers, cloned, no nullsdefaultTransformer
- the transformer to use if no match, null means nop
chained
transformer
IllegalArgumentException
- if array is null
IllegalArgumentException
- if any element in the array is nullpublic static <I,O> Transformer<I,O> getInstance(Map<Predicate<? super I>,Transformer<? super I,? extends O>> 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
IllegalArgumentException
- if the map is null
IllegalArgumentException
- if any transformer in the map is null
ClassCastException
- if the map elements are of the wrong typepublic O transform(I input)
transform
in interface Transformer<I,O>
input
- the input object to transform
public Predicate<? super I>[] getPredicates()
public Transformer<? super I,? extends O>[] getTransformers()
public Transformer<? super I,? extends O> getDefaultTransformer()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |