java.lang.Object
javax.money.convert.MonetaryConversions
public final class MonetaryConversions
extends java.lang.Object
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.
- Author:
- Anatole Tresch, Werner Keil
-
Method Summary
Modifier and Type Method Description static CurrencyConversiongetConversion(java.lang.String termCurrencyCode, java.lang.String... providers)Access an instance ofCurrencyConversionfor the given providers.static CurrencyConversiongetConversion(ConversionQuery conversionQuery)Access an instance ofCurrencyConversionfor the given providers.static CurrencyConversiongetConversion(CurrencyUnit termCurrency, java.lang.String... providers)Access an instance ofCurrencyConversionfor the given providers.static java.util.Collection<java.lang.String>getConversionProviderNames()Return the (non localized) names of all providers available in the current context.static java.util.List<java.lang.String>getDefaultConversionProviderChain()Get the default provider used.static ExchangeRateProvidergetExchangeRateProvider(java.lang.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.static booleanisConversionAvailable(java.lang.String currencyCode, java.lang.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, java.lang.String... providers)Checks if aCurrencyConversionis available for the given parameters.static booleanisExchangeRateProviderAvailable(ConversionQuery conversionQuery)Checks if aExchangeRateProvideris available for the given parameters.
-
Method Details
-
getConversion
public static CurrencyConversion getConversion(CurrencyUnit termCurrency, java.lang.String... providers)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:
java.lang.IllegalArgumentException- if no suchExchangeRateProvideris available.
-
getConversion
public static CurrencyConversion getConversion(java.lang.String termCurrencyCode, java.lang.String... providers)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:
java.lang.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
public static boolean isConversionAvailable(java.lang.String currencyCode, java.lang.String... providers)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
public static boolean isConversionAvailable(CurrencyUnit termCurrency, java.lang.String... providers)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:
java.lang.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:
java.lang.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:
java.lang.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
public static java.util.Collection<java.lang.String> 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
public static java.util.List<java.lang.String> getDefaultConversionProviderChain()Get the default provider used.- Returns:
- the default provider, never
null.
-