All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.money.currency.v1_0.ExchangeRate

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

public class ExchangeRate
extends Object
ExchangeRate encapsulates a source currency, a target currency, and a conversion factor, which is, by convention, a multiplicative conversion factor. This means that the source currency amount is multiplied by the conversion factor to obtain the equivalent amount in the target currency. Source and target currencies are stored by their mnemonics and the conversion factor is stored as a double precision floating point number.

Author:
Trevor Misfeldt
See Also:
ExchangeRateTable, FactoryExample, GroupExample

Constructor Index

 o ExchangeRate()
Creates an empty exchange rate.
 o ExchangeRate(String, String, double)
Creates an exchange rate with the specifed source currency, target currency and multiplicative conversion factor.

Method Index

 o equals(ExchangeRate)
Returns true if this exchange rate and specified exchange rate have identical source currencies, target currencies and conversion factors.
 o getConversionFactor()
Returns the conversion factor for source to target currency conversion.
 o getSource()
Returns the source currency.
 o getTarget()
Returns the target currency.
 o isValid()
Checks to see if this exchange rate has its source, target and factor fields set to non-default values.
 o read(Reader)
Reads in data values and initializes a new exchange rate with those values.
 o sameSourceAndTarget(ExchangeRate)
Tests whether the specified rate has the same source and target currencies.
 o setConversionFactor(double)
Sets the conversion factor which when multiplied by a source amount gives a target amount.
 o setSource(String)
Sets the source currency.
 o setTarget(String)
Sets the target currency.
 o toString()
Returns a string representation of this exchange rate.
 o write(Writer)
Persists this rate to a writer.

Constructors

 o ExchangeRate
 public ExchangeRate()
Creates an empty exchange rate.

 o ExchangeRate
 public ExchangeRate(String source,
                     String target,
                     double factor)
Creates an exchange rate with the specifed source currency, target currency and multiplicative conversion factor. In other words, an amount in currency source when multiplied by factor will give an equivalent amount in currency target.

Parameters:
source - the source currency mnemonic
target - the target currency mnemonic
factor - a double where source * factor = target

Methods

 o getSource
 public String getSource()
Returns the source currency.

Returns:
the source currency mnemonic
 o setSource
 public void setSource(String source)
Sets the source currency.

Parameters:
source - the source currency mnemonic
 o getTarget
 public String getTarget()
Returns the target currency.

Returns:
the target currency mnemonic
 o setTarget
 public void setTarget(String target)
Sets the target currency.

Parameters:
target - the target currency mnemonic
 o getConversionFactor
 public double getConversionFactor()
Returns the conversion factor for source to target currency conversion.

Returns:
the conversion factor
 o setConversionFactor
 public void setConversionFactor(double factor)
Sets the conversion factor which when multiplied by a source amount gives a target amount.

Parameters:
factor - the conversion factor
 o sameSourceAndTarget
 public boolean sameSourceAndTarget(ExchangeRate rate)
Tests whether the specified rate has the same source and target currencies.

Parameters:
rate - the exchange rate to test
Returns:
whether the source and target currencies are equal
 o equals
 public boolean equals(ExchangeRate rate)
Returns true if this exchange rate and specified exchange rate have identical source currencies, target currencies and conversion factors.

Parameters:
rate - the rate for comparison
Returns:
whether the rates are equal or not
 o write
 public Writer write(Writer writer) throws IOException
Persists this rate to a writer. Format is as follows:

 BEGIN_EXCHANGE
 source=USD
 target=CAD
 factor=1.556
 END_EXCHANGE
 

Parameters:
writer - The writer to which the data will be output. Note: The writer will not be flushed or closed.
Returns:
the writer
 o read
 public static ExchangeRate read(Reader reader) throws IOException
Reads in data values and initializes a new exchange rate with those values. Name-value pairs can be in any order. 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
 factor=1.556
 END_EXCHANGE
 

Parameters:
reader - The reader from which data will be read. Note: The reader is not closed.
Returns:
A new, initialized exchange rate.
 o toString
 public String toString()
Returns a string representation of this exchange rate. Format is as follows:

 BEGIN_EXCHANGE
 source=USD
 target=CAD
 factor=1.556
 END_EXCHANGE
 

Returns:
the string
Overrides:
toString in class Object
 o isValid
 protected boolean isValid()
Checks to see if this exchange rate has its source, target and factor fields set to non-default values.

Returns:
whether this exchange rate is valid or not

All Packages  Class Hierarchy  This Package  Previous  Next  Index