Top Description Fields Constructors Methods
org.apache.commons.math3.util

public Class TransformerMap

extends Object
implements NumberTransformer, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.util.NumberTransformer
Imports
java.io.Serializable, java.util.Collection, .HashMap, .Map, .Set, org.apache.commons.math3.exception.MathIllegalArgumentException

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.

Field Summary

Modifier and TypeField and Description
private NumberTransformer
defaultTransformer

A default Number Transformer for Numbers and numeric Strings.

private Map<Class<?>, NumberTransformer>
map

The internal Map.

private static final long
serialVersionUID

Serializable version identifier

Constructor Summary

AccessConstructor and Description
public
TransformerMap()

Build a map containing only the default transformer.

Method Summary

Modifier and TypeMethod and Description
public Set<Class<?>>

Returns:

Set of Classes
classes
()

Returns the Set of Classes used as keys in the map.

public void
clear()

Clears all the Class to Transformer mappings.

public boolean

Returns:

true|false
containsClass
(Class<?>
Class to check
key
)

Tests if a Class is present in the TransformerMap.

public boolean

Returns:

true|false
containsTransformer
(NumberTransformer
NumberTransformer to check
value
)

Tests if a NumberTransformer is present in the TransformerMap.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public NumberTransformer

Returns:

the mapped NumberTransformer or null.
getTransformer
(Class<?>
The Class of the object
key
)

Returns the Transformer that is mapped to a class if mapping is not present, this returns null.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public NumberTransformer

Returns:

the replaced transformer if one is present
putTransformer
(Class<?>
The Class
key
,
NumberTransformer
The NumberTransformer
transformer
)

Sets a Class to Transformer Mapping in the Map.

public NumberTransformer

Returns:

the removed transformer if one is present or null if none was present.
removeTransformer
(Class<?>
The Class
key
)

Removes a Class to Transformer Mapping in the Map.

public double

Returns:

the double value of the Object.
transform
(Object
the Object to be transformed.
o
)

Implements org.apache.commons.math3.util.NumberTransformer.transform.

Attempts to transform the Object against the map of NumberTransformers.

public Collection<NumberTransformer>

Returns:

Set of NumberTransformers
transformers
()

Returns the Set of NumberTransformers used as values in the map.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultTransformerback to summary
private NumberTransformer defaultTransformer

A default Number Transformer for Numbers and numeric Strings.

mapback to summary
private Map<Class<?>, NumberTransformer> map

The internal Map.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

Constructor Detail

TransformerMapback to summary
public TransformerMap()

Build a map containing only the default transformer.

Method Detail

classesback to summary
public Set<Class<?>> classes()

Returns the Set of Classes used as keys in the map.

Returns:Set<Class<?>>

Set of Classes

clearback to summary
public void clear()

Clears all the Class to Transformer mappings.

containsClassback to summary
public boolean containsClass(Class<?> key)

Tests if a Class is present in the TransformerMap.

Parameters
key:Class<?>

Class to check

Returns:boolean

true|false

containsTransformerback to summary
public boolean containsTransformer(NumberTransformer value)

Tests if a NumberTransformer is present in the TransformerMap.

Parameters
value:NumberTransformer

NumberTransformer to check

Returns:boolean

true|false

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getTransformerback to summary
public NumberTransformer getTransformer(Class<?> key)

Returns the Transformer that is mapped to a class if mapping is not present, this returns null.

Parameters
key:Class<?>

The Class of the object

Returns:NumberTransformer

the mapped NumberTransformer or null.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
putTransformerback to summary
public NumberTransformer putTransformer(Class<?> key, NumberTransformer transformer)

Sets a Class to Transformer Mapping in the Map. If the Class is already present, this overwrites that mapping.

Parameters
key:Class<?>

The Class

transformer:NumberTransformer

The NumberTransformer

Returns:NumberTransformer

the replaced transformer if one is present

removeTransformerback to summary
public NumberTransformer removeTransformer(Class<?> key)

Removes a Class to Transformer Mapping in the Map.

Parameters
key:Class<?>

The Class

Returns:NumberTransformer

the removed transformer if one is present or null if none was present.

transformback to summary
public double transform(Object o) throws MathIllegalArgumentException

Implements org.apache.commons.math3.util.NumberTransformer.transform.

Attempts to transform the Object against the map of NumberTransformers. Otherwise it returns Double.NaN.

Parameters
o:Object

the Object to be transformed.

Returns:double

the double value of the Object.

Exceptions
MathIllegalArgumentException:
if the Object can not be transformed into a Double.
See Also
org.apache.commons.math3.util.NumberTransformer#transform(java.lang.Object)
transformersback to summary
public Collection<NumberTransformer> transformers()

Returns the Set of NumberTransformers used as values in the map.

Returns:Collection<NumberTransformer>

Set of NumberTransformers