public interface ExchangeRateOperations
ExchangeRate
s. Object implementing this interface are contextual objects
operating on "current" ExchangeRate. Some operations modify the underlying ExchageRate and others just perform
operations using the underlying ExchangeRate. The reasoning behind having this can of object is that one can create
such an object with the given settings and then perform serveral operations with the same settings.Modifier and Type | Method and Description |
---|---|
ExchangeRateOperations |
combine(ExchangeRate other)
Combines
ExchangeRate represented by this object with the given one. |
BigMoney |
exchange(BigMoney toExchange)
Converts the given
value in currency to value in the other currency using the underlying
ExchangeRate. |
Money |
exchange(Money toExchange)
Converts the given
value in currency to value in the other currency returning an instance of
Money . |
ExchangeRate |
getExchangeRate()
Returns the current ExchangeRate.
|
ExchangeRateOperations |
invert()
Inverts the underlying ExchangeRate.
|
BigMoney exchange(BigMoney toExchange)
value in currency
to value in the other currency using the underlying
ExchangeRate. The conversion is possible if either source or target currency of the exchange rate represented by
this object matches the currency of the given BigMoney
.toExchange
- the value in currency to be convertedNullPointerException
- if the given parameter is null
NotExchangeableException
- if exchange rate represented by this object cannot be used for conversion of the
given Money
Money exchange(Money toExchange)
value in currency
to value in the other currency returning an instance of
Money
.toExchange
- the value in currency to be exchangedexchange(BigMoney)
ExchangeRateOperations invert()
getExchangeRate()
.ExchangeRateOperations combine(ExchangeRate other)
ExchangeRate
represented by this object with the given one. This ExchangeRate
and the
given one have to have a common currency no matter the position "source" or "target".
This object's non common currency will become the target currency and the other object's non common currency will
become the source currency of the returned object. The common currency will "disappear".
this rate: 1 USD = 3.50 PLN other rate: 1 EUR = 4.00 PLN this.combine(other) results in 1 USD = 0.8750 EUR other.combine(this) results in 1 EUR = 1.1429 USD (rounded to 4 decimal places *)A special case is when exchange rates for the same sets of currencies are combined no matter the position. In this case they may or may not differ on the rate field. Combining two such exchange rate will result in "identity" rate for
this
rate's target currency.
this rate: 1 EUR = 3.22 PLN other rate: 1 EUR = 3.19 PLN this.combine(other) results in 1 EUR = 1 EUR.The resulting ExchangeRate will have the scale and roundingMode of this instance.
* rounding for this example only, internally scale may be greater
other
- the exchange rate to be combine with this instanceNullPointerException
- if the other object is nullNoCommonCurrencyException
- if objects this and other have no common currency which means that it is
impossible to create a combination of the two exchange ratesExchangeRate getExchangeRate()
Copyright © 2009-2012 Joda.org. All Rights Reserved.