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

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

public class TranslatorObjectClassName<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 a constructor in the class specified by the string (canonical name). The parameters to the constructor are specified by the constructor to this TranslatorObjectClassName class. The string is generated by calling the getClass().getCanonicalName() method of the Object.

Author:
David Underhill
See Also:
Serialized Form

Constructor Summary
TranslatorObjectClassName()
          Instantiates a translator (will use T's default constructor)
TranslatorObjectClassName(java.util.AbstractList<java.lang.Object> params)
          Instantiates a translator
TranslatorObjectClassName(java.lang.Object o)
          Instantiates a translator
TranslatorObjectClassName(java.lang.Object o1, java.lang.Object o2)
          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 Object 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

TranslatorObjectClassName

public TranslatorObjectClassName()
Instantiates a translator (will use T's default constructor)


TranslatorObjectClassName

public TranslatorObjectClassName(java.lang.Object o)
Instantiates a translator

Parameters:
o - object to pass to the T's contructor

TranslatorObjectClassName

public TranslatorObjectClassName(java.lang.Object o1,
                                 java.lang.Object o2)
Instantiates a translator

Parameters:
o1 - first object to pass to the T's contructor
o2 - first object to pass to the T's contructor

TranslatorObjectClassName

public TranslatorObjectClassName(java.util.AbstractList<java.lang.Object> params)
Instantiates a translator

Parameters:
params - list of values to pass to the T's constructor (if null, then null is added to a new list!)
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 Object 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