## org.apache.commons.math.util
Class TransformerMap

    java.lang.Object
      org.apache.commons.math.util.TransformerMap

All Implemented Interfaces:
  java.io.Serializable, NumberTransformer

    public class TransformerMap

extends java.lang.Object
implements NumberTransformer, java.io.Serializable

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.

Version:
  $Revision: 922713 $ $Date: 2010-03-13 20:26:13 -0500 (Sat, 13 Mar 2010) $
See Also:
  Serialized Form

Field Summary
`private NumberTransformer` `defaultTransformer` A default Number Transformer for Numbers and numeric Strings.
`private java.util.Map<java.lang.Class<?>,NumberTransformer>` `map` The internal Map.
`private static long` `serialVersionUID` Serializable version identifier

Constructor Summary
`TransformerMap()` Build a map containing only the default transformer.

Method Summary
`java.util.Set<java.lang.Class<?>>` `classes()` Returns the Set of Classes used as keys in the map.
`void` `clear()` Clears all the Class to Transformer mappings.
`boolean` `containsClass(java.lang.Class<?> key)` Tests if a Class is present in the TransformerMap.
`boolean` `containsTransformer(NumberTransformer value)` Tests if a NumberTransformer is present in the TransformerMap.
`boolean` `equals(java.lang.Object other)`
`NumberTransformer` `getTransformer(java.lang.Class<?> key)` Returns the Transformer that is mapped to a class if mapping is not present, this returns null.
`int` `hashCode()`
`NumberTransformer` `putTransformer(java.lang.Class<?> key, NumberTransformer transformer)` Sets a Class to Transformer Mapping in the Map.
`NumberTransformer` `removeTransformer(java.lang.Class<?> key)` Removes a Class to Transformer Mapping in the Map.
`double` `transform(java.lang.Object o)` Attempts to transform the Object against the map of NumberTransformers.
`java.util.Collection<NumberTransformer>` `transformers()` Returns the Set of NumberTransformers used as values in the map.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### serialVersionUID

    private static final long serialVersionUID

  Serializable version identifier

  See Also:
    Constant Field Values

### defaultTransformer

    private NumberTransformer defaultTransformer

  A default Number Transformer for Numbers and numeric Strings.

### map

    private java.util.Map<java.lang.Class<?>,NumberTransformer> map

  The internal Map.

Constructor Detail

### TransformerMap

    public TransformerMap()

  Build a map containing only the default transformer.

Method Detail

### containsClass

    public boolean containsClass(java.lang.Class<?> key)

  Tests if a Class is present in the TransformerMap.

  Parameters:
    `key` - Class to check
  Returns:
    true|false

### containsTransformer

    public boolean containsTransformer(NumberTransformer value)

  Tests if a NumberTransformer is present in the TransformerMap.

  Parameters:
    `value` - NumberTransformer to check
  Returns:
    true|false

### getTransformer

    public NumberTransformer getTransformer(java.lang.Class<?> key)

  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

    public NumberTransformer putTransformer(java.lang.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` - The Class
    `transformer` - The NumberTransformer
  Returns:
    the replaced transformer if one is present

### removeTransformer

    public NumberTransformer removeTransformer(java.lang.Class<?> key)

  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

    public java.util.Set<java.lang.Class<?>> classes()

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

  Returns:
    Set of Classes

### transformers

    public java.util.Collection<NumberTransformer> transformers()

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

  Returns:
    Set of NumberTransformers

### transform

    public double transform(java.lang.Object o)
                     throws MathException

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

  Specified by:
    `transform` in interface `NumberTransformer`
  Parameters:
    `o` - the Object to be transformed.
  Returns:
    the double value of the Object.
  Throws:
    `MathException` - if the Object can not be transformed into a Double.
  See Also:
    `NumberTransformer.transform(java.lang.Object)`

### equals

    public boolean equals(java.lang.Object other)

  Overrides:
    `equals` in class `java.lang.Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `java.lang.Object`

Copyright (c) 2003-2011 Apache Software Foundation