Class SwitchTransformer
java.lang.Object
org.apache.commons.collections.functors.SwitchTransformer
- All Implemented Interfaces:
Serializable,Transformer
@Deprecated(since="2021-04-30")
public class SwitchTransformer
extends Object
implements Transformer, Serializable
Deprecated.
Apache Commons Collections version 3.x is being deprecated from AEMaaCS. The upgraded version 4.4 of Commons Collections is already included as replacement. Customers are advised to upgrade to this version of the library. Please note: the package name was changed to org.apache.commons.collections4. Further note that there are AEM APIs currently exposing the old collections classes; these will be updated in upcoming releases.
Transformer implementation calls the transformer whose predicate returns true,
like a switch statement.
- Since:
- Commons Collections 3.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSwitchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) Deprecated.Constructor that performs no validation. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Gets the default transformer.static TransformergetInstance(Map predicatesAndTransformers) Deprecated.Create a new Transformer that calls one of the transformers depending on the predicates.static TransformergetInstance(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) Deprecated.Factory method that performs validation and copies the parameter arrays.Deprecated.Gets the predicates, do not modify the array.Deprecated.Gets the transformers, do not modify the array.Deprecated.Transforms the input to result by calling the transformer whose matching predicate returns true.
-
Constructor Details
-
SwitchTransformer
public SwitchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) Deprecated.Constructor that performs no validation. UsegetInstanceif you want that.- Parameters:
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 null
-
-
Method Details
-
getInstance
public static Transformer getInstance(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) Deprecated.Factory method that performs validation and copies the parameter arrays.- Parameters:
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- Returns:
- the
chainedtransformer - Throws:
IllegalArgumentException- if array is nullIllegalArgumentException- if any element in the array is null
-
getInstance
Deprecated.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- Returns:
- the
switchtransformer - Throws:
IllegalArgumentException- if the map is nullIllegalArgumentException- if any transformer in the map is nullClassCastException- if the map elements are of the wrong type
-
transform
Deprecated.Transforms the input to result by calling the transformer whose matching predicate returns true.- Specified by:
transformin interfaceTransformer- Parameters:
input- the input object to transform- Returns:
- the transformed result
-
getPredicates
Deprecated.Gets the predicates, do not modify the array.- Returns:
- the predicates
- Since:
- Commons Collections 3.1
-
getTransformers
Deprecated.Gets the transformers, do not modify the array.- Returns:
- the transformers
- Since:
- Commons Collections 3.1
-
getDefaultTransformer
Deprecated.Gets the default transformer.- Returns:
- the default transformer
- Since:
- Commons Collections 3.1
-