|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectUnit<Q>
DerivedUnit<Money>
Currency
public class Currency
This class represents a currency Unit.
Currencies are a special form of DerivedUnit, conversions
between currencies is possible if their respective exchange rates
have been set. The conversion factor can be changed dynamically.
Measurements stated in a Currency are usually of Money
type. For example:
Measure<Money> tenDollars = Measure.valueOf(10, Currency.USD);
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). Although,
local mapping of currency symbol is possible.
For example:
EUR.setLabel("€");
GBP.setLabel("£");
JPY.setLabel("¥");
USD.setLabel("$");
| 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 |
TWD
The Taiwanese dollar currency. |
static Currency |
USD
The United State dollar currency. |
| Fields inherited from class Unit |
|---|
ONE |
| Constructor Summary | |
|---|---|
Currency(String code)
Creates the currency unit for the given currency code. |
|
| Method Summary | |
|---|---|
boolean |
equals(Object obj)
|
String |
getCode()
Returns the currency code for this currency. |
UnitConverter |
getConverterToSI()
|
Dimension |
getDimension()
|
UnitConverter |
getDimensionalTransform()
|
Number |
getExchangeRate(Currency target)
Returns the exchange rate from this Currency to the specified
currency. |
int |
getFractionDigits()
Returns the number of fraction digits used with this currency unit. |
static Currency |
getInstance(Locale locale)
Returns the currency for the country of the given locale. |
String |
getLabel()
Returns the local label
for this currency (default {@link #getCode()). |
int |
hashCode()
|
void |
setExchangeRate(Number factor,
Currency target)
Sets the exchange rate of this Currency to
the specified target currency. |
void |
setLabel(String label)
Sets the local label
for this currency. |
Currency |
toSI()
|
String |
toString()
|
| Methods inherited from class Unit |
|---|
alternate, asType, compound, divide, divide, divide, getConverterTo, getConverterToAny, inverse, isCompatible, isSI, plus, pow, root, times, times, times, toStringLocale, transform, valueOf |
| Methods inherited from class Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Currency AUD
public static final Currency CAD
public static final Currency CNY
public static final Currency EUR
public static final Currency GBP
public static final Currency JPY
public static final Currency KRW
public static final Currency TWD
public static final Currency USD
| Constructor Detail |
|---|
public Currency(String code)
code - the ISO-4217 code of the currency (e.g.
"EUR", "USD", "JPY").
IllegalArgumentException - if the specified code is not an ISO-4217
code.UnitFormat.getSymbolMap()| Method Detail |
|---|
public static Currency getInstance(Locale locale)
locale - the locale for whose country a Currency
instance is returned.
public String getCode()
"EUR", "USD", "JPY").public String getLabel()
local label
for this currency (default {@link #getCode()).
toString()public void setLabel(String label)
local label
for this currency.
label - the new label.public int getFractionDigits()
EUR is 2, while for the JPY (Yen)
it's 0. This method can be overriden for custom currencies returning
values different from 2.
public void setExchangeRate(Number factor,
Currency target)
Currency to
the specified target currency. Setting the exchange rate allows
for conversion between money quantities stated in this currency
to money quantities setting in the specified currency.
For example:
// Sets the exchange rate from EUR to USD and from USD to EUR.
EUR.setExchangeRate(1.45, USD);
USD.setExchangeRate(0.62, EUR);
factor - the amount of the target currency equals to this currency.target - the target currency.CurrencyConverter#setInstance(org.jscience.economics.money.CurrencyConverter)public Number getExchangeRate(Currency target)
Currency to the specified
currency.
target - the target currency.
BigDecimal.ONE if the specified target is equals
to this or null if the exchange rate has not be set.public boolean equals(Object obj)
equals in class Unit<Money>public int hashCode()
hashCode in class Unit<Money>public Currency toSI()
toSI in class Unit<Money>public String toString()
toString in class Unit<Money>public UnitConverter getConverterToSI()
getConverterToSI in class Unit<Money>public Dimension getDimension()
getDimension in class Unit<Money>public UnitConverter getDimensionalTransform()
getDimensionalTransform in class Unit<Money>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||