Top Description Methods
javax.money.convert

public Interface CurrencyConversion

extends MonetaryOperator, CurrencySupplier
Imports
javax.money.*

This interface defines a CurrencyConversion that is converting a MonetaryAmount to another MonetaryAmount with a different target CurrencyUnit. Each instance of this class is bound to a specific ExchangeRateProvider (or a chain of rate providers), a term CurrencyUnit and (optionally) a target timestamp. Additionally the javax.money.convert.ConversionContext can have additional attributes set that are passed to the rate provider (chain).

This interface serves a an API for the clients, but also must be implemented and registered as SPI to the mechanisms required by the javax.money.spi.MonetaryConversionsSingletonSpi implementation.

By extending MonetaryOperator currency conversion can simply be applied on each MonetaryAmount calling the amount'0s with method:


    MonetaryAmount amount = ...;
    CurrencyConversion conversion = MonetaryConversions.getConversion("CHF");
    MonetaryAmount amountInCHF = amount.with(conversion);

The terminating CurrencyUnit of this conversion instance can be accessed from getCurrency(), inherited from CurrencySupplier.

Instances of this class are required to be thread-safe, but it is not a requirement that they are serializable. In a EE context they can be implemented using contextual beans.

Authors
Anatole Tresch, Werner Keil

Method Summary

Modifier and TypeMethod and Description
public ConversionContext

Returns:

the target ConversionContext.
getContext
()

Access the target ConversionContext of this conversion instance.

public ExchangeRate

Returns:

the ExchangeRate applied.
getExchangeRate
(MonetaryAmount
the amount to be converted.
sourceAmount
)

Get the ExchangeRate applied for the given MonetaryAmount .

public ExchangeRateProvider
Inherited from javax.money.CurrencySupplier:
getCurrency
Inherited from javax.money.MonetaryOperator:
apply

Method Detail

getContextback to summary
public ConversionContext getContext()

Access the target ConversionContext of this conversion instance.

Returns:ConversionContext

the target ConversionContext.

getExchangeRateback to summary
public ExchangeRate getExchangeRate(MonetaryAmount sourceAmount)

Get the ExchangeRate applied for the given MonetaryAmount .

Parameters
sourceAmount:MonetaryAmount

the amount to be converted.

Returns:ExchangeRate

the ExchangeRate applied.

Exceptions
MonetaryException:
if the amount can not be converted.
getExchangeRateProviderback to summary
public ExchangeRateProvider getExchangeRateProvider()

Access the underlying javax.money.convert.ExchangeRateProvider.

Returns:ExchangeRateProvider

the underlying javax.money.convert.ExchangeRateProvider, never null.