com.pcauto.util
Class WeightFormat

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

public class WeightFormat
extends QuantityFormat

WeightFormat provides several mechanisms to use Weight objects:

  • to display weight values in dynamically selected units
  • to create and load values into Weight objects

    Locale based constructors use a default scale of 2. The parse and format methods are used to generate and format Weight 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
    WeightFormat()
              Constructs new WeightFormat instance based on default Locale.
    WeightFormat(java.util.Locale loc)
              Constructs new WeightFormat instance based on supplied Locale.
    WeightFormat(WeightUnits units, int scale)
              Constructs new WeightFormat with units set to WeightUnits units and scale set to int scale.
     
    Method Summary
     java.lang.Object clone()
              Creates new WeightFormat object based on this WeightFormat.
     java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
              Returns StringBuffer with supplied Weight quantity formatted in units.
     java.lang.String formatWeight(Weight wt)
              Returns String with supplied Weight quantity formatted in units.
     WeightUnits 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 Weight object.
     Weight parseWeight(java.lang.String value)
              Parses String based on units to return a Weight object.
     void setUnits(WeightUnits 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

    WeightFormat

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


    WeightFormat

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

    Parameters:
    loc - Locale to set correct measurement units

    WeightFormat

    public WeightFormat(WeightUnits units,
                        int scale)
    Constructs new WeightFormat with units set to WeightUnits units and scale set to int scale.

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

    formatWeight

    public java.lang.String formatWeight(Weight wt)
    Returns String with supplied Weight quantity formatted in units.

    Parameters:
    wt - Weight object from which to format value
    Returns:
    String weight 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 Weight quantity formatted in units.

    Parameters:
    obj - Object object from which to format value
    toAppendTo - StringBuffer string buffer to append to
    pos - FieldPosition ignored but can't be null
    Returns:
    StringBuffer weight in current units
    Throws:
    IllegalArguementException - if obj is not a Weight.

    parseWeight

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

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

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

    clone

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


    setUnits

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


    getUnits

    public WeightUnits getUnits()
    Gets value for measurement units.

    Returns:
    WeightUnits value of current measurement units