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 ProviderContextgetContext()Access theConversionContextfor thisExchangeRateProvider.default CurrencyConversiongetCurrencyConversion(java.lang.String termCode)Access aCurrencyConversionthat can be applied as aMonetaryOperatorto an amount.CurrencyConversiongetCurrencyConversion(ConversionQuery conversionQuery)Access aCurrencyConversionthat can be applied as aMonetaryOperatorto an amount.default CurrencyConversiongetCurrencyConversion(CurrencyUnit term)Access aCurrencyConversionthat can be applied as aMonetaryOperatorto an amount.default ExchangeRategetExchangeRate(java.lang.String baseCode, java.lang.String termCode)Access aExchangeRateusing the given currencies.ExchangeRategetExchangeRate(ConversionQuery conversionQuery)Access aExchangeRateusing the given currencies.default ExchangeRategetExchangeRate(CurrencyUnit base, CurrencyUnit term)Access aExchangeRateusing the given currencies.default ExchangeRategetReversed(ExchangeRate rate)The method reverses theExchangeRateto a rate mapping from term to baseCurrencyUnit.default booleanisAvailable(java.lang.String baseCode, java.lang.String termCode)Checks if anExchangeRatebetween twoCurrencyUnitis available from this provider.default booleanisAvailable(ConversionQuery conversionQuery)Checks if anExchangeRatebetween twoCurrencyUnitis available from this provider.default booleanisAvailable(CurrencyUnit base, CurrencyUnit term)Checks if anExchangeRatebetween twoCurrencyUnitis available from this provider.
-
Method Details
-
getContext
ProviderContext getContext()Access theConversionContextfor thisExchangeRateProvider. Each instance ofExchangeRateProviderprovides conversion data for exact oneConversionContext.- Returns:
- the exchange rate type, never
null.
-
getExchangeRate
Access aExchangeRateusing the given currencies. TheExchangeRatemay 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 aCurrencyConversionthat can be applied as aMonetaryOperatorto 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 anExchangeRatebetween twoCurrencyUnitis available from this provider. This method should check, if a given rate is currently defined.- Parameters:
conversionQuery- the requiredConversionQuery, notnull- Returns:
true, if such anExchangeRateis currently defined.
-
getExchangeRate
Access aExchangeRateusing the given currencies. TheExchangeRatemay be, depending on the data provider, real-time or deferred. This method should return the rate that is currently valid.- Parameters:
base- baseCurrencyUnit, notnullterm- termCurrencyUnit, notnull- Returns:
- the matching
ExchangeRate. - Throws:
CurrencyConversionException- If no such rate is available.
-
getCurrencyConversion
Access aCurrencyConversionthat can be applied as aMonetaryOperatorto an amount.- Parameters:
term- termCurrencyUnit, notnull- Returns:
- a new instance of a corresponding
CurrencyConversion, nevernull.
-
isAvailable
Checks if anExchangeRatebetween twoCurrencyUnitis available from this provider. This method should check, if a given rate is currently defined.- Parameters:
base- the baseCurrencyUnitterm- the termCurrencyUnit- Returns:
true, if such anExchangeRateis currently defined.
-
isAvailable
default boolean isAvailable(java.lang.String baseCode, java.lang.String termCode)Checks if anExchangeRatebetween twoCurrencyUnitis 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 anExchangeRateis currently defined.- Throws:
MonetaryException- if one of the currency codes passed is not valid.
-
getExchangeRate
Access aExchangeRateusing the given currencies. TheExchangeRatemay 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, notnulltermCode- 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 theExchangeRateto 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 aCurrencyConversionthat can be applied as aMonetaryOperatorto 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.
-