- All Superinterfaces:
public interface ExchangeRate extends CurrencySupplier
- an exchange rate always models one rate from a base (source) to a term
- an exchange rate is always bound to a rate type, which typically matches the data source of the conversion data, e.g. different credit card providers may use different rates for the same conversion.
- an exchange rate may restrict its validity. In most of the use cases a rates' validity will be well defined, but it is also possible that the data provider is not able to support the rate's validity, leaving it undefined-
- an exchange rate has a provider, which is responsible for defining the rate. A provider hereby may be, but must not be the same as the rate's data source.
- an exchange rate can be a direct rate, where its factor is represented by a single conversion step. Or it can model a derived rate, where multiple conversion steps are required to define the overall base/term conversion. In case of derived rates the chained rates define the overall factor, by multiplying the individual chain rate factors. Of course, this also requires that each subsequent rate's base currency in the chain does match the previous term currency (and vice versa):
- Whereas the factor should be directly implied by the format rate chain for derived rates, this is obviously not the case for the validity range, since rates can have a undefined validity range. Nevertheless in many cases also the validity range can (but must not) be derived from the rate chain.
- Finally a conversion rate is always unidirectional. There might be cases
where the reciprocal value of
getFactor()} matches the correct reverse rate. But in most use cases the reverse rate either has a different rate (not equal to the reciprocal value), or might not be defined at all. Therefore for reversing a ExchangeRate one must access an
ExchangeRateProviderand query for the reverse rate.
The class also implements
Comparable to allow sorting of multiple
exchange rates using the following sorting order;
- Exchange rate type
- Exchange rate provider
- base currency
- term currency
Finally ExchangeRate is modeled as an immutable and thread safe type. Also
exchange rates are
Serializable, hereby serializing in the following
form and order:
- The base
- The target
- The factor (NumberValue)
- The rate chain
Implementations of this interface
- must be Comparable(with
- must implement equals/hashCode considering #getBaseCurrency, #getCurrency, #getFactor and #getContext.
- should be thread-safe
- should be serializable
- should provide a fluent builder API for constructing new rate instances easily.
- Werner Keil, Anatole Tresch
- See Also:
- Wikipedia: Exchange Rate (Quotations)
Modifier and Type Method Description
getBaseCurrency()Get the base (source)
getCurrency()Get the term (target)
getExchangeRateChain()Access the chain of exchange rates.
getFactor()Access the rate's bid factor.
isDerived()Allows to evaluate if this exchange rate is a derived exchange rate.
- the conversion context, never null.
CurrencyUnit getBaseCurrency()Get the base (source)
- the base
CurrencyUnit getCurrency()Get the term (target)
NumberValue getFactor()Access the rate's bid factor.
- the bid factor for this exchange rate, or
java.util.List<ExchangeRate> getExchangeRateChain()Access the chain of exchange rates.
- the chain of rates, in case of a derived rate, this may be
several instances. For a direct exchange rate, this equals to
default boolean isDerived()Allows to evaluate if this exchange rate is a derived exchange rate. Derived exchange rates are defined by an ordered list of subconversions with intermediate steps, whereas a direct conversion is possible in one steps.
This method always returns
true, if the chain contains more than one rate. Direct rates, have also a chain, but with exact one rate.
- true, if the exchange rate is derived.