net.sf.molae.pipe.trafo
Class CachedTransformer

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

public class CachedTransformer
extends Object
implements TwoWayTransformer

A cached transformer. All transformation results are stored in a cache and used the next time the transformation is called with an equal input parameter.

Since:
1.1

Constructor Summary
CachedTransformer(Map cache, Map inverted, TwoWayTransformer base)
          Constructs a CachedTransformer on the base of the specified parameters.
CachedTransformer(TwoWayTransformer base)
          Constructs an empty CachedTransformer.
 
Method Summary
 Map getCache()
          Returns the cache.
 Map getInverted()
          Returns the retransformation cache.
 boolean isReadOnly()
          Returns true if this object is marked as read only.
 boolean isRetrievable(Object input)
          Indicates if the origin of the specified object can be calculated.
 Object retransform(Object input)
          Calculates the transformation origin of the specified object.
 void setReadOnly()
          Marks this CachedTransformer object as "read only".
 Object transform(Object input)
          Returns the value to which the base map maps the specified key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedTransformer

public CachedTransformer(Map cache,
                         Map inverted,
                         TwoWayTransformer base)
Constructs a CachedTransformer on the base of the specified parameters.
Parameters:
cache - Initial values of the cache.
inverted - Initial values of the retransformation cache.
base - the default transformer.

CachedTransformer

public CachedTransformer(TwoWayTransformer base)
Constructs an empty CachedTransformer.
Parameters:
base - the default transformer.
Method Detail

getCache

public Map getCache()
Returns the cache.
Returns:
the cache.

getInverted

public Map getInverted()
Returns the retransformation cache.
Returns:
the retransformation cache.

setReadOnly

public void setReadOnly()
Marks this CachedTransformer object as "read only". If this transformer is "read only" only the cache is used, but not the transformer.
See Also:
isReadOnly()

isReadOnly

public boolean isReadOnly()
Returns true if this object is marked as read only. By default, the object is not read only. It can be set to read only by a call to setReadOnly().
Returns:
true if this object is marked as readonly, false otherwise.

transform

public Object transform(Object input)
Returns the value to which the base map maps the specified key. If no value exists in the base map and this object is not read only, a new entry is created and stored in the base map.
Specified by:
transform in interface Transformer
Parameters:
input - key whose associated value is to be returned
Returns:
the value to which the base map maps the specified key.

retransform

public Object retransform(Object input)
Calculates the transformation origin of the specified object.
Specified by:
retransform in interface TwoWayTransformer
Parameters:
input - the object for which the transformation origin is searched.
Returns:
the transformation origin of the specified object.
Throws:
IllegalArgumentException - depending on the base transformer.
ClassCastException - depending on the base transformer.
UnsupportedOperationException - depending on the base transformer.

isRetrievable

public boolean isRetrievable(Object input)
Description copied from interface: TwoWayTransformer
Indicates if the origin of the specified object can be calculated. This requires that:
  1. retransform is implemented for this object and does not throw an exception.
  2. The object x returned by retransform is unique, or more formally: transform(o1).equals(transform(o2)) &rArr o1.equals(o2)
This implies that
 retransform(transform(input)).equals(input)
 
for all objects where the retransformation is defined.
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.