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