cdx.scorebot.util.translator
Class TranslatorTimeString

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

public class TranslatorTimeString
extends TypeTranslator<java.lang.Integer,java.lang.String>

Stores a value as a Integer and can translate to and from an String. The String may specify the unit of time using its last character. That String is resulting from the translation from an Integer will be in the base unit. The String may be specified as a Double, though any fraction of a second will be rounded to the nearest integer value.

Author:
David Underhill
See Also:
Serialized Form

Constructor Summary
TranslatorTimeString()
          Instantiates a translator with the base unit of one second
TranslatorTimeString(int secondsInBaseUnit)
          Instantiates a translator with the base unit of the specified number of seconds
 
Method Summary
 java.lang.String translate1(java.lang.Integer valueToTranslate)
          gets the String representation of the specified Integer
 java.lang.Integer translate2(java.lang.String valueToTranslate)
          Gets the Integer representation of the specified String in terms of the seconds in the base unit.
 
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

TranslatorTimeString

public TranslatorTimeString()
Instantiates a translator with the base unit of one second


TranslatorTimeString

public TranslatorTimeString(int secondsInBaseUnit)
Instantiates a translator with the base unit of the specified number of seconds

Method Detail

translate1

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

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

translate2

public java.lang.Integer translate2(java.lang.String valueToTranslate)
                             throws TranslationFailedException
Gets the Integer representation of the specified String in terms of the seconds in the base unit. The suffixes 's', 'm', 'h', and 'd' may be used to specify the units on the valueToTranslate. If no unit is supplied, then 's' is assumed.

Specified by:
translate2 in class TypeTranslator<java.lang.Integer,java.lang.String>
Parameters:
valueToTranslate - some String which may either be an Integer or a Double with some unit specification (e.g. 1.5h)
Returns:
the Integer representation of the valueToTranslate
Throws:
TranslationFailedException - thrown if the value cannot be translated