org.davesag.generica.util
Class CurrencyConverter

java.lang.Object
  extended byorg.davesag.generica.util.CurrencyConverter

public class CurrencyConverter
extends Object

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.

Since:
Generica 1.0
Version:
CVS Revision $Id: CurrencyConverter.java,v 1.9 2004/03/30 13:00:43 davesag Exp $
Author:
Dave Sag http://www.davesag.com

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

THE_CURR_CON

protected static CurrencyConverter THE_CURR_CON
the singleton class


EXCHANGE

protected static Map EXCHANGE
the map of exchange rates

Constructor Detail

CurrencyConverter

protected CurrencyConverter()
default contructor for internal use only. use getCurrencyConverter()

Method Detail

getCurrencyConverter

public static CurrencyConverter getCurrencyConverter()
Returns a default instance of the currency converter. use this if you are happy using the exchange rate table I wrote.

Returns:
An instance of a currency converter.

getCurrencyConverter

public static CurrencyConverter getCurrencyConverter(String resource)
Returns the singleton currency converter, or creates one based on the resource file supplied.

Parameters:
resource - The name of the resource file to use to read the currencies.
Returns:
The currency converter.

convertToEuro

public BigDecimal convertToEuro(Currency currency,
                                BigDecimal amount)
Converts the supplied amount in the supplied currency to EUROs.

Parameters:
currency - The currency the amount is denominated in.
amount - The amount of cents.
Returns:
A converted whole number of euro cents.
Throws:
NullPointerException - if we have no rate for the currency supplied.

convertToEuro

public Money convertToEuro(Money money)
Utility class to convert one Money to EURO denominated Money.

Parameters:
money - The money to convert
Returns:
The new money.

convertFromEuro

public Money convertFromEuro(Money money,
                             Currency currency)
Utility class to converto a Money to an equivalent value in a different currency.

Parameters:
money - The money to convert.
currency - The currencty to convert this money to.
Returns:
The converted Money.
Throws:
NullPointerException - if we have no rate for the currency supplied.

convert

public Money convert(Money from,
                     Currency tocurrency)
Utility class to converto a Money to an equivalent value in a different currency.

Parameters:
from - The money to convert from.
tocurrency - The currency to convert the money to.
Returns:
The converted Money.

buildMap

public void buildMap(ResourceBundle rates)
Builds the exchange map from the resource bundle provided.

Parameters:
rates - The resource bundle containing currency code = exchange values.


Dave Sag Generica API version 0.5.9 - (prerelease) Copyright 2003 - 2004 Dave Sag.