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 availableMonetaryAmount
implementation classes that are accessible from thisMonetaryAmount
singleton.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 anMonetaryAmountFactory
for the givenMonetaryAmount
implementation type.static MonetaryAmountFactory
getAmountFactory(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 availableMonetaryAmount
implementation classes that are accessible from thisMonetaryAmount
singleton.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 CurrencyUnit
getCurrency(java.lang.String currencyCode, java.lang.String... providers)
Access a new instance based on the currency code.static CurrencyUnit
getCurrency(java.util.Locale locale, java.lang.String... providers)
Access a new instance based on theLocale
.static CurrencyUnit
getCurrency(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 defaultMonetaryAmountFactory
as defined byMonetaryAmountsSingletonSpi.getDefaultAmountFactory()
.static java.lang.Class<? extends MonetaryAmount>
getDefaultAmountType()
Access the defaultMonetaryAmount
implementation class that is accessible from thisMonetaryAmount
singleton.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 MonetaryRounding
getDefaultRounding()
Creates a rounding that can be added asMonetaryOperator
to 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 MonetaryRounding
getRounding(java.lang.String roundingName, java.lang.String... providers)
Access anMonetaryOperator
for custom roundingMonetaryAmount
instances.static MonetaryRounding
getRounding(CurrencyUnit currencyUnit, java.lang.String... providers)
Creates anMonetaryOperator
for roundingMonetaryAmount
instances given a currency.static MonetaryRounding
getRounding(RoundingQuery roundingQuery)
Access aMonetaryRounding
using 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 multipleMonetaryRounding
instances using a possibly complex querystatic boolean
isAvailable(MonetaryAmountFactoryQuery query)
Allows to check if any of the getXXX methods return non empty/non null results of.MonetaryAmountFactory
.static boolean
isCurrencyAvailable(java.lang.String code, java.lang.String... providers)
Allows to check if aCurrencyUnit
instance is defined, i.e.static boolean
isCurrencyAvailable(java.util.Locale locale, java.lang.String... providers)
Allows to check if aCurrencyUnit
instance is defined, i.e.static boolean
isRoundingAvailable(java.lang.String roundingName, java.lang.String... providers)
Checks if aMonetaryRounding
is available given a roundingId.static boolean
isRoundingAvailable(CurrencyUnit currencyUnit, java.lang.String... providers)
Checks if aMonetaryRounding
is available given a roundingId.static boolean
isRoundingAvailable(RoundingQuery roundingQuery)
Checks if aMonetaryRounding
matching 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 asMonetaryOperator
to chained calculations. The instance will lookup the concreteMonetaryOperator
instance from theMonetary
based on the inputMonetaryAmount
'sCurrencyUnit
.- Returns:
- the (shared) default rounding instance.
-
getRounding
public static MonetaryRounding getRounding(CurrencyUnit currencyUnit, java.lang.String... providers)Creates anMonetaryOperator
for roundingMonetaryAmount
instances given a currency.- Parameters:
currencyUnit
- The currency, which determines the required scale. AsRoundingMode
, by default,RoundingMode.HALF_UP
is used.providers
- the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.- Returns:
- a new instance
MonetaryOperator
implementing the rounding, nevernull
.
-
getRounding
public static MonetaryRounding getRounding(java.lang.String roundingName, java.lang.String... providers)Access anMonetaryOperator
for custom roundingMonetaryAmount
instances.- 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
MonetaryOperator
implementing the rounding, nevernull
. - Throws:
java.lang.IllegalArgumentException
- if no such rounding is registered using aRoundingProviderSpi
instance.
-
getRounding
Access aMonetaryRounding
using a possibly complex query.- Parameters:
roundingQuery
- TheRoundingQuery
that may contains arbitrary parameters to be evaluated.- Returns:
- the corresponding
MonetaryRounding
, nevernull
. - Throws:
java.lang.IllegalArgumentException
- if no such rounding is registered using aRoundingProviderSpi
instance.
-
isRoundingAvailable
public static boolean isRoundingAvailable(java.lang.String roundingName, java.lang.String... providers)Checks if aMonetaryRounding
is 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
MonetaryRounding
is available. - Throws:
java.lang.IllegalArgumentException
- if no such rounding is registered using aRoundingProviderSpi
instance.
-
isRoundingAvailable
public static boolean isRoundingAvailable(CurrencyUnit currencyUnit, java.lang.String... providers)Checks if aMonetaryRounding
is available given a roundingId.- Parameters:
currencyUnit
- The currency, which determines the required scale. AsRoundingMode
, by default,RoundingMode.HALF_UP
is 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
MonetaryRounding
is available. - Throws:
java.lang.IllegalArgumentException
- if no such rounding is registered using aRoundingProviderSpi
instance.
-
isRoundingAvailable
Checks if aMonetaryRounding
matching the query is available.- Parameters:
roundingQuery
- TheRoundingQuery
that may contains arbitrary parameters to be evaluated.- Returns:
- true, if a corresponding
MonetaryRounding
is available. - Throws:
java.lang.IllegalArgumentException
- if no such rounding is registered using aRoundingProviderSpi
instance.
-
getRoundings
Access multipleMonetaryRounding
instances using a possibly complex query- Parameters:
roundingQuery
- TheRoundingQuery
that may contains arbitrary parameters to be evaluated.- Returns:
- all
MonetaryRounding
instances 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 anMonetaryAmountFactory
for the givenMonetaryAmount
implementation type.- Parameters:
amountType
-MonetaryAmount
implementation type, nornull
.- Returns:
- the corresponding
MonetaryAmountFactory
, nevernull
. - Throws:
MonetaryException
- if noMonetaryAmountFactory
targeting the givenMonetaryAmount
implementation class is registered.
-
getDefaultAmountFactory
Access the defaultMonetaryAmountFactory
as defined byMonetaryAmountsSingletonSpi.getDefaultAmountFactory()
.- Returns:
- the
MonetaryAmountFactory
corresponding to default amount type, nevernull
. - Throws:
MonetaryException
- if noMonetaryAmountFactory
targeting the default amount type implementation class is registered.
-
getAmountFactories
Access all currently availableMonetaryAmount
implementation classes that are accessible from thisMonetaryAmount
singleton.- Returns:
- all currently available
MonetaryAmount
implementation classes that have correspondingMonetaryAmountFactory
instances provided, nevernull
-
getAmountTypes
Access all currently availableMonetaryAmount
implementation classes that are accessible from thisMonetaryAmount
singleton.- Returns:
- all currently available
MonetaryAmount
implementation classes that have correspondingMonetaryAmountFactory
instances provided, nevernull
-
getDefaultAmountType
Access the defaultMonetaryAmount
implementation class that is accessible from thisMonetaryAmount
singleton.- Returns:
- all current default
MonetaryAmount
implementation 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
MonetaryAmountFactory
matches 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 byCurrencyProviderSpi
instances registered with theBootstrap
.- Parameters:
currencyCode
- the ISO currency code, notnull
.providers
- the (optional) specification of providers to consider.- Returns:
- the corresponding
CurrencyUnit
instance. - Throws:
UnknownCurrencyException
- if no such currency exists.
-
getCurrency
Access a new instance based on theLocale
. Currencies are available as provided byCurrencyProviderSpi
instances registered with theBootstrap
.- Parameters:
locale
- the targetLocale
, typically representing an ISO country, notnull
.providers
- the (optional) specification of providers to consider.- Returns:
- the corresponding
CurrencyUnit
instance. - 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 byCurrencyProviderSpi
instances registered with theBootstrap
.- Parameters:
locale
- the targetLocale
, typically representing an ISO country, notnull
.providers
- the (optional) specification of providers to consider.- Returns:
- the corresponding
CurrencyUnit
instance. - Throws:
UnknownCurrencyException
- if no such currency exists.
-
isCurrencyAvailable
public static boolean isCurrencyAvailable(java.lang.String code, java.lang.String... providers)Allows to check if aCurrencyUnit
instance is defined, i.e. accessible fromgetCurrency(String, String...)
.- Parameters:
code
- the currency code, notnull
.providers
- the (optional) specification of providers to consider.- Returns:
true
ifgetCurrency(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 aCurrencyUnit
instance is defined, i.e. accessible fromgetCurrency(String, String...)
.- Parameters:
locale
- the targetLocale
, notnull
.providers
- the (optional) specification of providers to consider.- Returns:
true
ifgetCurrencies(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.
-