|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.davesag.generica.util.CurrencyConverter
The currency converter converts one Money object to another
based on a table of currency exchange rates. These rates should be moved to
a database at some stage and be dynamically updated via an
ExchangeRateHarvester.
| Field Summary | |
protected static Map |
EXCHANGE
the map of exchange rates |
protected static CurrencyConverter |
THE_CURR_CON
the singleton class |
| Constructor Summary | |
protected |
CurrencyConverter()
default contructor for internal use only. |
| Method Summary | |
void |
buildMap(ResourceBundle rates)
Builds the exchange map from the resource bundle provided. |
Money |
convert(Money from,
Currency tocurrency)
Utility class to converto a Money to an equivalent value in a different currency. |
Money |
convertFromEuro(Money money,
Currency currency)
Utility class to converto a Money to an equivalent value in a different currency. |
BigDecimal |
convertToEuro(Currency currency,
BigDecimal amount)
Converts the supplied amount in the supplied currency to EUROs. |
Money |
convertToEuro(Money money)
Utility class to convert one Money to EURO denominated Money. |
static CurrencyConverter |
getCurrencyConverter()
Returns a default instance of the currency converter. |
static CurrencyConverter |
getCurrencyConverter(String resource)
Returns the singleton currency converter, or creates one based on the resource file supplied. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static CurrencyConverter THE_CURR_CON
protected static Map EXCHANGE
| Constructor Detail |
protected CurrencyConverter()
| Method Detail |
public static CurrencyConverter getCurrencyConverter()
public static CurrencyConverter getCurrencyConverter(String resource)
resource - The name of the resource file to use to read the
currencies.
public BigDecimal convertToEuro(Currency currency,
BigDecimal amount)
currency - The currency the amount is denominated in.amount - The amount of cents.
NullPointerException - if we have no rate for the currency
supplied.public Money convertToEuro(Money money)
money - The money to convert
public Money convertFromEuro(Money money,
Currency currency)
money - The money to convert.currency - The currencty to convert this money to.
NullPointerException - if we have no rate for the currency
supplied.
public Money convert(Money from,
Currency tocurrency)
from - The money to convert from.tocurrency - The currency to convert the money to.
public void buildMap(ResourceBundle rates)
rates - The resource bundle containing currency code = exchange
values.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||