net.sf.molae.pipe.trafo
Class MapAsTransformer<S,T>

java.lang.Object
  extended by net.sf.molae.pipe.trafo.MapAsTransformer<S,T>
All Implemented Interfaces:
TwoWayTransformer<S,T>

public final class MapAsTransformer<S,T>
extends Object
implements TwoWayTransformer<S,T>

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<S,T> base)
          Constructs a MapAsTransformer object.
 
Method Summary
 boolean isRetrievable(T input)
          Indicates if this transformer is injective.
 S retransform(T input)
          Returns a key of the base map that has the specified value.
 String toString()
          Returns a string representation of the object.
 T transform(S 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<S,T> 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 T transform(S input)
Returns the value of the specified key in the base map. If an exception occurred, null is returned.

Specified by:
transform in interface TwoWayTransformer<S,T>
Parameters:
input - the object to transform
Returns:
the value of the specified key in the base map

retransform

public S retransform(T input)
Returns a key of the base map that has the specified value.

Specified by:
retransform in interface TwoWayTransformer<S,T>
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(T 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<S,T>
Parameters:
input - the object for which the transformation origin is searched.
Returns:
true if the origin of the specified object can be calculated.