Top Description Fields Constructors Methods
org.javamoney.moneta.spi

public abstract Class AbstractCurrencyConversion

extends Object
implements CurrencyConversion
Class Inheritance
All Implemented Interfaces
javax.money.convert.CurrencyConversion, javax.money.CurrencySupplier, javax.money.MonetaryOperator
Known Direct Subclasses
org.javamoney.moneta.spi.LazyBoundCurrencyConversion
Imports
javax.money.CurrencyUnit, .MonetaryAmount, .MonetaryOperator, .NumberValue, javax.money.convert.ConversionContext, .CurrencyConversion, .CurrencyConversionException, .ExchangeRate, org.javamoney.moneta.function.MonetaryOperators, java.math.MathContext, .RoundingMode, java.util.Objects

Abstract base class used for implementing currency conversion.
Authors
Anatole Tresch, Werner Keil

Field Summary

Modifier and TypeField and Description
private final ConversionContext
public static final String
private final CurrencyUnit

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public MonetaryAmount

Returns:

The converted amount, never null.
apply
(MonetaryAmount
The source amount
amount
)

Implements javax.money.MonetaryOperator.apply.

Method that converts the source MonetaryAmount to an MonetaryAmount based on the ExchangeRate of this conversion.

public ConversionContext

Returns:

the target ConversionContext.
getContext
()

Implements javax.money.convert.CurrencyConversion.getContext.

Access the target ConversionContext of this conversion instance.

public CurrencyUnit

Returns:

the terminating CurrencyUnit , never null.
getCurrency
()

Implements javax.money.CurrencySupplier.getCurrency.

Access the terminating CurrencyUnit of this conversion instance.

public abstract ExchangeRate

Returns:

the ExchangeRate to be used, or null, if this conversion is not supported (will lead to a CurrencyConversionException.
getExchangeRate
(MonetaryAmount sourceAmount)

Redeclares javax.money.convert.CurrencyConversion.getExchangeRate.

Get the exchange rate type that this MonetaryOperator instance is using for conversion.

protected NumberValue

Returns:

the new rounding factor, never null.
roundFactor
(MonetaryAmount
the amount, not null.
amount
,
NumberValue
the factor
factor
)

Optionally rounds the factor to be used.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public abstract CurrencyConversion
with(ConversionContext conversionContext)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

conversionContextback to summary
private final ConversionContext conversionContext
KEY_SCALEback to summary
public static final String KEY_SCALE
termCurrencyback to summary
private final CurrencyUnit termCurrency

Constructor Detail

AbstractCurrencyConversionback to summary
public AbstractCurrencyConversion(CurrencyUnit termCurrency, ConversionContext conversionContext)

Method Detail

applyback to summary
public MonetaryAmount apply(MonetaryAmount amount)

Implements javax.money.MonetaryOperator.apply.

Method that converts the source MonetaryAmount to an MonetaryAmount based on the ExchangeRate of this conversion.

Parameters
amount:MonetaryAmount

The source amount

Returns:MonetaryAmount

The converted amount, never null.

Annotations
@Override
Exceptions
CurrencyConversionException:
if conversion failed, or the required data is not available.
See Also
getExchangeRate(MonetaryAmount)
getContextback to summary
public ConversionContext getContext()

Implements javax.money.convert.CurrencyConversion.getContext.

Access the target ConversionContext of this conversion instance.

Returns:ConversionContext

the target ConversionContext.

Annotations
@Override
getCurrencyback to summary
public CurrencyUnit getCurrency()

Implements javax.money.CurrencySupplier.getCurrency.

Access the terminating CurrencyUnit of this conversion instance.

Returns:CurrencyUnit

the terminating CurrencyUnit , never null.

Annotations
@Override
getExchangeRateback to summary
public abstract ExchangeRate getExchangeRate(MonetaryAmount sourceAmount)

Redeclares javax.money.convert.CurrencyConversion.getExchangeRate.

Get the exchange rate type that this MonetaryOperator instance is using for conversion.

Returns:ExchangeRate

the ExchangeRate to be used, or null, if this conversion is not supported (will lead to a CurrencyConversionException.

Annotations
@Override
See Also
apply(MonetaryAmount)
roundFactorback to summary
protected NumberValue roundFactor(MonetaryAmount amount, NumberValue factor)

Optionally rounds the factor to be used. By default this method will only round as much as it is needed, so the factor can be handled by the target amount instance based on its numeric capabilities. Rounding is applied only if amount.getContext().getMaxScale() > 0 as follows:

  • If the amount provides a MathContext as context property this is used.
  • If the amount provides a RoundingMode, this is used (default is RoundingMode.HALF_EVEN).
  • By default the scale used is scale of the conversion factor. If the acmount allows a higher scale based on amount.getContext().getMaxScale(), this higher scale is used.
Parameters
amount:MonetaryAmount

the amount, not null.

factor:NumberValue

the factor

Returns:NumberValue

the new rounding factor, never null.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
withback to summary
public abstract CurrencyConversion with(ConversionContext conversionContext)