cdx.scorebot.util.translator
Class TranslatorInstanceString<T>

java.lang.Object
  extended by cdx.scorebot.util.translator.TypeTranslator<T,java.lang.String>
      extended by cdx.scorebot.util.translator.TranslatorInstanceString<T>
All Implemented Interfaces:
java.io.Serializable

public class TranslatorInstanceString<T>
extends TypeTranslator<T,java.lang.String>

Can translate to an Object of type T from a string. The Object is generated from the string by using the constructor in Object which has a single string as a parameter. The string is generated from the Object using the toString method.

Author:
David Underhill
See Also:
Serialized Form

Constructor Summary
TranslatorInstanceString()
          Instantiates a translator for an Object
TranslatorInstanceString(java.lang.Class c)
          Instantiates a translator
TranslatorInstanceString(T o)
          Instantiates a translator
 
Method Summary
 java.lang.String translate1(T valueToTranslate)
          gets the String representation of the specified object T
 T translate2(java.lang.String valueToTranslate)
          gets the T representation of the specified String
 
Methods inherited from class cdx.scorebot.util.translator.TypeTranslator
canTranslate1, canTranslate2, getLastException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TranslatorInstanceString

public TranslatorInstanceString()
Instantiates a translator for an Object


TranslatorInstanceString

public TranslatorInstanceString(T o)
Instantiates a translator

Parameters:
o - an instance of the object to translate (only used to get the class)

TranslatorInstanceString

public TranslatorInstanceString(java.lang.Class c)
Instantiates a translator

Parameters:
c - the class this translator translates from
Method Detail

translate1

public java.lang.String translate1(T valueToTranslate)
gets the String representation of the specified object T

Specified by:
translate1 in class TypeTranslator<T,java.lang.String>
Parameters:
valueToTranslate - some object T
Returns:
the String representation of the valueToTranslate (null if valueToTranslate is null)

translate2

public T translate2(java.lang.String valueToTranslate)
             throws TranslationFailedException
gets the T representation of the specified String

Specified by:
translate2 in class TypeTranslator<T,java.lang.String>
Parameters:
valueToTranslate - some String
Returns:
the T representation of the valueToTranslate
Throws:
TranslationFailedException - thrown if the value cannot be translated