net.sf.molae.pipe.trafo
Class MapAsTransformer

java.lang.Object
  |
  +--net.sf.molae.pipe.trafo.MapAsTransformer
All Implemented Interfaces:
Transformer, TwoWayTransformer

public final class MapAsTransformer
extends Object
implements TwoWayTransformer

Implements a transformer on the basis of a Map. The transformation is defined for each element of the key set of the map. The result of the transformation is the associated value of the key in the map. The retransformation is defined for each element of the value set of the map. The result of the retransformation is the associated key of the value in the map.


Constructor Summary
MapAsTransformer(Map base)
          Constructs a MapAsTransformer object.
 
Method Summary
 boolean isRetrievable(Object input)
          Indicates if this transformer is injective.
 Object retransform(Object input)
          Returns a key of the base map that has the specified value.
 String toString()
          Returns a string representation of the object.
 Object transform(Object input)
          Returns the value of the specified key in the base map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MapAsTransformer

public MapAsTransformer(Map base)
Constructs a MapAsTransformer object.
Parameters:
base - the underlying map
Throws:
NullPointerException - if any of the specified objects is null.
Method Detail

toString

public String toString()
Returns a string representation of the object.
Overrides:
toString in class Object
Returns:
a string representation of the object.

transform

public Object transform(Object input)
Returns the value of the specified key in the base map. If an exception occurred, null is returned.
Specified by:
transform in interface Transformer
Parameters:
input - the object to transform
Returns:
the value of the specified key in the base map

retransform

public Object retransform(Object input)
Returns a key of the base map that has the specified value.
Specified by:
retransform in interface TwoWayTransformer
Parameters:
input - the object for which the transformation origin is searched.
Returns:
a key of the base map that has the specified value

isRetrievable

public boolean isRetrievable(Object input)
Indicates if this transformer is injective. Returns false because the underlying map can change and it cannot be guaranteed that the object is retrievable.
Specified by:
isRetrievable in interface TwoWayTransformer
Following copied from interface: net.sf.molae.pipe.trafo.TwoWayTransformer
Parameters:
input - the object for which the transformation origin is searched.
Returns:
true if the origin of the specified object can be calculated.