All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.money.currency.v1_0.ExchangeRateTable

java.lang.Object
   |
   +----com.roguewave.money.currency.v1_0.ExchangeRateTable

public class ExchangeRateTable
extends Object
Class ExchangeRateTable stores exchange rates as unique pairs of source and target currencies. No two exchange rates in the table have the same source-target currency pair. The ExchangeRateTable class can be initialized from a reader. The format for the stream is:

 ...
 BEGIN_EXCHANGE
 source=USD
 target=CAD
 rate=1.5334
 END_EXCHANGE
 BEGIN_EXCHANGE
 source=JPY
 target=GBP
 rate=133.23
 END_EXCHANGE
 ...
 

Author:
Trevor Misfeldt
See Also:
ExchangeRate, FactoryExample, GroupExample, MoneyCalculatorExample

Variable Index

 o NOT_FOUND
Used to indicate that an exchange rate is not found in the table.

Constructor Index

 o ExchangeRateTable()
Creates an empty exchange rate table.

Method Index

 o add(ExchangeRate)
Adds the given exchange rate to this table.
 o clear()
Clears all of the exchange rates from this table.
 o contains(ExchangeRate)
Returns true if an exchange rate already exists with this rate's source, target pair.
 o contains(String, String)
Returns true if an exchange rate already exists with this source and target.
 o elements()
Returns all of the exchange rates in an enumeration.
 o enterExchangeRate(String, String, double)
Adds the exchange rate specified by the source, target and factor values.
 o entries()
Returns the number of exchange rates in this table.
 o findConversionFactor(String, String)
Finds the exchange rate that includes the specified source and target currencies and returns its conversion factor.
 o findExchangeRate(String, String)
Finds the exchange rate that includes the specified source and target currencies.
 o initialize(Reader)
Clears this table of all rates and initializes it with new ones from the reader.
 o read(Reader)
Creates a new exchange rate table and initializes it with exchange rates.
 o remove(ExchangeRate)
Removes this exchange rate from the table.
 o remove(String, String)
Removes the exchange rate from the table described by the source, target pair.
 o replace(ExchangeRate)
Replaces the exchange rate in the table which has the same source and target as the specified one with this new rate.
 o setFactor(String, String, double)
Replaces the currency exchange rate that matches the source, target pair with this specified new conversion factor.
 o write(Writer)
Persists the table's exchange rates to this writer.

Variables

 o NOT_FOUND
 public static final double NOT_FOUND
Used to indicate that an exchange rate is not found in the table.

Constructors

 o ExchangeRateTable
 public ExchangeRateTable()
Creates an empty exchange rate table.

Methods

 o elements
 public Enumeration elements()
Returns all of the exchange rates in an enumeration. For example,

 Enumeration rates = myTable.elements();
 while(rates.hasMoreElements()) {
   ExchangeRate rate = (ExchangeRate)elements.nextElement();
   System.out.println(rate);
 }
 

Returns:
the collection of exchange rates
 o entries
 public int entries()
Returns the number of exchange rates in this table.

Returns:
the size
 o clear
 public void clear()
Clears all of the exchange rates from this table.

 o findExchangeRate
 public ExchangeRate findExchangeRate(String source,
                                      String target)
Finds the exchange rate that includes the specified source and target currencies.

Parameters:
source - the source currency mnemonic
target - the target currency mnemonic
Returns:
The exchange rate or a null value if it cannot be be found.
See Also:
ExchangeRate
 o findConversionFactor
 public double findConversionFactor(String source,
                                    String target)
Finds the exchange rate that includes the specified source and target currencies and returns its conversion factor.

Parameters:
source - the source currency mnemonic
target - the target currency mnemonic
Returns:
The conversion factor or NOT_FOUND if it cannot be be found.
See Also:
NOT_FOUND
 o add
 public synchronized void add(ExchangeRate rate)
Adds the given exchange rate to this table. If a current rate exists for the source, target pair then it is replaced by this new one.

Parameters:
rate - the new exchange rate
See Also:
ExchangeRate
 o enterExchangeRate
 public synchronized void enterExchangeRate(String source,
                                            String target,
                                            double factor)
Adds the exchange rate specified by the source, target and factor values. If a a current rate exists for the source, target pair then it is replaced by this new one.

Parameters:
source - the source currency mnemonic
target - the target currency mnemonic
factor - the conversion factor
 o remove
 public synchronized boolean remove(ExchangeRate rate)
Removes this exchange rate from the table.

Parameters:
rate - the exchange rate to remove
Returns:
whether the rate existed or not
See Also:
ExchangeRate
 o remove
 public synchronized boolean remove(String source,
                                    String target)
Removes the exchange rate from the table described by the source, target pair.

Parameters:
source - the source currency mnemonic
target - the target currency mnemonic
Returns:
whether the rate existed or not
 o replace
 public synchronized boolean replace(ExchangeRate rate)
Replaces the exchange rate in the table which has the same source and target as the specified one with this new rate.

Parameters:
rate - the new exchange rate
Returns:
whether this rate already existed in the table
See Also:
ExchangeRate
 o setFactor
 public synchronized boolean setFactor(String source,
                                       String target,
                                       double factor)
Replaces the currency exchange rate that matches the source, target pair with this specified new conversion factor.

Parameters:
source - the source currency mnemonic
target - the target currency mnemonic
factor - the new conversion factor
Returns:
whether this rate already existed in the table
 o contains
 public boolean contains(ExchangeRate rate)
Returns true if an exchange rate already exists with this rate's source, target pair.

Parameters:
rate - the exchange rate for comparison
Returns:
whether an exchange rate already existed for the source, target pair
See Also:
ExchangeRate
 o contains
 public boolean contains(String source,
                         String target)
Returns true if an exchange rate already exists with this source and target.

Parameters:
source - the source currency mnemonic
target - the target currency mnemonic
Returns:
whether an exchange rate already existed for the source, target pair
 o write
 public void write(Writer writer) throws IOException
Persists the table's exchange rates to this writer. The format looks like:

 
 ...
 BEGIN_EXCHANGE
 source=USD
 target=CAD
 rate=1.5334
 END_EXCHANGE
 BEGIN_EXCHANGE
 source=JPY
 target=GBP
 rate=133.23
 END_EXCHANGE
 ...
 

Parameters:
writer - The writer to which the data is output. Note: The writer is neither flushed or closed.
Returns:
the writer
See Also:
ExchangeRate, write
 o initialize
 public void initialize(Reader reader) throws IOException
Clears this table of all rates and initializes it with new ones from the reader. A field without a value or a missing field will be set to the default value. Format is as follows:

 
 ...
 BEGIN_EXCHANGE
 source=USD
 target=CAD
 rate=1.5334
 END_EXCHANGE
 BEGIN_EXCHANGE
 source=JPY
 target=GBP
 rate=133.23
 END_EXCHANGE
 ...
 

Parameters:
reader - The reader from which data will be read. Note: The reader is not closed.
Returns:
the initialized exchange rate table
See Also:
ExchangeRate, read
 o read
 public static ExchangeRateTable read(Reader reader) throws IOException
Creates a new exchange rate table and initializes it with exchange rates. A field without a value or a missing field will be set to the default value. Format is as follows:

 
 ...
 BEGIN_EXCHANGE
 source=USD
 target=CAD
 rate=1.5334
 END_EXCHANGE
 BEGIN_EXCHANGE
 source=JPY
 target=GBP
 rate=133.23
 END_EXCHANGE
 ...
 

Parameters:
reader - The reader from which data will be read. Note: The reader is not closed.
Returns:
a new, initialized exchange rate table
See Also:
ExchangeRate, read

All Packages  Class Hierarchy  This Package  Previous  Next  Index