com.pcauto.util
Class DistanceFormat

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

public class DistanceFormat
extends QuantityFormat

DistanceFormat provides several mechanisms to use Distance objects:

  • to display distance values in dynamically selected units
  • to create and load values into Distance objects

    Locale based constructors use a default scale of 2. The parse and format methods are used to generate and format Distance objects respectively

    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
    DistanceFormat()
              Constructs new DistanceFormat instance based on default Locale
    DistanceFormat(DistanceUnits units, int scale)
              Constructs new DistanceFormat instance with units set to DistanceUnits units and scale set to int scale.
    DistanceFormat(java.util.Locale loc)
              Constructs new DistanceFormat instance based on locale.
     
    Method Summary
     java.lang.Object clone()
              Creates new DistanceFormat object based on this DistanceFormat.
     java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
              Returns StringBuffer with supplied Distance quantity formatted in units
     java.lang.String formatDistance(Distance dist)
              Returns String with supplied Distance quantity formatted in units
     DistanceUnits getUnits()
              Gets value for measurement units.
     Distance parseDistance(java.lang.String value)
              Parses String based on units to return a Distance object.
     java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
              Parses String based on units to return a Distance object.
     void setUnits(DistanceUnits units)
              Sets value for measurement units.
     
    Methods inherited from class com.pcauto.util.QuantityFormat
    getScale, isGroupingUsed, setGroupingUsed, setScale
     
    Methods inherited from class java.text.Format
    format, formatToCharacterIterator, parseObject
     
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    DistanceFormat

    public DistanceFormat()
    Constructs new DistanceFormat instance based on default Locale


    DistanceFormat

    public DistanceFormat(java.util.Locale loc)
    Constructs new DistanceFormat instance based on locale.

    Parameters:
    loc - Locale to set correct measurement units

    DistanceFormat

    public DistanceFormat(DistanceUnits units,
                          int scale)
    Constructs new DistanceFormat instance with units set to DistanceUnits units and scale set to int scale.

    Parameters:
    scale - int to set scale
    Method Detail

    formatDistance

    public java.lang.String formatDistance(Distance dist)
    Returns String with supplied Distance quantity formatted in units

    Parameters:
    dist - Distance object from which to format value
    Returns:
    String distance in current units

    format

    public java.lang.StringBuffer format(java.lang.Object obj,
                                         java.lang.StringBuffer toAppendTo,
                                         java.text.FieldPosition pos)
    Returns StringBuffer with supplied Distance quantity formatted in units

    Returns:
    String distance in current units
    Throws:
    IllegalArgumentException - if obj is not of type Distance

    parseDistance

    public Distance parseDistance(java.lang.String value)
    Parses String based on units to return a Distance object.

    Parameters:
    value - String to be converted to Distance object
    Returns:
    Distance holding a value specified in input String

    parseObject

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

    Parameters:
    source - String to be converted to Distance object
    pos - ParsePosition ignored in this implementation
    Returns:
    Distance holding a value specified in input String
    Throws:
    NumberFormatException - on non-numeric String input

    clone

    public java.lang.Object clone()
    Creates new DistanceFormat object based on this DistanceFormat.


    setUnits

    public void setUnits(DistanceUnits units)
    Sets value for measurement units.


    getUnits

    public DistanceUnits getUnits()
    Gets value for measurement units.

    Returns:
    DistanceUnits value of current measurement units