public abstract class BaseExchangeRateProvider extends Object implements javax.money.convert.ExchangeRateProvider
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.
Constructor and Description |
---|
BaseExchangeRateProvider() |
Modifier and Type | Method and Description |
---|---|
javax.money.convert.CurrencyConversion |
getCurrencyConversion(javax.money.CurrencyUnit term)
Access a
CurrencyConversion that can be applied as a
MonetaryOperator to an amount. |
javax.money.convert.CurrencyConversion |
getCurrencyConversion(String termCode)
Access a
CurrencyConversion that can be applied as a
MonetaryOperator to an amount. |
javax.money.convert.ExchangeRate |
getExchangeRate(javax.money.CurrencyUnit base,
javax.money.CurrencyUnit term)
Access a
ExchangeRate using the given currencies. |
javax.money.convert.ExchangeRate |
getExchangeRate(String baseCode,
String termCode)
Access a
ExchangeRate using the given currencies. |
javax.money.convert.ExchangeRate |
getReversed(javax.money.convert.ExchangeRate rate)
The method reverses the
ExchangeRate to a rate mapping from term
to base CurrencyUnit . |
boolean |
isAvailable(javax.money.convert.ConversionQuery conversionQuery)
Checks if an
ExchangeRate between two CurrencyUnit is
available from this provider. |
boolean |
isAvailable(javax.money.CurrencyUnit base,
javax.money.CurrencyUnit term)
Checks if an
ExchangeRate between two CurrencyUnit is
available from this provider. |
boolean |
isAvailable(String baseCode,
String termCode)
Checks if an
ExchangeRate between two CurrencyUnit is
available from this provider. |
public BaseExchangeRateProvider()
public boolean isAvailable(javax.money.convert.ConversionQuery conversionQuery)
ExchangeRate
between two CurrencyUnit
is
available from this provider. This method should check, if a given rate
is currently defined.isAvailable
in interface javax.money.convert.ExchangeRateProvider
conversionQuery
- the required ConversionQuery
, not null
true
, if such an ExchangeRate
is currently
defined.public javax.money.convert.ExchangeRate getExchangeRate(javax.money.CurrencyUnit base, javax.money.CurrencyUnit term)
ExchangeRate
using the given currencies. The
ExchangeRate
may be, depending on the data provider, eal-time or
deferred. This method should return the rate that is currently
valid.getExchangeRate
in interface javax.money.convert.ExchangeRateProvider
base
- base CurrencyUnit
, not null
term
- term CurrencyUnit
, not null
javax.money.convert.CurrencyConversionException
- If no such rate is available.public javax.money.convert.CurrencyConversion getCurrencyConversion(javax.money.CurrencyUnit term)
CurrencyConversion
that can be applied as a
MonetaryOperator
to an amount.getCurrencyConversion
in interface javax.money.convert.ExchangeRateProvider
term
- term CurrencyUnit
, not null
CurrencyConversion
,
never null
.public boolean isAvailable(javax.money.CurrencyUnit base, javax.money.CurrencyUnit term)
ExchangeRate
between two CurrencyUnit
is
available from this provider. This method should check, if a given rate
is currently defined.isAvailable
in interface javax.money.convert.ExchangeRateProvider
base
- the base CurrencyUnit
term
- the term CurrencyUnit
true
, if such an ExchangeRate
is currently
defined.public boolean isAvailable(String baseCode, String termCode)
ExchangeRate
between two CurrencyUnit
is
available from this provider. This method should check, if a given rate
is currently defined.isAvailable
in interface javax.money.convert.ExchangeRateProvider
baseCode
- the base currency codetermCode
- the terminal/target currency codetrue
, if such an ExchangeRate
is currently
defined.javax.money.MonetaryException
- if one of the currency codes passed is not valid.public javax.money.convert.ExchangeRate getExchangeRate(String baseCode, String termCode)
ExchangeRate
using the given currencies. The
ExchangeRate
may be, depending on the data provider, eal-time or
deferred. This method should return the rate that is currently
valid.getExchangeRate
in interface javax.money.convert.ExchangeRateProvider
baseCode
- base currency code, not null
termCode
- term/target currency code, not null
ExchangeRate
.javax.money.convert.CurrencyConversionException
- If no such rate is available.javax.money.MonetaryException
- if one of the currency codes passed is not valid.public javax.money.convert.ExchangeRate getReversed(javax.money.convert.ExchangeRate rate)
ExchangeRate
to a rate mapping from term
to base CurrencyUnit
. Hereby the factor must not be
recalculated as 1/oldFactor
, since typically reverse rates are
not symmetric in most cases.getReversed
in interface javax.money.convert.ExchangeRateProvider
ExchangeRate
, or null
, if
the rate cannot be reversed.public javax.money.convert.CurrencyConversion getCurrencyConversion(String termCode)
CurrencyConversion
that can be applied as a
MonetaryOperator
to an amount.getCurrencyConversion
in interface javax.money.convert.ExchangeRateProvider
termCode
- terminal/target currency code, not null
CurrencyConversion
,
never null
.javax.money.MonetaryException
- if one of the currency codes passed is not valid.Copyright © 2012-2015 JavaMoney. All Rights Reserved.