com.pcauto.util
Class ElapsedTimeFormat

java.lang.Object
  extended byjava.text.Format
      extended bycom.pcauto.util.QuantityFormat
          extended bycom.pcauto.util.ElapsedTimeFormat
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class ElapsedTimeFormat
extends QuantityFormat

ElapsedTimeFormat is a concrete class for formatting and parsing ElapsedTime objects. If no current pattern for the formatter is specified at instantiation, the global pattern will be used to create all new ElapsedTimeFormat objects.

The reserved letters for formatter pattern definitions, are defined below:

  • w - week
  • d - day
  • h - hour
  • m - minute
  • s -second

    All literals should be enclosed into single quotes '', except . and :

    The smallest time unit in the pattern string can use a scale, which should be specified in the pattern (for example, hh:mm.mm).

    See Also:
    Serialized Form

    Nested Class Summary
     
    Nested classes inherited from class java.text.Format
    java.text.Format.Field
     
    Field Summary
     
    Fields inherited from class com.pcauto.util.QuantityFormat
    groupingUsed, scale, units
     
    Constructor Summary
    ElapsedTimeFormat()
              Constructs new ElapsedTimeFormat using global pattern.
    ElapsedTimeFormat(java.lang.String format)
              Constructs new ElapsedTimeFormat instance based on pattern specified.
     
    Method Summary
    static void applyGlobalPattern(java.lang.String format)
              Sets new global pattern to be used as default for new objects.
     void applyPattern(java.lang.String format)
              Sets new pattern for this ElapsedTimeFormat.
    protected  double convertUnits(double value, int srcUnit, int destUnit)
               
     java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
              Returns StringBuffer with ElapsedTime formatted in current format.
     java.lang.String formatElapsedTime(ElapsedTime time)
              Returns String with ElapsedTime formatted in current format.
     int getRoundingMode()
              Get current rounding mode.
     ElapsedTime parseElapsedTime(java.lang.String value)
              Parses String based on units to return an ElapsedTime object.
     java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
              Parses String based on units to return an ElapsedTime object.
     void setRoundingMode(int roundingMode)
              Sets rounding mode to be used by the smallest time unit in the current pattern string.
    static java.lang.String toGlobalPattern()
              Returns current global pattern String.
     java.lang.String toPattern()
              Returns current pattern string
     
    Methods inherited from class com.pcauto.util.QuantityFormat
    getScale, isGroupingUsed, setGroupingUsed, setScale
     
    Methods inherited from class java.text.Format
    clone, format, formatToCharacterIterator, parseObject
     
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    ElapsedTimeFormat

    public ElapsedTimeFormat()
    Constructs new ElapsedTimeFormat using global pattern.


    ElapsedTimeFormat

    public ElapsedTimeFormat(java.lang.String format)
    Constructs new ElapsedTimeFormat instance based on pattern specified.

    Parameters:
    format - String
    Method Detail

    applyGlobalPattern

    public static void applyGlobalPattern(java.lang.String format)
    Sets new global pattern to be used as default for new objects.

    Parameters:
    format - String

    toGlobalPattern

    public static java.lang.String toGlobalPattern()
    Returns current global pattern String.

    Returns:
    String global pattern

    applyPattern

    public void applyPattern(java.lang.String format)
    Sets new pattern for this ElapsedTimeFormat.

    Parameters:
    format - String

    toPattern

    public java.lang.String toPattern()
    Returns current pattern string

    Returns:
    String pattern

    setRoundingMode

    public void setRoundingMode(int roundingMode)
    Sets rounding mode to be used by the smallest time unit in the current pattern string. The rounding modes expected are those, which are used in BigDecimal class.

    Parameters:
    roundingMode - int

    getRoundingMode

    public int getRoundingMode()
    Get current rounding mode.

    Returns:
    int

    parseElapsedTime

    public ElapsedTime parseElapsedTime(java.lang.String value)
                                 throws java.text.ParseException
    Parses String based on units to return an ElapsedTime object.

    Parameters:
    value - String to be converted to ElapsedTime object
    Returns:
    ElapsedTime holding a value specified in input String
    Throws:
    java.text.ParseException

    parseObject

    public java.lang.Object parseObject(java.lang.String source,
                                        java.text.ParsePosition pos)
    Parses String based on units to return an ElapsedTime object.

    Parameters:
    source - String to be converted to ElapsedTime object
    pos - ParsePosition (can't be null)
    Returns:
    Object a ElapsedTime holding a value specified in input String
    Throws:
    NumberFormatException - on non-numeric String input

    formatElapsedTime

    public java.lang.String formatElapsedTime(ElapsedTime time)
    Returns String with ElapsedTime formatted in current format.

    Parameters:
    time - ElapsedTime object from which to format value
    Returns:
    String ElapsedTime in current format

    format

    public java.lang.StringBuffer format(java.lang.Object obj,
                                         java.lang.StringBuffer toAppendTo,
                                         java.text.FieldPosition pos)
    Returns StringBuffer with ElapsedTime formatted in current format.

    Parameters:
    obj - Object The object to format
    toAppendTo - int where the text is to be appended
    pos - On input: an alignment field, if desired.
    Returns:
    StringBuffer ElapsedTime in current format

    convertUnits

    protected double convertUnits(double value,
                                  int srcUnit,
                                  int destUnit)