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
-
NOT_FOUND
- Used to indicate that an exchange rate is not found in the table.
-
ExchangeRateTable()
- Creates an empty exchange rate table.
-
add(ExchangeRate)
- Adds the given exchange rate to this table.
-
clear()
- Clears all of the exchange rates from this table.
-
contains(ExchangeRate)
- Returns true if an exchange rate already exists with this rate's source,
target pair.
-
contains(String, String)
- Returns true if an exchange rate already exists with this source and
target.
-
elements()
- Returns all of the exchange rates in an enumeration.
-
enterExchangeRate(String, String, double)
- Adds the exchange rate specified by the source, target and factor values.
-
entries()
- Returns the number of exchange rates in this table.
-
findConversionFactor(String, String)
- Finds the exchange rate that includes the specified source and target currencies
and returns its conversion factor.
-
findExchangeRate(String, String)
- Finds the exchange rate that includes the specified source and target currencies.
-
initialize(Reader)
- Clears this table of all rates and initializes it with new ones from the reader.
-
read(Reader)
- Creates a new exchange rate table and initializes it with exchange rates.
-
remove(ExchangeRate)
- Removes this exchange rate from the table.
-
remove(String, String)
- Removes the exchange rate from the table described by the source, target
pair.
-
replace(ExchangeRate)
- Replaces the exchange rate in the table which has the same source and target
as the specified one with this new rate.
-
setFactor(String, String, double)
- Replaces the currency exchange rate that matches the source, target pair with
this specified new conversion factor.
-
write(Writer)
- Persists the table's exchange rates to this writer.
NOT_FOUND
public static final double NOT_FOUND
- Used to indicate that an exchange rate is not found in the table.
ExchangeRateTable
public ExchangeRateTable()
- Creates an empty exchange rate table.
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
entries
public int entries()
- Returns the number of exchange rates in this table.
- Returns:
- the size
clear
public void clear()
- Clears all of the exchange rates from this table.
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
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
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
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
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
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
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
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
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
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
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
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
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