-
- All Superinterfaces:
CurrencySupplier,MonetaryOperator
public interface CurrencyConversion extends MonetaryOperator, CurrencySupplier
This interface defines aCurrencyConversionthat is converting aMonetaryAmountto anotherMonetaryAmountwith a different targetCurrencyUnit. Each instance of this class is bound to a specificExchangeRateProvider(or a chain of rate providers), a termCurrencyUnitand (optionally) a target timestamp. Additionally theConversionContextcan have additional attributes set that are passed to the rate provider (chain).This interface serves a an API for the clients, but also must be implemented and registered as SPI to the mechanisms required by the
MonetaryConversionsSingletonSpiimplementation.By extending
MonetaryOperatorcurrency conversion can simply be applied on eachMonetaryAmountcalling the amount'0s with method:MonetaryAmount amount = ...; CurrencyConversion conversion = MonetaryConversions.getConversion("CHF"); MonetaryAmount amountInCHF = amount.with(conversion);The terminating
CurrencyUnitof this conversion instance can be accessed fromgetCurrency(), inherited fromCurrencySupplier.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.
- Author:
- Anatole Tresch, Werner Keil
-
-
Method Summary
Modifier and Type Method Description ConversionContextgetContext()Access the targetConversionContextof this conversion instance.ExchangeRategetExchangeRate(MonetaryAmount sourceAmount)Get theExchangeRateapplied for the givenMonetaryAmount.ExchangeRateProvidergetExchangeRateProvider()Access the underlyingExchangeRateProvider.-
Methods inherited from interface javax.money.CurrencySupplier
getCurrency
-
Methods inherited from interface javax.money.MonetaryOperator
apply
-
-
-
-
Method Detail
-
getContext
ConversionContext getContext()
Access the targetConversionContextof this conversion instance.- Returns:
- the target
ConversionContext.
-
getExchangeRate
ExchangeRate getExchangeRate(MonetaryAmount sourceAmount)
Get theExchangeRateapplied for the givenMonetaryAmount.- Parameters:
sourceAmount- the amount to be converted.- Returns:
- the
ExchangeRateapplied. - Throws:
MonetaryException- if the amount can not be converted.
-
getExchangeRateProvider
ExchangeRateProvider getExchangeRateProvider()
Access the underlyingExchangeRateProvider.- Returns:
- the underlying
ExchangeRateProvider, never null.
-
-