public interface CurrencyConversion extends MonetaryOperator
CurrencyConversion that is converting a MonetaryAmount to another
MonetaryAmount with a different target CurrencyUnit. Each instance of this class is bound to
a specific ExchangeRateProvider (or a chain of rate providers), a term CurrencyUnit and
(optionally) a target timestamp. Additionally the ConversionContext can have additional
attributes set that are passed to the rate provider (chain).MonetaryConversionsSpi implementation.MonetaryOperator currency conversion can simply be applied on each MonetaryAmount
calling the amount'0s with method:
MonetaryAmount amount = ...;
CurrencyConversion conversion = MonetaryConversions.getCurrencyConversion("CHF");
MonetaryAmount amountInCHF = amount.with(conversion);
Instances of this class are required to be thread-safe, but it is not a requirement that they are serializable. In a EE context they can be implemented using contextual beans.
| Modifier and Type | Method and Description |
|---|---|
ConversionContext |
getConversionContext()
Access the target
ConversionContext of this conversion instance. |
ExchangeRate |
getExchangeRate(MonetaryAmount sourceAmount)
Get the
ExchangeRate applied for the given MonetaryAmount
. |
CurrencyUnit |
getTermCurrency()
Access the terminating
CurrencyUnit of this conversion instance. |
CurrencyConversion |
with(ConversionContext conversionContext)
Get a new
CurrencyConversionusing the given
ConversionContext with additional attributes. |
applyConversionContext getConversionContext()
ConversionContext of this conversion instance.ConversionContext.ExchangeRate getExchangeRate(MonetaryAmount sourceAmount)
ExchangeRate applied for the given MonetaryAmount
.sourceAmount - the amount to be converted.ExchangeRate applied.MonetaryException - if the amount can not be converted.CurrencyUnit getTermCurrency()
CurrencyUnit of this conversion instance.CurrencyUnit , never null.CurrencyConversion with(ConversionContext conversionContext)
CurrencyConversionusing the given
ConversionContext with additional attributes.conversionContext - the ConversionContext to be applied, not nullCurrencyConversion, based on this
instance, but with a changed ConversionContext to be
applied. if the amount can not be converted.