java.lang.Object
javax.money.convert.MonetaryConversions
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 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 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 MonetaryConversionsSingletonSpi SPI, which also is required
to be thread-safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CurrencyConversiongetConversion(String termCurrencyCode, String... providers) Access an instance ofCurrencyConversionfor the given providers.static CurrencyConversiongetConversion(ConversionQuery conversionQuery) Access an instance ofCurrencyConversionfor the given providers.static CurrencyConversiongetConversion(CurrencyUnit termCurrency, String... providers) Access an instance ofCurrencyConversionfor the given providers.static Collection<String> Return the (non localized) names of all providers available in the current context.Get the default provider used.static ExchangeRateProvidergetExchangeRateProvider(String... providers) Access an instance ofCurrencyConversionusing the given providers as a provider chain.static ExchangeRateProvidergetExchangeRateProvider(ConversionQuery conversionQuery) Access an instance ofCurrencyConversionusing the given providers as a provider chain.static ExchangeRateProvidergetExchangeRateProvider(ExchangeRateProviderSupplier provider, ExchangeRateProviderSupplier... providers) Access an instance ofCurrencyConversionusing theExchangeRateProviderSupplier.private static MonetaryConversionsSingletonSpiThe SPI currently active, useServiceLoaderto register an alternate implementation.static booleanisConversionAvailable(String currencyCode, String... providers) Checks if aCurrencyConversionis available for the given parameters.static booleanisConversionAvailable(ConversionQuery conversionQuery) Checks if aCurrencyConversionis available for the given parameters.static booleanisConversionAvailable(CurrencyUnit termCurrency, String... providers) Checks if aCurrencyConversionis available for the given parameters.static booleanisExchangeRateProviderAvailable(ConversionQuery conversionQuery) Checks if aExchangeRateProvideris available for the given parameters.
-
Constructor Details
-
MonetaryConversions
private MonetaryConversions()Private singleton constructor.
-
-
Method Details
-
getMonetaryConversionsSpi
The SPI currently active, useServiceLoaderto register an alternate implementation. -
getConversion
Access an instance ofCurrencyConversionfor the given providers. UsegetConversionProviderNames()to check, which are available.- Parameters:
termCurrency- the terminating or target currency, notnullproviders- Additional providers, for building a provider chain- Returns:
- the exchange rate type if this instance.
- Throws:
IllegalArgumentException- if no suchExchangeRateProvideris available.
-
getConversion
Access an instance ofCurrencyConversionfor the given providers. UsegetConversionProviderNames()} to check, which are available.- Parameters:
termCurrencyCode- the terminating or target currency code, notnullproviders- Additional providers, for building a provider chain- Returns:
- the exchange rate type if this instance.
- Throws:
MonetaryException- if no suchExchangeRateProvideris available or if noCurrencyUnitwas matching the given currency code.
-
getConversion
Access an instance ofCurrencyConversionfor the given providers. UsegetConversionProviderNames()} to check, which are available.- Parameters:
conversionQuery- TheConversionQueryrequired, notnull- Returns:
- the
CurrencyConversioninstance matching. - Throws:
IllegalArgumentException- if the query definesExchangeRateProviders that are not available.
-
isConversionAvailable
Checks if aCurrencyConversionis available for the given parameters.- Parameters:
conversionQuery- theConversionQuery, not null.- Returns:
- true, if a conversion is accessible from
getConversion(ConversionQuery).
-
isConversionAvailable
Checks if aCurrencyConversionis available for the given parameters.- Parameters:
currencyCode- The currency code, resolvable by(String, String...)providers- Additional providers, for building a provider chain- Returns:
- true, if a conversion is accessible from
getConversion(String, String...).
-
isConversionAvailable
Checks if aCurrencyConversionis available for the given parameters.- Parameters:
termCurrency- the terminating or target currency, notnullproviders- Additional providers, for building a provider chain- Returns:
- true, if a conversion is accessible from
getConversion(String, String...).
-
getExchangeRateProvider
Access an instance ofCurrencyConversionusing the given providers as a provider chain. UsegetConversionProviderNames()s to check, which are available.- Parameters:
providers- Additional providers, for building a provider chain- Returns:
- the exchange rate provider.
- Throws:
IllegalArgumentException- if no suchExchangeRateProvideris available.
-
getExchangeRateProvider
public static ExchangeRateProvider getExchangeRateProvider(ExchangeRateProviderSupplier provider, ExchangeRateProviderSupplier... providers) Access an instance ofCurrencyConversionusing theExchangeRateProviderSupplier.- Parameters:
provider- the exchange rate provider.providers- the exchange rate provider.- Returns:
- the exchange rate provider.
- Throws:
IllegalArgumentException- if no suchExchangeRateProvideris available.
-
getExchangeRateProvider
Access an instance ofCurrencyConversionusing the given providers as a provider chain. UsegetConversionProviderNames()to check, which are available.- Parameters:
conversionQuery- theConversionQuery, not null.- Returns:
- the exchange rate provider.
- Throws:
IllegalArgumentException- if no suchExchangeRateProvideris available.
-
isExchangeRateProviderAvailable
Checks if aExchangeRateProvideris available for the given parameters.- Parameters:
conversionQuery- theConversionQuery, not null.- Returns:
- true, if a rate provider is accessible from
getExchangeRateProvider(ConversionQuery)}.
-
getConversionProviderNames
Return the (non localized) names of all providers available in the current context. Each id can be used to obtainExchangeRateProviderorCurrencyConversioninstances.- Returns:
- all supported provider ids, never
null.
-
getDefaultConversionProviderChain
Get the default provider used.- Returns:
- the default provider, never
null.
-