public class SwitchTransformer<I,O> extends Objectimplements Transformer <I ,O>, Serializable
| Constructor and Description |
|---|
SwitchTransformer(Predicate
Constructor that performs no validation.
|
| Modifier and Type | Method and Description |
|---|---|
Transformer |
getDefaultTransformer()
Gets the default transformer.
|
Predicate |
getPredicates()
Gets the predicates.
|
Transformer |
getTransformers()
Gets the transformers.
|
static <I |
switchTransformer(Map
Create a new Transformer that calls one of the transformers depending on the predicates.
|
static <I |
switchTransformer(Predicate
Factory method that performs validation and copies the parameter arrays.
|
O |
transform(I input)
Transforms the input to result by calling the transformer whose matching predicate returns true.
|
public SwitchTransformer(Predicate<? super I>[] predicates, Transformer <? super I ,? extends O>[] transformers, Transformer <? super I ,? extends O> defaultTransformer)
switchTransformer if you want that.
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
public static <I,O> Transformer <I ,O> switchTransformer(Predicate <? super I>[] predicates, Transformer <? super I ,? extends O>[] transformers, Transformer <? super I ,? extends O> defaultTransformer)
I - the input type
O - the output type
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
chained transformer
NullPointerException - if array is null
NullPointerException - if any element in the array is null
public static <I,O> Transformer <I ,O> switchTransformer(Map <? extends Predicate <? super I> ,? extends Transformer <? super I ,? extends O>> map)
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.
I - the input type
O - the output type
map - a map of predicates to transformers
switch transformer
NullPointerException - if the map is null
NullPointerException - if any transformer in the map is null
ClassCastException - if the map elements are of the wrong type
public 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()