public final class MonetaryConversions
extends java.lang.Object
ExchangeRateProvider
and 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 MonetaryConversionsSpi
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 MonetaryConversionsSpi
SPI, which also is required
to be thread-safe.
Modifier and Type | Method and Description |
---|---|
static CurrencyConversion |
getConversion(CurrencyUnit termCurrency,
ConversionContext conversionContext,
java.lang.String... providers)
Access an instance of
CurrencyConversion for the given providers. |
static CurrencyConversion |
getConversion(CurrencyUnit termCurrency,
java.lang.String... providers)
Access an instance of
CurrencyConversion for the given providers. |
static CurrencyConversion |
getConversion(java.lang.String termCurrencyCode,
ConversionContext conversionContext,
java.lang.String... providers)
Access an instance of
CurrencyConversion for the given providers. |
static CurrencyConversion |
getConversion(java.lang.String termCurrencyCode,
java.lang.String... providers)
Access an instance of
CurrencyConversion for the given providers. |
static java.util.List<java.lang.String> |
getDefaultProviderChain()
Get the default provider used.
|
static ExchangeRateProvider |
getExchangeRateProvider(java.lang.String... providers)
Access an instance of
CurrencyConversion using the given
providers as a provider chain. |
static ProviderContext |
getProviderContext(java.lang.String provider)
Get the
ProviderContext for a provider. |
static java.util.Collection<java.lang.String> |
getProviderNames()
Return the (non localized) names of all providers available in the
current context.
|
static boolean |
isProviderAvailable(java.lang.String provider)
Checks if a provider is available in the current context.
|
public static CurrencyConversion getConversion(CurrencyUnit termCurrency, ConversionContext conversionContext, java.lang.String... providers)
CurrencyConversion
for the given providers.
Use isProviderAvailable(String)
to check, which are
available.termCurrency
- the terminating or target currency, not null
conversionContext
- The ConversionContext
required, not null
providers
- Additional providers, for building a provider chainjava.lang.IllegalArgumentException
- if no such ExchangeRateProvider
is available.public static CurrencyConversion getConversion(CurrencyUnit termCurrency, java.lang.String... providers)
CurrencyConversion
for the given providers.
Use isProviderAvailable(String)
to check, which are available.termCurrency
- the terminating or target currency, not null
providers
- Additional providers, for building a provider chainjava.lang.IllegalArgumentException
- if no such ExchangeRateProvider
is available.public static CurrencyConversion getConversion(java.lang.String termCurrencyCode, ConversionContext conversionContext, java.lang.String... providers)
CurrencyConversion
for the given providers.
Use isProviderAvailable(String)
to check, which are available.termCurrencyCode
- the terminating or target currency code, not null
conversionContext
- The ConversionContext
required, not null
providers
- Additional providers, for building a provider chainjava.lang.IllegalArgumentException
- if no such ExchangeRateProvider
is available.MonetaryException
- if no CurrencyUnit
was matching the given currency
code.public static CurrencyConversion getConversion(java.lang.String termCurrencyCode, java.lang.String... providers)
CurrencyConversion
for the given providers.
Use isProviderAvailable(String)
to check, which are available.termCurrencyCode
- the terminating or target currency code, not null
providers
- Additional providers, for building a provider chainjava.lang.IllegalArgumentException
- if no such ExchangeRateProvider
is available.MonetaryException
- if no CurrencyUnit
was matching the given currency
code.public static java.util.List<java.lang.String> getDefaultProviderChain()
null
.public static ExchangeRateProvider getExchangeRateProvider(java.lang.String... providers)
CurrencyConversion
using the given
providers as a provider chain. Use isProviderAvailable(String)
to check, which are available.java.lang.IllegalArgumentException
- if no such ExchangeRateProvider
is available.public static ProviderContext getProviderContext(java.lang.String provider)
ProviderContext
for a provider.provider
- the provider name, not null
.ProviderContext
, not null
.java.lang.IllegalArgumentException
- if no such provider is registered.public static java.util.Collection<java.lang.String> getProviderNames()
ExchangeRateProvider
or CurrencyConversion
instances.null
.public static boolean isProviderAvailable(java.lang.String provider)
provider
- the provider name, not null
CurrencyConversion
or
ExchangeRateProvider
with this provider name can be
obtained from the MonetaryConversions
instance.