cdx.scorebot.util.translator
Class TranslatorMulti<FROM,TO>

java.lang.Object
  extended by cdx.scorebot.util.translator.TypeTranslator<FROM,TO>
      extended by cdx.scorebot.util.translator.TranslatorMulti<FROM,TO>
All Implemented Interfaces:
java.io.Serializable

public class TranslatorMulti<FROM,TO>
extends TypeTranslator<FROM,TO>

Can translate between two objects using different translaters depending on what type the two objects actually are. The user specifies which translators to use.

Author:
David Underhill
See Also:
Serialized Form

Constructor Summary
TranslatorMulti()
          Instantiates a translator for an Object
 
Method Summary
 void addTranslator(java.lang.Class from, java.lang.Class to, TypeTranslator t)
          adds a translator to use
 TO translate1(FROM valueToTranslate)
          gets the TO representation of the specified object FROM
 FROM translate2(TO valueToTranslate)
          gets the FROM representation of the specified TO object
 
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

TranslatorMulti

public TranslatorMulti()
Instantiates a translator for an Object

Method Detail

addTranslator

public void addTranslator(java.lang.Class from,
                          java.lang.Class to,
                          TypeTranslator t)
adds a translator to use


translate1

public TO translate1(FROM valueToTranslate)
              throws TranslationFailedException
gets the TO representation of the specified object FROM

Specified by:
translate1 in class TypeTranslator<FROM,TO>
Parameters:
valueToTranslate - some object of type FROM
Returns:
the TO representation of the valueToTranslate; null if FROM can't be translated to TO
Throws:
TranslationFailedException - thrown if the value cannot be translated

translate2

public FROM translate2(TO valueToTranslate)
                throws TranslationFailedException
gets the FROM representation of the specified TO object

Specified by:
translate2 in class TypeTranslator<FROM,TO>
Parameters:
valueToTranslate - some object of type TO
Returns:
the FROM representation of the valueToTranslate
Throws:
TranslationFailedException - thrown if the value cannot be translated