com.pcauto.util
Class VolumeFormat

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

public class VolumeFormat
extends QuantityFormat

VolumeFormat provides several mechanisms to use Volume objects:

  • to display volume values in dynamically selected units
  • to create and load values into Volume objects

    Locale based constructors use a default scale of 2. The parse and format methods are used to generate and format Volume 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
    VolumeFormat()
              Constructs new VolumeFormat instance based on default Locale.
    VolumeFormat(java.util.Locale loc)
              Constructs new VolumeFormat instance based on supplied Locale.
    VolumeFormat(VolumeUnits units, int scale)
              Constructs new VolumeFormat with units set to VolumeUnits units and scale set to int scale.
     
    Method Summary
     java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
              Returns StringBuffer with supplied Volume quantity formatted in units.
     java.lang.String formatVolume(Volume vol)
              Returns String with supplied Volume quantity formatted in units.
     VolumeUnits getUnits()
              Gets value for measurement units.
     java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
              Parses String based on units to return a Volume object as an Object.
     Volume parseVolume(java.lang.String value)
              Parses String based on units to return a Volume object.
     void setUnits(VolumeUnits 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
    clone, format, formatToCharacterIterator, parseObject
     
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    VolumeFormat

    public VolumeFormat()
    Constructs new VolumeFormat instance based on default Locale.


    VolumeFormat

    public VolumeFormat(java.util.Locale loc)
    Constructs new VolumeFormat instance based on supplied Locale.

    Parameters:
    loc - Locale to set correct measurement units

    VolumeFormat

    public VolumeFormat(VolumeUnits units,
                        int scale)
    Constructs new VolumeFormat with units set to VolumeUnits units and scale set to int scale.

    Parameters:
    units - VolumeUnits to set units
    scale - int to set scale
    Method Detail

    formatVolume

    public java.lang.String formatVolume(Volume vol)
    Returns String with supplied Volume quantity formatted in units.

    Parameters:
    vol - Volume object from which to format value
    Returns:
    String volume 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 Volume quantity formatted in units.

    Parameters:
    obj - Object object from which to format value
    toAppendTo - (@link StringBuffer} buffer to append value to
    pos - FieldPosition ignored in this implementation
    Returns:
    StringBuffer volume in current units
    Throws:
    IllegalArgumentException - if obj is not of type Volume.

    parseVolume

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

    Parameters:
    value - String to be converted to Volume object
    Returns:
    Volume holding a value specified in input String
    Throws:
    NumberFormatException - on non-numeric String input

    parseObject

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

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

    setUnits

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

    Parameters:
    units - VolumeUnits new value for measurement units

    getUnits

    public VolumeUnits getUnits()
    Gets value for measurement units.

    Returns:
    VolumeUnits value of current measurement units