com.pcauto.util
Class DensityFormat

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

public class DensityFormat
extends QuantityFormat

DensityFormat provides several mechanisms to use Density objects:

  • to display density values in dynamically selected units
  • to create and load values into Density objects

    Locale based constructors use a default scale of 2. The parse and format methods are used to generate and format Density 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
    DensityFormat()
              Creates new DensityFormat instance based on default Locale.
    DensityFormat(DensityUnits units, int scale)
              Constructs new DensityFormat with units set to int units and scale set to int scale.
    DensityFormat(java.util.Locale loc)
              Creates new DensityFormat instance based on supplied Locale
     
    Method Summary
     java.lang.Object clone()
              Creates new DensityFormat object based on this DensityFormat.
     java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
              Returns StringBuffer with supplied Density quantity formatted in units.
     java.lang.String formatDensity(Density den)
              Returns String with supplied Density quantity formatted in units.
     DensityUnits getUnits()
              Gets value for measurement unit.
     Density parseDensity(java.lang.String value)
              Parses String based on units to return a Density object.
     java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
              Parses String based on units to return a Density object.
     void setUnits(DensityUnits 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

    DensityFormat

    public DensityFormat()
    Creates new DensityFormat instance based on default Locale.


    DensityFormat

    public DensityFormat(java.util.Locale loc)
    Creates new DensityFormat instance based on supplied Locale

    Parameters:
    loc - Locale to set correct density units

    DensityFormat

    public DensityFormat(DensityUnits units,
                         int scale)
    Constructs new DensityFormat with units set to int units and scale set to int scale.

    Method Detail

    getUnits

    public DensityUnits getUnits()
    Gets value for measurement unit.

    Returns:
    DensityUnits value of current measurement units

    setUnits

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


    formatDensity

    public java.lang.String formatDensity(Density den)
    Returns String with supplied Density quantity formatted in units.

    Returns:
    String density 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 Density quantity formatted in units.

    Parameters:
    obj - Density object from which to format value
    Returns:
    StringBuffer density in current units

    parseDensity

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

    Parameters:
    value - String to be converted to Density object
    Returns:
    Density 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 Density object.

    Parameters:
    pos - ParsePosition ignored in this implementation
    Returns:
    Density holding a value specified in input String
    Throws:
    NumberFormatException - on non-numeric String input

    clone

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

    Returns:
    new DensityFormat object