Package org.apache.commons.math3.util
Class TransformerMap
java.lang.Object
org.apache.commons.math3.util.TransformerMap
- All Implemented Interfaces:
Serializable
,NumberTransformer
This TansformerMap automates the transformation of mixed object types.
It provides a means to set NumberTransformers that will be selected
based on the Class of the object handed to the Maps
double transform(Object o)
method.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclasses()
Returns the Set of Classes used as keys in the map.void
clear()
Clears all the Class to Transformer mappings.boolean
containsClass
(Class<?> key) Tests if a Class is present in the TransformerMap.boolean
Tests if a NumberTransformer is present in the TransformerMap.boolean
getTransformer
(Class<?> key) Returns the Transformer that is mapped to a class if mapping is not present, this returns null.int
hashCode()
putTransformer
(Class<?> key, NumberTransformer transformer) Sets a Class to Transformer Mapping in the Map.removeTransformer
(Class<?> key) Removes a Class to Transformer Mapping in the Map.double
Attempts to transform the Object against the map of NumberTransformers.Returns the Set of NumberTransformers used as values in the map.
-
Constructor Details
-
TransformerMap
public TransformerMap()Build a map containing only the default transformer.
-
-
Method Details
-
containsClass
Tests if a Class is present in the TransformerMap.- Parameters:
key
- Class to check- Returns:
- true|false
-
containsTransformer
Tests if a NumberTransformer is present in the TransformerMap.- Parameters:
value
- NumberTransformer to check- Returns:
- true|false
-
getTransformer
Returns the Transformer that is mapped to a class if mapping is not present, this returns null.- Parameters:
key
- The Class of the object- Returns:
- the mapped NumberTransformer or null.
-
putTransformer
Sets a Class to Transformer Mapping in the Map. If the Class is already present, this overwrites that mapping.- Parameters:
key
- The Classtransformer
- The NumberTransformer- Returns:
- the replaced transformer if one is present
-
removeTransformer
Removes a Class to Transformer Mapping in the Map.- Parameters:
key
- The Class- Returns:
- the removed transformer if one is present or null if none was present.
-
clear
public void clear()Clears all the Class to Transformer mappings. -
classes
Returns the Set of Classes used as keys in the map.- Returns:
- Set of Classes
-
transformers
Returns the Set of NumberTransformers used as values in the map.- Returns:
- Set of NumberTransformers
-
transform
Attempts to transform the Object against the map of NumberTransformers. Otherwise it returns Double.NaN.- Specified by:
transform
in interfaceNumberTransformer
- Parameters:
o
- the Object to be transformed.- Returns:
- the double value of the Object.
- Throws:
MathIllegalArgumentException
- if the Object can not be transformed into a Double.- See Also:
-
equals
-
hashCode
public int hashCode()
-