Venice 0.751beta

nz.org.venice.util
Class Currency

java.lang.Object
  extended bynz.org.venice.util.Currency
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class Currency
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable

An immutaable representation of Currency. This class represents a currency, such as the Australian Dollar or the British Pound, rather than an acutal amount of money. We use our own representation because the Java API's Currency class has no way of returning a NumberFormat object. So we could not simply pass a Currency object to our Money object and have the Money object be able to print properly. We would have to pass both the locale and the currency around, which is heavy handed.

Author:
Andrew Leppard
See Also:
Money

Constructor Summary
Currency(java.util.Locale locale)
          Create an instance of the currency associated with the given locale.
Currency(java.lang.String currencyCode)
          Create an an instance of the currency using the currency described by the given ISO 4217 currency code.
 
Method Summary
 java.lang.Object clone()
          Create and return a compare of this currency.
 int compareTo(java.lang.Object object)
          Compare this currency to the given object.
 boolean equals(java.lang.Object object)
          Compare this currency to the given object.
static java.util.List getAvailableCurrencies()
          Return a list of all the available currencies.
 java.lang.String getCurrencyCode()
          Return the ISO 4217 currency code of this currency.
static Currency getDefaultCurrency()
          Return the currency associated with the default locale.
 int getDefaultFractionDigits()
          Return the number of fraction digits used to display this currency.
 java.text.NumberFormat getNumberFormat()
          Return the number format which can be used to form a number into the appropriate locale representation of this currency.
 java.lang.String toString()
          Return a string representation of this currency.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Currency

public Currency(java.util.Locale locale)
Create an instance of the currency associated with the given locale. If the given locale has no associated currency, e.g. Antartica, this function will default to the US dollar.

Parameters:
locale - use the currency associated with this locale

Currency

public Currency(java.lang.String currencyCode)
         throws UnknownCurrencyCodeException
Create an an instance of the currency using the currency described by the given ISO 4217 currency code.

Parameters:
currencyCode - the ISO 4217 currency code (3 characters).
Throws:
UnknownCurrencyCodeException - if the currency code is not known.
Method Detail

getAvailableCurrencies

public static java.util.List getAvailableCurrencies()
Return a list of all the available currencies.

Returns:
list of available currencies.

getDefaultCurrency

public static Currency getDefaultCurrency()
Return the currency associated with the default locale. If there is no currency associated with the default locale, it will use the US Dollar.

Returns:
currency associated with the default locale.

getCurrencyCode

public java.lang.String getCurrencyCode()
Return the ISO 4217 currency code of this currency.

Returns:
ISO 4217 currency code.

toString

public java.lang.String toString()
Return a string representation of this currency.

Returns:
string representation of this currency.

getDefaultFractionDigits

public int getDefaultFractionDigits()
Return the number of fraction digits used to display this currency. For examle, the Australian Dollar has 2 fraction digits (e.g. $12.95) while the Japanese Yen has zero (e.g. 100 yen).

Returns:
number of fraction digits.

getNumberFormat

public java.text.NumberFormat getNumberFormat()
Return the number format which can be used to form a number into the appropriate locale representation of this currency.

Returns:
the number format.

compareTo

public int compareTo(java.lang.Object object)
Compare this currency to the given object. If the given object is not a currency, it will throw a ClassCastException. Currencies are ordered alphabetically by their ISO 4217 currency codes.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - currency object to be compared
Returns:
0 if the two objects are identical, -1 if the argument currency comes alphabetically after this currency, 1 if the argument currency comes alphabetically before this currency.
Throws:
java.lang.ClassCastException - if the argument is not a Currency.

equals

public boolean equals(java.lang.Object object)
Compare this currency to the given object. If the given object is not a currency, it will throw a ClassCastException.

Parameters:
object - currency object to be compared
Returns:
true if the currencies are the same; false otherwise.
Throws:
java.lang.ClassCastException - if the argument is not a Currency.

clone

public java.lang.Object clone()
Create and return a compare of this currency. Since currencies are immutable, this simply returns this object.

Returns:
this object.

Venice 0.751beta