Top Description Constructors Methods
javax.money.convert

public final Class MonetaryConversions

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Collection, .Collections, .List, .Objects, .Optional, .ServiceLoader, java.util.logging.Logger, javax.money.CurrencyUnit, .Monetary, .MonetaryException, javax.money.spi.Bootstrap, .MonetaryConversionsSingletonSpi

This singleton defines access to the exchange and currency conversion logic of JavaMoney. It allows to evaluate the currently available exchange rate type instances and provides access to the corresponding ExchangeRateProvider and javax.money.convert.CurrencyConversion instances.

This class is thread safe.

This class is designed to support also contextual behaviour, e.g. in Java EE containers each application may provide its own ExchangeRateProvider instances, e.g. by registering them as CDI beans. An EE container can register an according javax.money.spi.MonetaryConversionsSingletonSpi that manages the different application contexts transparently. In a SE environment this class is expected to behave like an ordinary singleton, loading its SPIs e.g. from the JDK ServiceLoader or an alternate component and service provider.

This class is thread-safe. Hereby it is important to know that it delegates to the registered javax.money.spi.MonetaryConversionsSingletonSpi SPI, which also is required to be thread-safe.

Authors
Anatole Tresch, Werner Keil

Constructor Summary

AccessConstructor and Description
private
MonetaryConversions()

Private singleton constructor.

Method Summary

Modifier and TypeMethod and Description
public static CurrencyConversion

Returns:

the exchange rate type if this instance.
getConversion
(CurrencyUnit
the terminating or target currency, not null
termCurrency
,
String...
Additional providers, for building a provider chain
providers
)

Access an instance of CurrencyConversion for the given providers.

public static CurrencyConversion

Returns:

the exchange rate type if this instance.
getConversion
(String
the terminating or target currency code, not null
termCurrencyCode
,
String...
Additional providers, for building a provider chain
providers
)

Access an instance of CurrencyConversion for the given providers.

public static CurrencyConversion

Returns:

the CurrencyConversion instance matching.
getConversion
(ConversionQuery
The ConversionQuery required, not null
conversionQuery
)

Access an instance of CurrencyConversion for the given providers.

public static Collection<String>

Returns:

all supported provider ids, never null.
getConversionProviderNames
()

Return the (non localized) names of all providers available in the current context.

public static List<String>

Returns:

the default provider, never null.
getDefaultConversionProviderChain
()

Get the default provider used.

public static ExchangeRateProvider

Returns:

the exchange rate provider.
getExchangeRateProvider
(String...
Additional providers, for building a provider chain
providers
)

Access an instance of CurrencyConversion using the given providers as a provider chain.

public static ExchangeRateProvider

Returns:

the exchange rate provider.
getExchangeRateProvider
(ExchangeRateProviderSupplier
the exchange rate provider.
provider
,
ExchangeRateProviderSupplier...
the exchange rate provider.
providers
)

Access an instance of CurrencyConversion using the ExchangeRateProviderSupplier.

public static ExchangeRateProvider

Returns:

the exchange rate provider.
getExchangeRateProvider
(ConversionQuery conversionQuery)

Access an instance of CurrencyConversion using the given providers as a provider chain.

private static MonetaryConversionsSingletonSpi
getMonetaryConversionsSpi()

The SPI currently active, use ServiceLoader to register an alternate implementation.

public static boolean

Returns:

true, if a conversion is accessible from getConversion(ConversionQuery).
isConversionAvailable
(ConversionQuery conversionQuery)

Checks if a javax.money.convert.CurrencyConversion is available for the given parameters.

public static boolean

Returns:

true, if a conversion is accessible from getConversion(String, String...).
isConversionAvailable
(String
The currency code, resolvable by (String, String...)
currencyCode
,
String...
Additional providers, for building a provider chain
providers
)

Checks if a javax.money.convert.CurrencyConversion is available for the given parameters.

public static boolean

Returns:

true, if a conversion is accessible from getConversion(String, String...).
isConversionAvailable
(CurrencyUnit
the terminating or target currency, not null
termCurrency
,
String...
Additional providers, for building a provider chain
providers
)

Checks if a javax.money.convert.CurrencyConversion is available for the given parameters.

public static boolean

Returns:

true, if a rate provider is accessible from getExchangeRateProvider(ConversionQuery)}.
isExchangeRateProviderAvailable
(ConversionQuery conversionQuery)

Checks if a javax.money.convert.ExchangeRateProvider is available for the given parameters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MonetaryConversionsback to summary
private MonetaryConversions()

Private singleton constructor.

Method Detail

getConversionback to summary
public static CurrencyConversion getConversion(CurrencyUnit termCurrency, String... providers)

Access an instance of CurrencyConversion for the given providers. Use getConversionProviderNames() to check, which are available.

Parameters
termCurrency:CurrencyUnit

the terminating or target currency, not null

providers:String[]

Additional providers, for building a provider chain

Returns:CurrencyConversion

the exchange rate type if this instance.

Exceptions
IllegalArgumentException:
if no such ExchangeRateProvider is available.
getConversionback to summary
public static CurrencyConversion getConversion(String termCurrencyCode, String... providers)

Access an instance of CurrencyConversion for the given providers. Use getConversionProviderNames()} to check, which are available.

Parameters
termCurrencyCode:String

the terminating or target currency code, not null

providers:String[]

Additional providers, for building a provider chain

Returns:CurrencyConversion

the exchange rate type if this instance.

Exceptions
MonetaryException:
if no such ExchangeRateProvider is available or if no CurrencyUnit was matching the given currency code.
getConversionback to summary
public static CurrencyConversion getConversion(ConversionQuery conversionQuery)

Access an instance of CurrencyConversion for the given providers. Use getConversionProviderNames()} to check, which are available.

Parameters
conversionQuery:ConversionQuery

The ConversionQuery required, not null

Returns:CurrencyConversion

the CurrencyConversion instance matching.

Exceptions
IllegalArgumentException:
if the query defines ExchangeRateProviders that are not available.
getConversionProviderNamesback to summary
public static Collection<String> getConversionProviderNames()

Return the (non localized) names of all providers available in the current context. Each id can be used to obtain ExchangeRateProvider or CurrencyConversion instances.

Returns:Collection<String>

all supported provider ids, never null.

getDefaultConversionProviderChainback to summary
public static List<String> getDefaultConversionProviderChain()

Get the default provider used.

Returns:List<String>

the default provider, never null.

getExchangeRateProviderback to summary
public static ExchangeRateProvider getExchangeRateProvider(String... providers)

Access an instance of CurrencyConversion using the given providers as a provider chain. Use getConversionProviderNames()s to check, which are available.

Parameters
providers:String[]

Additional providers, for building a provider chain

Returns:ExchangeRateProvider

the exchange rate provider.

Exceptions
IllegalArgumentException:
if no such ExchangeRateProvider is available.
getExchangeRateProviderback to summary
public static ExchangeRateProvider getExchangeRateProvider(ExchangeRateProviderSupplier provider, ExchangeRateProviderSupplier... providers)

Access an instance of CurrencyConversion using the ExchangeRateProviderSupplier.

Parameters
provider:ExchangeRateProviderSupplier

the exchange rate provider.

providers:ExchangeRateProviderSupplier[]

the exchange rate provider.

Returns:ExchangeRateProvider

the exchange rate provider.

Exceptions
IllegalArgumentException:
if no such ExchangeRateProvider is available.
getExchangeRateProviderback to summary
public static ExchangeRateProvider getExchangeRateProvider(ConversionQuery conversionQuery)

Access an instance of CurrencyConversion using the given providers as a provider chain. Use getConversionProviderNames() to check, which are available.

Parameters
conversionQuery:ConversionQuery

the javax.money.convert.ConversionQuery, not null.

Returns:ExchangeRateProvider

the exchange rate provider.

Exceptions
IllegalArgumentException:
if no such ExchangeRateProvider is available.
getMonetaryConversionsSpiback to summary
private static MonetaryConversionsSingletonSpi getMonetaryConversionsSpi()

The SPI currently active, use ServiceLoader to register an alternate implementation.

isConversionAvailableback to summary
public static boolean isConversionAvailable(ConversionQuery conversionQuery)

Checks if a javax.money.convert.CurrencyConversion is available for the given parameters.

Parameters
conversionQuery:ConversionQuery

the javax.money.convert.ConversionQuery, not null.

Returns:boolean

true, if a conversion is accessible from getConversion(ConversionQuery).

isConversionAvailableback to summary
public static boolean isConversionAvailable(String currencyCode, String... providers)

Checks if a javax.money.convert.CurrencyConversion is available for the given parameters.

Parameters
currencyCode:String

The currency code, resolvable by (String, String...)

providers:String[]

Additional providers, for building a provider chain

Returns:boolean

true, if a conversion is accessible from getConversion(String, String...).

isConversionAvailableback to summary
public static boolean isConversionAvailable(CurrencyUnit termCurrency, String... providers)

Checks if a javax.money.convert.CurrencyConversion is available for the given parameters.

Parameters
termCurrency:CurrencyUnit

the terminating or target currency, not null

providers:String[]

Additional providers, for building a provider chain

Returns:boolean

true, if a conversion is accessible from getConversion(String, String...).

isExchangeRateProviderAvailableback to summary
public static boolean isExchangeRateProviderAvailable(ConversionQuery conversionQuery)

Checks if a javax.money.convert.ExchangeRateProvider is available for the given parameters.

Parameters
conversionQuery:ConversionQuery

the javax.money.convert.ConversionQuery, not null.

Returns:boolean

true, if a rate provider is accessible from getExchangeRateProvider(ConversionQuery)}.