JADE v6.1

com.dautelle.money
Class Currency

java.lang.Object
  extended byjavax.units.Unit
      extended byjavax.units.BaseUnit
          extended bycom.dautelle.money.Currency
All Implemented Interfaces:
java.io.Serializable

public final class Currency
extends BaseUnit

This class represents a currency Unit. Currencies are BaseUnit, conversions between currencies is possible if their respective exchange rates have been set.

Quantities stated in Currency are instances of Money.

By default, the label associated to a currency is its ISO-4217 code (see the ISO 4217 maintenance agency for a table of currency codes). An application may change this default using the UnitFormat.label(...) static method. For example:

     UnitFormat.label(Currency.EUR, "€");
     UnitFormat.label(Currency.GBP, "£");
     UnitFormat.label(Currency.JPY, "¥");
     UnitFormat.label(Currency.USD, "$");
     

Version:
4.3, March 10, 2003
Author:
Jean-Marie Dautelle
See Also:
setExchangeRate(double), Serialized Form

Field Summary
static Currency AUD
          The Australian Dollar currency unit.
static Currency CAD
          The Canadian Dollar currency unit.
static Currency CNY
          The China Yan currency.
static Currency EUR
          The Euro currency.
static Currency GBP
          The British Pound currency.
static Currency JPY
          The Japanese Yen currency.
static Currency KRW
          The Korean Republic Won currency.
static Currency SYSTEM
          A generic currency (currency sign "¤"), used when the locale currency is unknown.
static Currency TWD
          The Taiwanese dollar currency.
static Currency USD
          The United State dollar currency.
 
Fields inherited from class javax.units.Unit
ONE
 
Method Summary
static int getDefaultFractionDigits(Currency currency)
          Returns the default number of fraction digits used with the specified currency unit.
 double getExchangeRate()
          Returns the exchange rate for this Currency.
static Currency getInstance(java.util.Locale locale)
          Returns the currency unit for the country of the given locale.
static BaseUnit getInstance(java.lang.String code)
          Returns the currency unit for the given currency code.
static Currency getReferenceCurrency()
          Returns the currency used as reference when setting the exchange rate.
 void setExchangeRate(double refAmount)
          Sets the exchange rate of this Currency relatively to the reference currency.
static void setReferenceCurrency(Currency currency)
          Sets the reference currency (context sensitive).
 
Methods inherited from class javax.units.BaseUnit
equals, getSymbol, getSystemUnit, setDimension
 
Methods inherited from class javax.units.Unit
add, alternate, appendTo, divide, getConverterTo, getDimension, getInstance, getInstances, hashCode, isCompatible, isSystemUnit, multiply, multiply, pow, readResolve, root, searchSymbol, toString, valueOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SYSTEM

public static final Currency SYSTEM
A generic currency (currency sign "¤"), used when the locale currency is unknown.


AUD

public static final Currency AUD
The Australian Dollar currency unit.


CAD

public static final Currency CAD
The Canadian Dollar currency unit.


CNY

public static final Currency CNY
The China Yan currency.


EUR

public static final Currency EUR
The Euro currency.


GBP

public static final Currency GBP
The British Pound currency.


JPY

public static final Currency JPY
The Japanese Yen currency.


KRW

public static final Currency KRW
The Korean Republic Won currency.


TWD

public static final Currency TWD
The Taiwanese dollar currency.


USD

public static final Currency USD
The United State dollar currency.

Method Detail

setReferenceCurrency

public static void setReferenceCurrency(Currency currency)
Sets the reference currency (context sensitive). Changing the reference currency clears all the exchange rates previously set.

Parameters:
currency - the new reference currency.
See Also:
LocalContext

getReferenceCurrency

public static Currency getReferenceCurrency()
Returns the currency used as reference when setting the exchange rate. By default, the reference currency is the currency for the default country locale.

Returns:
the reference currency.
See Also:
setExchangeRate(double), getInstance(Locale)

setExchangeRate

public void setExchangeRate(double refAmount)
Sets the exchange rate of this Currency relatively to the reference currency. Setting the exchange rate allows for conversion between Money stated in different currencies. For example:
     Currency.setReferenceCurrency(Currency.USD);
     Currency.EUR.setExchangeRate(1.17); // 1.0 € = 1.17 $
 

Parameters:
refAmount - the amount stated in the getReferenceCurrency() equals to one unit of this Currency.
See Also:
getReferenceCurrency()

getExchangeRate

public double getExchangeRate()
Returns the exchange rate for this Currency.

Returns:
the amount stated in the getReferenceCurrency() equals to one unit of this Currency.
Throws:
ConversionException - if the exchange rate has not be set for this Currency.

getInstance

public static BaseUnit getInstance(java.lang.String code)
Returns the currency unit for the given currency code. See the ISO 4217 maintenance agency for more information, including a table of currency codes.

Parameters:
code - the ISO-4217 code of the currency (e.g. "EUR", "USD", "JPY").
Returns:
the currency unit for the given currency code.
Throws:
java.lang.IllegalArgumentException - if the specified code is not an ISO-4217 code.

getInstance

public static Currency getInstance(java.util.Locale locale)
Returns the currency unit for the country of the given locale.

Parameters:
locale - the locale for whose country a currency unit is returned.
Returns:
the currency unit for the country of the given locale or SYSTEM if unknown..

getDefaultFractionDigits

public static int getDefaultFractionDigits(Currency currency)
Returns the default number of fraction digits used with the specified currency unit. For example, the default number of fraction digits for the EUR is 2, while for the JPY (Yen) it's 0.

Parameters:
currency - the currency unit for which the return the default number of fraction digits is returned.
Returns:
the default number of fraction digits for the specified currency.

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.