public class SwitchTransformer<I,O> extends Object implements Transformer<I,O>, Serializable
Constructor and Description |
---|
SwitchTransformer(Predicate<? super I>[] predicates,
Transformer<? super I,? extends O>[] transformers,
Transformer<? super I,? extends O> defaultTransformer)
Constructor that performs no validation.
|
Modifier and Type | Method and Description |
---|---|
Transformer<? super I,? extends O> |
getDefaultTransformer()
Gets the default transformer.
|
Predicate<? super I>[] |
getPredicates()
Gets the predicates.
|
Transformer<? super I,? extends O>[] |
getTransformers()
Gets the transformers.
|
static <I,O> Transformer<I,O> |
switchTransformer(Map<? extends Predicate<? super I>,? extends Transformer<? super I,? extends O>> map)
Create a new Transformer that calls one of the transformers depending
on the predicates.
|
static <I,O> Transformer<I,O> |
switchTransformer(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.
|
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 nullstransformers
- matching array of transformers, cloned, no nullsdefaultTransformer
- the transformer to use if no match, null means return nullpublic 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 typeO
- the output typepredicates
- array of predicates, cloned, no nullstransformers
- matching array of transformers, cloned, no nullsdefaultTransformer
- the transformer to use if no match, null means return nullchained
transformerNullPointerException
- if array is nullNullPointerException
- if any element in the array is nullpublic 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 typeO
- the output typemap
- a map of predicates to transformersswitch
transformerNullPointerException
- if the map is nullNullPointerException
- if any transformer in the map is nullClassCastException
- if the map elements are of the wrong typepublic O transform(I input)
transform
in interface Transformer<I,O>
input
- the input object to transformpublic Predicate<? super I>[] getPredicates()
public Transformer<? super I,? extends O>[] getTransformers()
public Transformer<? super I,? extends O> getDefaultTransformer()
Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.