java.lang.Object
javax.money.Monetary
Factory singleton for
CurrencyUnit, MonetaryAmount and
MonetaryRounding instances as provided by the
different registered SPI instances.
This class is thread safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<MonetaryAmountFactory<?>> Access all currently availableMonetaryAmountimplementation classes that are accessible from thisMonetaryAmountsingleton.static Collection<MonetaryAmountFactory<?>> Returns all factory instances that match the query.static <T extends MonetaryAmount>
MonetaryAmountFactory<T> getAmountFactory(Class<T> amountType) Access anMonetaryAmountFactoryfor the givenMonetaryAmountimplementation type.static MonetaryAmountFactoryExecutes the query and returns the factory found, if there is only one factory.static Collection<Class<? extends MonetaryAmount>> Access all currently availableMonetaryAmountimplementation classes that are accessible from thisMonetaryAmountsingleton.static Collection<CurrencyUnit> getCurrencies(String... providers) Access all currencies known.static Set<CurrencyUnit> getCurrencies(Locale locale, String... providers) Access a new instance based on theLocale.static Collection<CurrencyUnit> getCurrencies(CurrencyQuery query) Query all currencies matching the given query.static CurrencyUnitgetCurrency(String currencyCode, String... providers) Access a new instance based on the currency code.static CurrencyUnitgetCurrency(Locale locale, String... providers) Access a new instance based on theLocale.static CurrencyUnitgetCurrency(CurrencyQuery query) Query all currencies matching the given query.Query all currencies matching the given query.static MonetaryAmountFactory<?> Access the defaultMonetaryAmountFactoryas defined byMonetaryAmountsSingletonSpi.getDefaultAmountFactory().static Class<? extends MonetaryAmount> Access the defaultMonetaryAmountimplementation class that is accessible from thisMonetaryAmountsingleton.Query the list and ordering of provider names modelling the default provider chain to be used, if no provider chain was explicitly set..static MonetaryRoundingCreates a rounding that can be added asMonetaryOperatorto chained calculations.Allows to access the default providers chain used if no provider chain was passed explicitly..static MonetaryRoundinggetRounding(String roundingName, String... providers) Access anMonetaryOperatorfor custom roundingMonetaryAmountinstances.static MonetaryRoundinggetRounding(CurrencyUnit currencyUnit, String... providers) Creates anMonetaryOperatorfor roundingMonetaryAmountinstances given a currency.static MonetaryRoundinggetRounding(RoundingQuery roundingQuery) Access aMonetaryRoundingusing a possibly complex query.getRoundingNames(String... providers) Allows to access the names of the current defined roundings.Allows to access the names of the current registered providers.static Collection<MonetaryRounding> getRoundings(RoundingQuery roundingQuery) Access multipleMonetaryRoundinginstances using a possibly complex querystatic booleanAllows to check if any of the getXXX methods return non empty/non null results of.MonetaryAmountFactory.static booleanisCurrencyAvailable(String code, String... providers) Allows to check if aCurrencyUnitinstance is defined, i.e.static booleanisCurrencyAvailable(Locale locale, String... providers) Allows to check if aCurrencyUnitinstance is defined, i.e.static booleanisRoundingAvailable(String roundingName, String... providers) Checks if aMonetaryRoundingis available given a roundingId.static booleanisRoundingAvailable(CurrencyUnit currencyUnit, String... providers) Checks if aMonetaryRoundingis available given a roundingId.static booleanisRoundingAvailable(RoundingQuery roundingQuery) Checks if aMonetaryRoundingmatching the query is available.private static MonetaryAmountsSingletonQuerySpiThe usedMonetaryAmountsSingletonSpiinstance.private static MonetaryAmountsSingletonSpiThe usedMonetaryAmountsSingletonSpiinstance.private static MonetaryCurrenciesSingletonSpiThe usedMonetaryCurrenciesSingletonSpiinstance.private static MonetaryRoundingsSingletonSpiThe usedMonetaryCurrenciesSingletonSpiinstance.
-
Constructor Details
-
Monetary
private Monetary()Private singletons constructor.
-
-
Method Details
-
monetaryCurrenciesSingletonSpi
The usedMonetaryCurrenciesSingletonSpiinstance.- Returns:
- the used
MonetaryCurrenciesSingletonSpiinstance, nevernull
-
monetaryAmountsSingletonSpi
The usedMonetaryAmountsSingletonSpiinstance. -
monetaryAmountsSingletonQuerySpi
The usedMonetaryAmountsSingletonSpiinstance. -
monetaryRoundingsSingletonSpi
The usedMonetaryCurrenciesSingletonSpiinstance.- Returns:
- the used
MonetaryCurrenciesSingletonSpiinstance, nevernull
-
getRoundingProviderNames
Allows to access the names of the current registered providers.- Returns:
- the set of provider names, never
null.
-
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
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
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:
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:
IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
isRoundingAvailable
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:
IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
isRoundingAvailable
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:
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:
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
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(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 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
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
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
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
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
Query all currencies matching the given query.- Returns:
- the list of known currencies, never null.
-
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.
-