public interface ExchangeRateProvider
This interface defines access to the exchange rates provided by a provider.
The provider and its capabilities can be defined in arbitrary detail by the
corresponding
ProviderContext
.
Instances of this class must only provide conversion data for exact one provider, identified by
AbstractContext.getProviderName()
.
When accessing ExchangeRateProvider instances or CurrencyConversion
instances from the
MonetaryConversions
in many cases a chain of providers will be returned. It is the responsibility of the implementation code assembling
the chain to
establish a well defined coordination mechanism for evaluating the correct result. By default the first provider
in the chain that returns a non null result determines the final result of a call. Nevertheless adapting the
MonetaryConversionsSingletonSpi
allows
to implement also alternate strategies, e.g. honoring different priorities of providers as well.
Implementations of this interface are required to be thread save.
Implementations of this class must neither be immutable nor serializable.
- Author:
- Anatole Tresch, Werner Keil
-
Method Summary
Modifier and Type Method Description ProviderContext
getContext()
Access theConversionContext
for thisExchangeRateProvider
.default CurrencyConversion
getCurrencyConversion(java.lang.String termCode)
Access aCurrencyConversion
that can be applied as aMonetaryOperator
to an amount.CurrencyConversion
getCurrencyConversion(ConversionQuery conversionQuery)
Access aCurrencyConversion
that can be applied as aMonetaryOperator
to an amount.default CurrencyConversion
getCurrencyConversion(CurrencyUnit term)
Access aCurrencyConversion
that can be applied as aMonetaryOperator
to an amount.default ExchangeRate
getExchangeRate(java.lang.String baseCode, java.lang.String termCode)
Access aExchangeRate
using the given currencies.ExchangeRate
getExchangeRate(ConversionQuery conversionQuery)
Access aExchangeRate
using the given currencies.default ExchangeRate
getExchangeRate(CurrencyUnit base, CurrencyUnit term)
Access aExchangeRate
using the given currencies.default ExchangeRate
getReversed(ExchangeRate rate)
The method reverses theExchangeRate
to a rate mapping from term to baseCurrencyUnit
.default boolean
isAvailable(java.lang.String baseCode, java.lang.String termCode)
Checks if anExchangeRate
between twoCurrencyUnit
is available from this provider.default boolean
isAvailable(ConversionQuery conversionQuery)
Checks if anExchangeRate
between twoCurrencyUnit
is available from this provider.default boolean
isAvailable(CurrencyUnit base, CurrencyUnit term)
Checks if anExchangeRate
between twoCurrencyUnit
is available from this provider.
-
Method Details
-
getContext
ProviderContext getContext()Access theConversionContext
for thisExchangeRateProvider
. Each instance ofExchangeRateProvider
provides conversion data for exact oneConversionContext
.- Returns:
- the exchange rate type, never
null
.
-
getExchangeRate
Access aExchangeRate
using the given currencies. TheExchangeRate
may be, depending on the data provider, real-time or deferred. This method should return the rate that is currently valid.- Parameters:
conversionQuery
- the requiredConversionQuery
, notnull
- Returns:
- the matching
ExchangeRate
. - Throws:
CurrencyConversionException
- If no such rate is available.MonetaryException
- if one of the currency codes passed is not valid.- See Also:
ConversionQueryBuilder
-
getCurrencyConversion
Access aCurrencyConversion
that can be applied as aMonetaryOperator
to an amount.- Parameters:
conversionQuery
- the requiredConversionQuery
, notnull
- Returns:
- a new instance of a corresponding
CurrencyConversion
, nevernull
. - Throws:
MonetaryException
- if one of the currency codes passed is not valid.- See Also:
ConversionQueryBuilder
-
isAvailable
Checks if anExchangeRate
between twoCurrencyUnit
is available from this provider. This method should check, if a given rate is currently defined.- Parameters:
conversionQuery
- the requiredConversionQuery
, notnull
- Returns:
true
, if such anExchangeRate
is currently defined.
-
getExchangeRate
Access aExchangeRate
using the given currencies. TheExchangeRate
may be, depending on the data provider, real-time or deferred. This method should return the rate that is currently valid.- Parameters:
base
- baseCurrencyUnit
, notnull
term
- termCurrencyUnit
, notnull
- Returns:
- the matching
ExchangeRate
. - Throws:
CurrencyConversionException
- If no such rate is available.
-
getCurrencyConversion
Access aCurrencyConversion
that can be applied as aMonetaryOperator
to an amount.- Parameters:
term
- termCurrencyUnit
, notnull
- Returns:
- a new instance of a corresponding
CurrencyConversion
, nevernull
.
-
isAvailable
Checks if anExchangeRate
between twoCurrencyUnit
is available from this provider. This method should check, if a given rate is currently defined.- Parameters:
base
- the baseCurrencyUnit
term
- the termCurrencyUnit
- Returns:
true
, if such anExchangeRate
is currently defined.
-
isAvailable
default boolean isAvailable(java.lang.String baseCode, java.lang.String termCode)Checks if anExchangeRate
between twoCurrencyUnit
is available from this provider. This method should check, if a given rate is currently defined.- Parameters:
baseCode
- the base currency codetermCode
- the terminal/target currency code- Returns:
true
, if such anExchangeRate
is currently defined.- Throws:
MonetaryException
- if one of the currency codes passed is not valid.
-
getExchangeRate
Access aExchangeRate
using the given currencies. TheExchangeRate
may be, depending on the data provider, real-time or deferred. This method should return the rate that is currently valid.- Parameters:
baseCode
- base currency code, notnull
termCode
- term/target currency code, notnull
- Returns:
- the matching
ExchangeRate
. - Throws:
CurrencyConversionException
- If no such rate is available.MonetaryException
- if one of the currency codes passed is not valid.
-
getReversed
The method reverses theExchangeRate
to a rate mapping from term to baseCurrencyUnit
. Hereby the factor must not be recalculated as1/oldFactor
, since typically reverse rates are not symmetric in most cases.- Parameters:
rate
-ExchangeRate
, notnull
- Returns:
- the matching reversed
ExchangeRate
, ornull
, if the rate cannot be reversed.
-
getCurrencyConversion
Access aCurrencyConversion
that can be applied as aMonetaryOperator
to an amount.- Parameters:
termCode
- terminal/target currency code, notnull
- Returns:
- a new instance of a corresponding
CurrencyConversion
, nevernull
. - Throws:
MonetaryException
- if one of the currency codes passed is not valid.
-