com.pcauto.util
Class CurrencyFormat

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

public class CurrencyFormat
extends QuantityFormat

CurrencyFormat provides several mechanisms to use Currency objects;

  • to display currency values in dynamically selected units and scale
  • to create and load values into Currency objects

    Locale based constructors will use a default scale of 2. The parse and format methods are used to generate and format Currency objects respectively. They can be used in conjunction to convert Currency objects into different units.

    Conversion rates have been hardcoded to Sept. 06, 2002. Use the setCurrencyExchange member function to set new conversion rates.

    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
    CurrencyFormat()
              Creates new CurrencyFormat instance based on default Locale
    CurrencyFormat(CurrencyUnits units, int scale)
              Creates new CurrencyFormat instance with units set to int units and scale set to int scale.
    CurrencyFormat(java.util.Locale loc)
              Creates new CurrencyFormat instance based on supplied Locale
     
    Method Summary
     java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
              Returns StringBuffer with supplied Currency quantity formatted in units
     java.lang.String formatCurrency(Currency crn)
              Returns String with supplied Currency quantity formatted in units
     CurrencyUnits getUnits()
              Gets value for currency units.
     Currency parseCurrency(java.lang.String value)
              Parses String based on units to return a Currency object.
     java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
              Parses String based on units to return a Currency object.
     void setCurrencyExchange(CurrencyUnits srcCurrency, CurrencyUnits destCurrency, double exchangeRate)
              Sets exchange rate between diferent currency units.
     void setUnits(CurrencyUnits units)
              Sets value for currency 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

    CurrencyFormat

    public CurrencyFormat()
    Creates new CurrencyFormat instance based on default Locale


    CurrencyFormat

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

    Parameters:
    loc - Locale to set correct currency units

    CurrencyFormat

    public CurrencyFormat(CurrencyUnits units,
                          int scale)
    Creates new CurrencyFormat instance with units set to int units and scale set to int scale.

    Parameters:
    scale - int to set scale
    Method Detail

    formatCurrency

    public java.lang.String formatCurrency(Currency crn)
    Returns String with supplied Currency quantity formatted in units

    Parameters:
    crn - Currency object from which to format value
    Returns:
    String currency 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 Currency quantity formatted in units

    Parameters:
    toAppendTo - StringBuffer to append string to
    pos - FieldPosition ignored in this implementation
    Returns:
    StringBuffer currency in current units

    parseCurrency

    public Currency parseCurrency(java.lang.String value)
    Parses String based on units to return a Currency object. The function will successfully parse input String, even if it contains unit character as first character ($5.33)

    Parameters:
    value - String to be converted to Currency object
    Returns:
    Currency 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 Currency object. The function will successfully parse input String, even if it contains unit character as first character ($5.33)

    Returns:
    Currency holding a value specified in input String
    Throws:
    NumberFormatException - on non-numeric String input

    setCurrencyExchange

    public void setCurrencyExchange(CurrencyUnits srcCurrency,
                                    CurrencyUnits destCurrency,
                                    double exchangeRate)
    Sets exchange rate between diferent currency units. This function should be used before any convertions, to override the built-in conversion table.


    setUnits

    public void setUnits(CurrencyUnits units)
    Sets value for currency units.


    getUnits

    public CurrencyUnits getUnits()
    Gets value for currency units.

    Returns:
    CurrencyUnits value of current measurement units