java.lang.Object
javax.money.Monetary
public final class Monetary
extends java.lang.Object
Factory singleton for
CurrencyUnit, MonetaryAmount and
MonetaryRounding instances as provided by the
different registered SPI instances.
This class is thread safe.
- Author:
- Anatole Tresch
-
Method Summary
Modifier and Type Method Description static java.util.Collection<MonetaryAmountFactory<?>>getAmountFactories()Access all currently availableMonetaryAmountimplementation classes that are accessible from thisMonetaryAmountsingleton.static java.util.Collection<MonetaryAmountFactory<?>>getAmountFactories(MonetaryAmountFactoryQuery query)Returns all factory instances that match the query.static <T extends MonetaryAmount>
MonetaryAmountFactory<T>getAmountFactory(java.lang.Class<T> amountType)Access anMonetaryAmountFactoryfor the givenMonetaryAmountimplementation type.static MonetaryAmountFactorygetAmountFactory(MonetaryAmountFactoryQuery query)Executes the query and returns the factory found, if there is only one factory.static java.util.Collection<java.lang.Class<? extends MonetaryAmount>>getAmountTypes()Access all currently availableMonetaryAmountimplementation classes that are accessible from thisMonetaryAmountsingleton.static java.util.Collection<CurrencyUnit>getCurrencies(java.lang.String... providers)Access all currencies known.static java.util.Set<CurrencyUnit>getCurrencies(java.util.Locale locale, java.lang.String... providers)Access a new instance based on theLocale.static java.util.Collection<CurrencyUnit>getCurrencies(CurrencyQuery query)Query all currencies matching the given query.static CurrencyUnitgetCurrency(java.lang.String currencyCode, java.lang.String... providers)Access a new instance based on the currency code.static CurrencyUnitgetCurrency(java.util.Locale locale, java.lang.String... providers)Access a new instance based on theLocale.static CurrencyUnitgetCurrency(CurrencyQuery query)Query all currencies matching the given query.static java.util.Set<java.lang.String>getCurrencyProviderNames()Query all currencies matching the given query.static MonetaryAmountFactory<?>getDefaultAmountFactory()Access the defaultMonetaryAmountFactoryas defined byMonetaryAmountsSingletonSpi.getDefaultAmountFactory().static java.lang.Class<? extends MonetaryAmount>getDefaultAmountType()Access the defaultMonetaryAmountimplementation class that is accessible from thisMonetaryAmountsingleton.static java.util.List<java.lang.String>getDefaultCurrencyProviderChain()Query the list and ordering of provider names modelling the default provider chain to be used, if no provider chain was explicitly set..static MonetaryRoundinggetDefaultRounding()Creates a rounding that can be added asMonetaryOperatorto chained calculations.static java.util.List<java.lang.String>getDefaultRoundingProviderChain()Allows to access the default providers chain used if no provider chain was passed explicitly..static MonetaryRoundinggetRounding(java.lang.String roundingName, java.lang.String... providers)Access anMonetaryOperatorfor custom roundingMonetaryAmountinstances.static MonetaryRoundinggetRounding(CurrencyUnit currencyUnit, java.lang.String... providers)Creates anMonetaryOperatorfor roundingMonetaryAmountinstances given a currency.static MonetaryRoundinggetRounding(RoundingQuery roundingQuery)Access aMonetaryRoundingusing a possibly complex query.static java.util.Set<java.lang.String>getRoundingNames(java.lang.String... providers)Allows to access the names of the current defined roundings.static java.util.Set<java.lang.String>getRoundingProviderNames()Allows to access the names of the current registered providers.static java.util.Collection<MonetaryRounding>getRoundings(RoundingQuery roundingQuery)Access multipleMonetaryRoundinginstances using a possibly complex querystatic booleanisAvailable(MonetaryAmountFactoryQuery query)Allows to check if any of the getXXX methods return non empty/non null results of.MonetaryAmountFactory.static booleanisCurrencyAvailable(java.lang.String code, java.lang.String... providers)Allows to check if aCurrencyUnitinstance is defined, i.e.static booleanisCurrencyAvailable(java.util.Locale locale, java.lang.String... providers)Allows to check if aCurrencyUnitinstance is defined, i.e.static booleanisRoundingAvailable(java.lang.String roundingName, java.lang.String... providers)Checks if aMonetaryRoundingis available given a roundingId.static booleanisRoundingAvailable(CurrencyUnit currencyUnit, java.lang.String... providers)Checks if aMonetaryRoundingis available given a roundingId.static booleanisRoundingAvailable(RoundingQuery roundingQuery)Checks if aMonetaryRoundingmatching the query is available.
-
Method Details
-
getRoundingProviderNames
public static java.util.Set<java.lang.String> getRoundingProviderNames()Allows to access the names of the current registered providers.- Returns:
- the set of provider names, never
null.
-
getDefaultRoundingProviderChain
public static java.util.List<java.lang.String> getDefaultRoundingProviderChain()Allows to access the default providers chain used if no provider chain was passed explicitly..- Returns:
- the chained list of provider names, never
null.
-
getDefaultRounding
Creates a rounding that can be added asMonetaryOperatorto chained calculations. The instance will lookup the concreteMonetaryOperatorinstance from theMonetarybased on the inputMonetaryAmount'sCurrencyUnit.- Returns:
- the (shared) default rounding instance.
-
getRounding
public static MonetaryRounding getRounding(CurrencyUnit currencyUnit, java.lang.String... providers)Creates anMonetaryOperatorfor roundingMonetaryAmountinstances given a currency.- Parameters:
currencyUnit- The currency, which determines the required scale. AsRoundingMode, by default,RoundingMode.HALF_UPis used.providers- the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.- Returns:
- a new instance
MonetaryOperatorimplementing the rounding, nevernull.
-
getRounding
public static MonetaryRounding getRounding(java.lang.String roundingName, java.lang.String... providers)Access anMonetaryOperatorfor custom roundingMonetaryAmountinstances.- Parameters:
roundingName- The rounding identifier.providers- the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.- Returns:
- the corresponding
MonetaryOperatorimplementing the rounding, nevernull. - Throws:
java.lang.IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
getRounding
Access aMonetaryRoundingusing a possibly complex query.- Parameters:
roundingQuery- TheRoundingQuerythat may contains arbitrary parameters to be evaluated.- Returns:
- the corresponding
MonetaryRounding, nevernull. - Throws:
java.lang.IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
isRoundingAvailable
public static boolean isRoundingAvailable(java.lang.String roundingName, java.lang.String... providers)Checks if aMonetaryRoundingis available given a roundingId.- Parameters:
roundingName- The rounding identifier.providers- the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.- Returns:
- true, if a corresponding
MonetaryRoundingis available. - Throws:
java.lang.IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
isRoundingAvailable
public static boolean isRoundingAvailable(CurrencyUnit currencyUnit, java.lang.String... providers)Checks if aMonetaryRoundingis available given a roundingId.- Parameters:
currencyUnit- The currency, which determines the required scale. AsRoundingMode, by default,RoundingMode.HALF_UPis used.providers- the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.- Returns:
- true, if a corresponding
MonetaryRoundingis available. - Throws:
java.lang.IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
isRoundingAvailable
Checks if aMonetaryRoundingmatching the query is available.- Parameters:
roundingQuery- TheRoundingQuerythat may contains arbitrary parameters to be evaluated.- Returns:
- true, if a corresponding
MonetaryRoundingis available. - Throws:
java.lang.IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
getRoundings
Access multipleMonetaryRoundinginstances using a possibly complex query- Parameters:
roundingQuery- TheRoundingQuerythat may contains arbitrary parameters to be evaluated.- Returns:
- all
MonetaryRoundinginstances matching the query, nevernull.
-
getRoundingNames
public static java.util.Set<java.lang.String> getRoundingNames(java.lang.String... providers)Allows to access the names of the current defined roundings.- Parameters:
providers- the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.- Returns:
- the set of custom rounding ids, never
null.
-
getAmountFactory
public static <T extends MonetaryAmount> MonetaryAmountFactory<T> getAmountFactory(java.lang.Class<T> amountType)Access anMonetaryAmountFactoryfor the givenMonetaryAmountimplementation type.- Parameters:
amountType-MonetaryAmountimplementation type, nornull.- Returns:
- the corresponding
MonetaryAmountFactory, nevernull. - Throws:
MonetaryException- if noMonetaryAmountFactorytargeting the givenMonetaryAmountimplementation class is registered.
-
getDefaultAmountFactory
Access the defaultMonetaryAmountFactoryas defined byMonetaryAmountsSingletonSpi.getDefaultAmountFactory().- Returns:
- the
MonetaryAmountFactorycorresponding to default amount type, nevernull. - Throws:
MonetaryException- if noMonetaryAmountFactorytargeting the default amount type implementation class is registered.
-
getAmountFactories
Access all currently availableMonetaryAmountimplementation classes that are accessible from thisMonetaryAmountsingleton.- Returns:
- all currently available
MonetaryAmountimplementation classes that have correspondingMonetaryAmountFactoryinstances provided, nevernull
-
getAmountTypes
Access all currently availableMonetaryAmountimplementation classes that are accessible from thisMonetaryAmountsingleton.- Returns:
- all currently available
MonetaryAmountimplementation classes that have correspondingMonetaryAmountFactoryinstances provided, nevernull
-
getDefaultAmountType
Access the defaultMonetaryAmountimplementation class that is accessible from thisMonetaryAmountsingleton.- Returns:
- all current default
MonetaryAmountimplementation class, nevernull
-
getAmountFactory
Executes the query and returns the factory found, if there is only one factory. If multiple factories match the query, one is selected.- Parameters:
query- the factory query, not null.- Returns:
- the factory found, or null.
-
getAmountFactories
public static java.util.Collection<MonetaryAmountFactory<?>> getAmountFactories(MonetaryAmountFactoryQuery query)Returns all factory instances that match the query.- Parameters:
query- the factory query, not null.- Returns:
- the instances found, never null.
-
isAvailable
Allows to check if any of the getXXX methods return non empty/non null results of.MonetaryAmountFactory.- Parameters:
query- the factory query, not null.- Returns:
- true, if at least one
MonetaryAmountFactorymatches the query.
-
getCurrency
public static CurrencyUnit getCurrency(java.lang.String currencyCode, java.lang.String... providers)Access a new instance based on the currency code. Currencies are available as provided byCurrencyProviderSpiinstances registered with theBootstrap.- Parameters:
currencyCode- the ISO currency code, notnull.providers- the (optional) specification of providers to consider.- Returns:
- the corresponding
CurrencyUnitinstance. - Throws:
UnknownCurrencyException- if no such currency exists.
-
getCurrency
Access a new instance based on theLocale. Currencies are available as provided byCurrencyProviderSpiinstances registered with theBootstrap.- Parameters:
locale- the targetLocale, typically representing an ISO country, notnull.providers- the (optional) specification of providers to consider.- Returns:
- the corresponding
CurrencyUnitinstance. - Throws:
UnknownCurrencyException- if no such currency exists.
-
getCurrencies
public static java.util.Set<CurrencyUnit> getCurrencies(java.util.Locale locale, java.lang.String... providers)Access a new instance based on theLocale. Currencies are available as provided byCurrencyProviderSpiinstances registered with theBootstrap.- Parameters:
locale- the targetLocale, typically representing an ISO country, notnull.providers- the (optional) specification of providers to consider.- Returns:
- the corresponding
CurrencyUnitinstance. - Throws:
UnknownCurrencyException- if no such currency exists.
-
isCurrencyAvailable
public static boolean isCurrencyAvailable(java.lang.String code, java.lang.String... providers)Allows to check if aCurrencyUnitinstance is defined, i.e. accessible fromgetCurrency(String, String...).- Parameters:
code- the currency code, notnull.providers- the (optional) specification of providers to consider.- Returns:
trueifgetCurrency(String, java.lang.String...)would return a result for the given code.
-
isCurrencyAvailable
public static boolean isCurrencyAvailable(java.util.Locale locale, java.lang.String... providers)Allows to check if aCurrencyUnitinstance is defined, i.e. accessible fromgetCurrency(String, String...).- Parameters:
locale- the targetLocale, notnull.providers- the (optional) specification of providers to consider.- Returns:
trueifgetCurrencies(Locale, String...)would return a result containing a currency with the given code.
-
getCurrencies
Access all currencies known.- Parameters:
providers- the (optional) specification of providers to consider.- Returns:
- the list of known currencies, never null.
-
getCurrency
Query all currencies matching the given query.- Parameters:
query- TheCurrencyQuery, not null.- Returns:
- the list of known currencies, never null.
-
getCurrencies
Query all currencies matching the given query.- Parameters:
query- TheCurrencyQuery, not null.- Returns:
- the list of known currencies, never null.
-
getCurrencyProviderNames
public static java.util.Set<java.lang.String> getCurrencyProviderNames()Query all currencies matching the given query.- Returns:
- the list of known currencies, never null.
-
getDefaultCurrencyProviderChain
public static java.util.List<java.lang.String> getDefaultCurrencyProviderChain()Query the list and ordering of provider names modelling the default provider chain to be used, if no provider chain was explicitly set..- Returns:
- the ordered list provider names, modelling the default provider chain used, never null.
-