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 SummaryModifier 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- 
getContextProviderContext getContext()Access theConversionContextfor thisExchangeRateProvider. Each instance ofExchangeRateProviderprovides conversion data for exact oneConversionContext.- Returns:
- the exchange rate type, never null.
 
- 
getExchangeRateAccess 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 required- ConversionQuery, not- null
- 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
 
- 
getCurrencyConversionAccess aCurrencyConversionthat can be applied as aMonetaryOperatorto an amount.- Parameters:
- conversionQuery- the required- ConversionQuery, not- null
- Returns:
- a new instance of a corresponding CurrencyConversion, nevernull.
- Throws:
- MonetaryException- if one of the currency codes passed is not valid.
- See Also:
- ConversionQueryBuilder
 
- 
isAvailableChecks if anExchangeRatebetween twoCurrencyUnitis available from this provider. This method should check, if a given rate is currently defined.- Parameters:
- conversionQuery- the required- ConversionQuery, not- null
- Returns:
- true, if such an- ExchangeRateis currently defined.
 
- 
getExchangeRateAccess 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- base- CurrencyUnit, not- null
- term- term- CurrencyUnit, not- null
- Returns:
- the matching ExchangeRate.
- Throws:
- CurrencyConversionException- If no such rate is available.
 
- 
getCurrencyConversionAccess aCurrencyConversionthat can be applied as aMonetaryOperatorto an amount.- Parameters:
- term- term- CurrencyUnit, not- null
- Returns:
- a new instance of a corresponding CurrencyConversion, nevernull.
 
- 
isAvailableChecks if anExchangeRatebetween twoCurrencyUnitis available from this provider. This method should check, if a given rate is currently defined.- Parameters:
- base- the base- CurrencyUnit
- term- the term- CurrencyUnit
- Returns:
- true, if such an- ExchangeRateis currently defined.
 
- 
isAvailabledefault 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 code
- termCode- the terminal/target currency code
- Returns:
- true, if such an- ExchangeRateis currently defined.
- Throws:
- MonetaryException- if one of the currency codes passed is not valid.
 
- 
getExchangeRateAccess 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, not- null
- termCode- term/target currency code, not- null
- Returns:
- the matching ExchangeRate.
- Throws:
- CurrencyConversionException- If no such rate is available.
- MonetaryException- if one of the currency codes passed is not valid.
 
- 
getReversedThe 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, not- null
- Returns:
- the matching reversed ExchangeRate, ornull, if the rate cannot be reversed.
 
- 
getCurrencyConversionAccess aCurrencyConversionthat can be applied as aMonetaryOperatorto an amount.- Parameters:
- termCode- terminal/target currency code, not- null
- Returns:
- a new instance of a corresponding CurrencyConversion, nevernull.
- Throws:
- MonetaryException- if one of the currency codes passed is not valid.
 
 
-