|
JScience v4.3 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.measure.unit.Unit<Q>
javax.measure.unit.DerivedUnit<Money>
org.jscience.economics.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 and the conversion factor can be changed dynamically.
Quantities stated in Currency are usually 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(String) method.
For example:
UnitFormat.getStandardInstance().label(Currency.EUR, "€");
UnitFormat.getStandardInstance().label(Currency.GBP, "£");
UnitFormat.getStandardInstance().label(Currency.JPY, "¥");
UnitFormat.getStandardInstance().label(Currency.USD, "$");
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 |
TWD
The Taiwanese dollar currency. |
static Currency |
USD
The United State dollar currency. |
| Fields inherited from class javax.measure.unit.Unit |
|---|
ONE |
| Constructor Summary | |
|---|---|
Currency(java.lang.String code)
Creates the currency unit for the given currency code. |
|
| Method Summary | |
|---|---|
boolean |
equals(java.lang.Object obj)
Indicates if the specified unit can be considered equals to the one specified. |
java.lang.String |
getCode()
Returns the currency code for this currency. |
int |
getDefaultFractionDigits()
Returns the default number of fraction digits used with this currency unit. |
double |
getExchangeRate()
Returns the exchange rate for this Currency. |
static Currency |
getReferenceCurrency()
Returns the currency used as reference when setting the exchange rate. |
Unit<? super Money> |
getStandardUnit()
Returns the base unit, alternate
unit or product of base units and alternate units this unit is derived
from. |
int |
hashCode()
Returns the hash code for this unit. |
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-local). |
UnitConverter |
toStandardUnit()
Returns the converter from this unit to its system unit. |
| Methods inherited from class javax.measure.unit.Unit |
|---|
alternate, asType, compound, divide, divide, divide, getConverterTo, getDimension, inverse, isCompatible, isStandardUnit, plus, pow, root, times, times, times, toString, transform, valueOf |
| Methods inherited from class java.lang.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(java.lang.String code)
code - the ISO-4217 code of the currency (e.g.
"EUR", "USD", "JPY").
java.lang.IllegalArgumentException - if the specified code is not an ISO-4217
code.| Method Detail |
|---|
public java.lang.String getCode()
"EUR", "USD", "JPY").public int getDefaultFractionDigits()
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 static void setReferenceCurrency(Currency currency)
currency - the new reference currency.LocalContextpublic static Currency getReferenceCurrency()
setExchangeRate(double)public void setExchangeRate(double refAmount)
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 $
refAmount - the amount stated in the getReferenceCurrency()
equals to one unit of this Currency.getReferenceCurrency()public double getExchangeRate()
Currency.
getReferenceCurrency()
equals to one unit of this Currency.
ConversionException - if the exchange rate has not be set for
this Currency.public boolean equals(java.lang.Object obj)
Unit
equals in class Unit<Money>obj - the object to compare to.
true if this unit is considered equal to
that unit; false otherwise.public int hashCode()
Unit
hashCode in class Unit<Money>public Unit<? super Money> getStandardUnit()
Unitbase unit, alternate
unit or product of base units and alternate units this unit is derived
from. The standard unit identifies the "type" of
quantity for which this unit is employed.
For example:
boolean isAngularVelocity(Unit<?> u) {
return u.getStandardUnit().equals(RADIAN.divide(SECOND));
}
assert(REVOLUTION.divide(MINUTE).isAngularVelocity());
Note: Having the same system unit is not sufficient to ensure that a converter exists between the two units (e.g. °C/m and K/m).
getStandardUnit in class Unit<Money>public UnitConverter toStandardUnit()
Unit
toStandardUnit in class Unit<Money>this.getConverterTo(this.getSystemUnit())
|
JScience v4.3 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||