Venice 0.751beta

nz.org.venice.util
Class ExchangeRateCache

java.lang.Object
  extended bynz.org.venice.util.ExchangeRateCache

public class ExchangeRateCache
extends java.lang.Object

Cache of exchange rates. This class caches exchange rates in memory from the database. It is also responsible for importing the exchange rates, saving them into the database, loading them from database, and querying the user for exchange rates. It also provides helper functions to make performing cross-currency calculations easier.

Author:
Andrew Leppard

Method Summary
 Money add(TradingDate date, Money destinationMoney, Money sourceMoney)
          Add the two given monies.
 Money exchange(TradingDate date, Money money, Currency currency)
          Exchange the given money for the given currency.
static ExchangeRateCache getInstance()
          Create or return the singleton instance of the exchange rate cache.
 double getRate(TradingDate date, Currency sourceCurrency, Currency destinationCurrency)
          Return the exchange rate between the two currencies on the given date.
 void setDesktopPane(javax.swing.JDesktopPane desktopPane)
          Inform the exchange rate cache of the desktop which will be used to display dialogs.
 Money subtract(TradingDate date, Money destinationMoney, Money sourceMoney)
          Subtract the two given monies.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ExchangeRateCache getInstance()
Create or return the singleton instance of the exchange rate cache.

Returns:
singleton instance of this class

setDesktopPane

public void setDesktopPane(javax.swing.JDesktopPane desktopPane)
Inform the exchange rate cache of the desktop which will be used to display dialogs.

Parameters:
desktopPane - the desktop pane to use

getRate

public double getRate(TradingDate date,
                      Currency sourceCurrency,
                      Currency destinationCurrency)
Return the exchange rate between the two currencies on the given date.

Parameters:
date - the date for the exchange
sourceCurrency - the source currency to convert from
destinationCurrency - the destination currency to convert to

add

public Money add(TradingDate date,
                 Money destinationMoney,
                 Money sourceMoney)
Add the two given monies. This function will perform currency conversion if necessary.

Parameters:
date - the date for the exchange
destinationMoney - the "destination" money.
sourceMoney - the "source" money
Returns:
the sum of the two monies in the same currency as the "destination" money.

subtract

public Money subtract(TradingDate date,
                      Money destinationMoney,
                      Money sourceMoney)
Subtract the two given monies. The "source" money will be subtracted from the "destination" money. This function will perform currency conversion if necessary.

Parameters:
date - the date for the exchange
destinationMoney - the "destination" money.
sourceMoney - the "source" money
Returns:
the subtraction of "source" money from "destination" money in the same currency as the "destination" money.

exchange

public Money exchange(TradingDate date,
                      Money money,
                      Currency currency)
Exchange the given money for the given currency. Use the exchange rate that is valid on the given date.

Parameters:
date - the date for the exchange
money - the money to convert
currency - the currency to convert to
Returns:
the converted currency.

Venice 0.751beta