net.sf.molae.pipe.text
Class FormatTransformer

java.lang.Object
  extended by net.sf.molae.pipe.text.FormatTransformer
All Implemented Interfaces:
TwoWayTransformer<Object,String>

public final class FormatTransformer
extends Object
implements TwoWayTransformer<Object,String>

A text format as a transformer.


Constructor Summary
FormatTransformer(Format base)
          Creates a new FormatTransformer based on the specified format.
FormatTransformer(Format base, boolean injective)
          Creates a new FormatTransformer based on the specified format.
 
Method Summary
 boolean isRetrievable(String input)
          Returns the value specified in the constructor.
 Object retransform(String input)
          Calls parseObject(String) of the underlying format.
 String toString()
          Returns a string representation of the object.
 String transform(Object input)
          Calls format(Object) of the underlying format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FormatTransformer

public FormatTransformer(Format base,
                         boolean injective)
Creates a new FormatTransformer based on the specified format.

Parameters:
base - the base format
injective - indicates if this transformer is injective for all objects except null
Throws:
NullPointerException - base is null.

FormatTransformer

public FormatTransformer(Format base)
Creates a new FormatTransformer based on the specified format. It is assumed that the transformation is injective.

Parameters:
base - the base format
Throws:
NullPointerException - base 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 String transform(Object input)
Calls format(Object) of the underlying format.

Specified by:
transform in interface TwoWayTransformer<Object,String>
Parameters:
input - the object to be transformed, should be left unchanged
Returns:
a transformed object
Throws:
IllegalArgumentException - if the Format cannot format the type of object

retransform

public Object retransform(String input)
Calls parseObject(String) of the underlying format.

Specified by:
retransform in interface TwoWayTransformer<Object,String>
Parameters:
input - the object for which the transformation origin is searched.
Returns:
the transformation origin of the specified object.
Throws:
ClassCastException - if the input object is not a string
IllegalArgumentException - if a parsing exception occurred

isRetrievable

public boolean isRetrievable(String input)
Returns the value specified in the constructor.

Specified by:
isRetrievable in interface TwoWayTransformer<Object,String>
Parameters:
input - the object for which the transformation origin is searched.
Returns:
true if the origin of the specified object can be calculated.