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

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

public final class InverseTransformer<S,T>
extends ObjectProxy<TwoWayTransformer<T,S>>
implements TwoWayTransformer<S,T>

Exchanges the transform and retransform methods of the base transformer.


Constructor Summary
InverseTransformer(TwoWayTransformer<T,S> base)
          Constructs an InverseTransformer object.
 
Method Summary
 boolean isRetrievable(T input)
          Indicates if the origin of the specified object can be calculated.
 S retransform(T input)
          Calculates the transformation origin of the specified object.
 T transform(S input)
          Transforms the input object into some output object.
 
Methods inherited from class net.sf.molae.pipe.basic.ObjectProxy
assertNotNull, equals, getBase, hashCode, toString, toVerboseString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InverseTransformer

public InverseTransformer(TwoWayTransformer<T,S> base)
Constructs an InverseTransformer object.

Parameters:
base - the underlying transformer.
Throws:
NullPointerException - if any of the specified objects is null.
Method Detail

transform

public T transform(S input)
Transforms the input object into some output object. Calls retransform(Object) of the underlying transformer. If an exception occurred, null is returned.

Specified by:
transform in interface TwoWayTransformer<S,T>
Parameters:
input - the object to transform
Returns:
the transformation of the input object to the output object

retransform

public S retransform(T input)
Calculates the transformation origin of the specified object. This implementaion calls transform(Object) of the underlying transformer.

Specified by:
retransform in interface TwoWayTransformer<S,T>
Parameters:
input - the object for which the transformation origin is searched.
Returns:
the transformation origin of the specified object.
Throws:
IllegalArgumentException - if the retransformation condition transform(retransform(input)).equals(input) does not hold.

isRetrievable

public boolean isRetrievable(T input)
Indicates if the origin of the specified object can be calculated. This implementation checks that the retransformation condition transform(retransform(input)).equals(input) holds. As the retransformation of the base transformer must be injective on its definition set this implies that the result of the transformation of this transformer is unique and thereby the specified 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.