Top Description Constructors Methods
javax.money

public final Class Monetary

extends Object
Class Inheritance
Imports
javax.money.spi.*, java.util.Collection, .List, .Locale, .Optional, .Set, java.util.logging.Level, .Logger

Factory singleton for CurrencyUnit, javax.money.MonetaryAmount and javax.money.MonetaryRounding instances as provided by the different registered SPI instances.

This class is thread safe.

Author
Anatole Tresch

Constructor Summary

AccessConstructor and Description
private
Monetary()

Private singletons constructor.

Method Summary

Modifier and TypeMethod and Description
public static Collection<MonetaryAmountFactory<?>>

Returns:

all currently available MonetaryAmount implementation classes that have corresponding MonetaryAmountFactory instances provided, never null
getAmountFactories
()

Access all currently available MonetaryAmount implementation classes that are accessible from this MonetaryAmount singleton.

public static Collection<MonetaryAmountFactory<?>>

Returns:

the instances found, never null.
getAmountFactories
(MonetaryAmountFactoryQuery
the factory query, not null.
query
)

Returns all factory instances that match the query.

public static <T extends MonetaryAmount> MonetaryAmountFactory<T>

Returns:

the corresponding MonetaryAmountFactory, never null.
getAmountFactory
(Class<T>
MonetaryAmount implementation type, nor null.
amountType
)

Access an MonetaryAmountFactory for the given MonetaryAmount implementation type.

public static MonetaryAmountFactory<T extends MonetaryAmount>

Returns:

the factory found, or null.
getAmountFactory
(MonetaryAmountFactoryQuery
the factory query, not null.
query
)

Executes the query and returns the factory found, if there is only one factory.

public static Collection<Class<? extends MonetaryAmount>>

Returns:

all currently available MonetaryAmount implementation classes that have corresponding MonetaryAmountFactory instances provided, never null
getAmountTypes
()

Access all currently available MonetaryAmount implementation classes that are accessible from this MonetaryAmount singleton.

public static Set<CurrencyUnit>

Returns:

the corresponding CurrencyUnit instance.
getCurrencies
(Locale
the target Locale, typically representing an ISO country, not null.
locale
,
String...
the (optional) specification of providers to consider.
providers
)

Access a new instance based on the Locale.

public static Collection<CurrencyUnit>

Returns:

the list of known currencies, never null.
getCurrencies
(String...
the (optional) specification of providers to consider.
providers
)

Access all currencies known.

public static Collection<CurrencyUnit>

Returns:

the list of known currencies, never null.
getCurrencies
(CurrencyQuery query)

Query all currencies matching the given query.

public static CurrencyUnit

Returns:

the corresponding CurrencyUnit instance.
getCurrency
(String
the ISO currency code, not null.
currencyCode
,
String...
the (optional) specification of providers to consider.
providers
)

Access a new instance based on the currency code.

public static CurrencyUnit

Returns:

the corresponding CurrencyUnit instance.
getCurrency
(Locale
the target Locale, typically representing an ISO country, not null.
locale
,
String...
the (optional) specification of providers to consider.
providers
)

Access a new instance based on the Locale.

public static CurrencyUnit

Returns:

the list of known currencies, never null.
getCurrency
(CurrencyQuery query)

Query all currencies matching the given query.

public static Set<String>

Returns:

the list of known currencies, never null.
getCurrencyProviderNames
()

Query all currencies matching the given query.

public static MonetaryAmountFactory<?>

Returns:

the MonetaryAmountFactory corresponding to default amount type, never null.
getDefaultAmountFactory
()

Access the default MonetaryAmountFactory as defined by javax.money.spi.MonetaryAmountsSingletonSpi#getDefaultAmountFactory().

public static Class<? extends MonetaryAmount>

Returns:

all current default MonetaryAmount implementation class, never null
getDefaultAmountType
()

Access the default MonetaryAmount implementation class that is accessible from this MonetaryAmount singleton.

public static List<String>

Returns:

the ordered list provider names, modelling the default provider chain used, 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..

public static MonetaryRounding

Returns:

the (shared) default rounding instance.
getDefaultRounding
()

Creates a rounding that can be added as MonetaryOperator to chained calculations.

public static List<String>

Returns:

the chained list of provider names, never null.
getDefaultRoundingProviderChain
()

Allows to access the default providers chain used if no provider chain was passed explicitly..

public static MonetaryRounding

Returns:

a new instance MonetaryOperator implementing the rounding, never null.
getRounding
(CurrencyUnit
The currency, which determines the required scale. As java.math.RoundingMode, by default, java.math.RoundingMode#HALF_UP is used.
currencyUnit
,
String...
the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.
providers
)

Creates an MonetaryOperator for rounding MonetaryAmount instances given a currency.

public static MonetaryRounding

Returns:

the corresponding MonetaryOperator implementing the rounding, never null.
getRounding
(String
The rounding identifier.
roundingName
,
String...
the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.
providers
)

Access an MonetaryOperator for custom rounding MonetaryAmount instances.

public static MonetaryRounding

Returns:

the corresponding javax.money.MonetaryRounding, never null.
getRounding
(RoundingQuery
The javax.money.RoundingQuery that may contains arbitrary parameters to be evaluated.
roundingQuery
)

Access a MonetaryRounding using a possibly complex query.

public static Set<String>

Returns:

the set of custom rounding ids, never null.
getRoundingNames
(String...
the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.
providers
)

Allows to access the names of the current defined roundings.

public static Set<String>

Returns:

the set of provider names, never null.
getRoundingProviderNames
()

Allows to access the names of the current registered providers.

public static Collection<MonetaryRounding>

Returns:

all javax.money.MonetaryRounding instances matching the query, never null.
getRoundings
(RoundingQuery
The javax.money.RoundingQuery that may contains arbitrary parameters to be evaluated.
roundingQuery
)

Access multiple MonetaryRounding instances using a possibly complex query

public static boolean

Returns:

true, if at least one MonetaryAmountFactory matches the query.
isAvailable
(MonetaryAmountFactoryQuery
the factory query, not null.
query
)

Allows to check if any of the getXXX methods return non empty/non null results of .MonetaryAmountFactory.

public static boolean

Returns:

true if Monetary#getCurrency(String, java.lang.String...) would return a result for the given code.
isCurrencyAvailable
(String
the currency code, not null.
code
,
String...
the (optional) specification of providers to consider.
providers
)

Allows to check if a CurrencyUnit instance is defined, i.e. accessible from Monetary#getCurrency(String, String...).

public static boolean

Returns:

true if getCurrencies(Locale, String...) would return a result containing a currency with the given code.
isCurrencyAvailable
(Locale
the target Locale, not null.
locale
,
String...
the (optional) specification of providers to consider.
providers
)

Allows to check if a javax.money.CurrencyUnit instance is defined, i.e. accessible from getCurrency(String, String...).

public static boolean

Returns:

true, if a corresponding javax.money.MonetaryRounding is available.
isRoundingAvailable
(String
The rounding identifier.
roundingName
,
String...
the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.
providers
)

Checks if a MonetaryRounding is available given a roundingId.

public static boolean

Returns:

true, if a corresponding javax.money.MonetaryRounding is available.
isRoundingAvailable
(CurrencyUnit
The currency, which determines the required scale. As java.math.RoundingMode, by default, java.math.RoundingMode#HALF_UP is used.
currencyUnit
,
String...
the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.
providers
)

Checks if a MonetaryRounding is available given a roundingId.

public static boolean

Returns:

true, if a corresponding javax.money.MonetaryRounding is available.
isRoundingAvailable
(RoundingQuery
The javax.money.RoundingQuery that may contains arbitrary parameters to be evaluated.
roundingQuery
)

Checks if a MonetaryRounding matching the query is available.

private static MonetaryAmountsSingletonQuerySpi
private static MonetaryAmountsSingletonSpi
private static MonetaryCurrenciesSingletonSpi
private static MonetaryRoundingsSingletonSpi
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Monetaryback to summary
private Monetary()

Private singletons constructor.

Method Detail

getAmountFactoriesback to summary
public static Collection<MonetaryAmountFactory<?>> getAmountFactories()

Access all currently available MonetaryAmount implementation classes that are accessible from this MonetaryAmount singleton.

Returns:Collection<MonetaryAmountFactory<?>>

all currently available MonetaryAmount implementation classes that have corresponding MonetaryAmountFactory instances provided, never null

getAmountFactoriesback to summary
public static Collection<MonetaryAmountFactory<?>> getAmountFactories(MonetaryAmountFactoryQuery query)

Returns all factory instances that match the query.

Parameters
query:MonetaryAmountFactoryQuery

the factory query, not null.

Returns:Collection<MonetaryAmountFactory<?>>

the instances found, never null.

getAmountFactoryback to summary
public static <T extends MonetaryAmount> MonetaryAmountFactory<T> getAmountFactory(Class<T> amountType)

Access an MonetaryAmountFactory for the given MonetaryAmount implementation type.

Parameters
amountType:Class<T>

MonetaryAmount implementation type, nor null.

Returns:MonetaryAmountFactory<T>

the corresponding MonetaryAmountFactory, never null.

Exceptions
MonetaryException:
if no MonetaryAmountFactory targeting the given MonetaryAmount implementation class is registered.
getAmountFactoryback to summary
public static MonetaryAmountFactory<T extends MonetaryAmount> getAmountFactory(MonetaryAmountFactoryQuery query)

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:MonetaryAmountFactoryQuery

the factory query, not null.

Returns:MonetaryAmountFactory<T extends MonetaryAmount>

the factory found, or null.

Annotations
@SuppressWarnings:rawtypes
getAmountTypesback to summary
public static Collection<Class<? extends MonetaryAmount>> getAmountTypes()

Access all currently available MonetaryAmount implementation classes that are accessible from this MonetaryAmount singleton.

Returns:Collection<Class<? extends MonetaryAmount>>

all currently available MonetaryAmount implementation classes that have corresponding MonetaryAmountFactory instances provided, never null

getCurrenciesback to summary
public static Set<CurrencyUnit> getCurrencies(Locale locale, String... providers)

Access a new instance based on the Locale. Currencies are available as provided by CurrencyProviderSpi instances registered with the javax.money.spi.Bootstrap.

Parameters
locale:Locale

the target Locale, typically representing an ISO country, not null.

providers:String[]

the (optional) specification of providers to consider.

Returns:Set<CurrencyUnit>

the corresponding CurrencyUnit instance.

Exceptions
UnknownCurrencyException:
if no such currency exists.
getCurrenciesback to summary
public static Collection<CurrencyUnit> getCurrencies(String... providers)

Access all currencies known.

Parameters
providers:String[]

the (optional) specification of providers to consider.

Returns:Collection<CurrencyUnit>

the list of known currencies, never null.

getCurrenciesback to summary
public static Collection<CurrencyUnit> getCurrencies(CurrencyQuery query)

Query all currencies matching the given query.

Parameters
query:CurrencyQuery

The javax.money.CurrencyQuery, not null.

Returns:Collection<CurrencyUnit>

the list of known currencies, never null.

getCurrencyback to summary
public static CurrencyUnit getCurrency(String currencyCode, String... providers)

Access a new instance based on the currency code. Currencies are available as provided by CurrencyProviderSpi instances registered with the javax.money.spi.Bootstrap.

Parameters
currencyCode:String

the ISO currency code, not null.

providers:String[]

the (optional) specification of providers to consider.

Returns:CurrencyUnit

the corresponding CurrencyUnit instance.

Exceptions
UnknownCurrencyException:
if no such currency exists.
getCurrencyback to summary
public static CurrencyUnit getCurrency(Locale locale, String... providers)

Access a new instance based on the Locale. Currencies are available as provided by CurrencyProviderSpi instances registered with the javax.money.spi.Bootstrap.

Parameters
locale:Locale

the target Locale, typically representing an ISO country, not null.

providers:String[]

the (optional) specification of providers to consider.

Returns:CurrencyUnit

the corresponding CurrencyUnit instance.

Exceptions
UnknownCurrencyException:
if no such currency exists.
getCurrencyback to summary
public static CurrencyUnit getCurrency(CurrencyQuery query)

Query all currencies matching the given query.

Parameters
query:CurrencyQuery

The javax.money.CurrencyQuery, not null.

Returns:CurrencyUnit

the list of known currencies, never null.

getCurrencyProviderNamesback to summary
public static Set<String> getCurrencyProviderNames()

Query all currencies matching the given query.

Returns:Set<String>

the list of known currencies, never null.

getDefaultAmountFactoryback to summary
public static MonetaryAmountFactory<?> getDefaultAmountFactory()

Access the default MonetaryAmountFactory as defined by javax.money.spi.MonetaryAmountsSingletonSpi#getDefaultAmountFactory().

Returns:MonetaryAmountFactory<?>

the MonetaryAmountFactory corresponding to default amount type, never null.

Exceptions
MonetaryException:
if no MonetaryAmountFactory targeting the default amount type implementation class is registered.
getDefaultAmountTypeback to summary
public static Class<? extends MonetaryAmount> getDefaultAmountType()

Access the default MonetaryAmount implementation class that is accessible from this MonetaryAmount singleton.

Returns:Class<? extends MonetaryAmount>

all current default MonetaryAmount implementation class, never null

getDefaultCurrencyProviderChainback to summary
public static List<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:List<String>

the ordered list provider names, modelling the default provider chain used, never null.

getDefaultRoundingback to summary
public static MonetaryRounding getDefaultRounding()

Creates a rounding that can be added as MonetaryOperator to chained calculations. The instance will lookup the concrete MonetaryOperator instance from the Monetary based on the input MonetaryAmount's CurrencyUnit.

Returns:MonetaryRounding

the (shared) default rounding instance.

getDefaultRoundingProviderChainback to summary
public static List<String> getDefaultRoundingProviderChain()

Allows to access the default providers chain used if no provider chain was passed explicitly..

Returns:List<String>

the chained list of provider names, never null.

getRoundingback to summary
public static MonetaryRounding getRounding(CurrencyUnit currencyUnit, String... providers)

Creates an MonetaryOperator for rounding MonetaryAmount instances given a currency.

Parameters
currencyUnit:CurrencyUnit

The currency, which determines the required scale. As java.math.RoundingMode, by default, java.math.RoundingMode#HALF_UP is used.

providers:String[]

the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.

Returns:MonetaryRounding

a new instance MonetaryOperator implementing the rounding, never null.

getRoundingback to summary
public static MonetaryRounding getRounding(String roundingName, String... providers)

Access an MonetaryOperator for custom rounding MonetaryAmount instances.

Parameters
roundingName:String

The rounding identifier.

providers:String[]

the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.

Returns:MonetaryRounding

the corresponding MonetaryOperator implementing the rounding, never null.

Exceptions
IllegalArgumentException:
if no such rounding is registered using a javax.money.spi.RoundingProviderSpi instance.
getRoundingback to summary
public static MonetaryRounding getRounding(RoundingQuery roundingQuery)

Access a MonetaryRounding using a possibly complex query.

Parameters
roundingQuery:RoundingQuery

The javax.money.RoundingQuery that may contains arbitrary parameters to be evaluated.

Returns:MonetaryRounding

the corresponding javax.money.MonetaryRounding, never null.

Exceptions
IllegalArgumentException:
if no such rounding is registered using a javax.money.spi.RoundingProviderSpi instance.
getRoundingNamesback to summary
public static Set<String> getRoundingNames(String... providers)

Allows to access the names of the current defined roundings.

Parameters
providers:String[]

the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.

Returns:Set<String>

the set of custom rounding ids, never null.

getRoundingProviderNamesback to summary
public static Set<String> getRoundingProviderNames()

Allows to access the names of the current registered providers.

Returns:Set<String>

the set of provider names, never null.

getRoundingsback to summary
public static Collection<MonetaryRounding> getRoundings(RoundingQuery roundingQuery)

Access multiple MonetaryRounding instances using a possibly complex query

Parameters
roundingQuery:RoundingQuery

The javax.money.RoundingQuery that may contains arbitrary parameters to be evaluated.

Returns:Collection<MonetaryRounding>

all javax.money.MonetaryRounding instances matching the query, never null.

isAvailableback to summary
public static boolean isAvailable(MonetaryAmountFactoryQuery query)

Allows to check if any of the getXXX methods return non empty/non null results of .MonetaryAmountFactory.

Parameters
query:MonetaryAmountFactoryQuery

the factory query, not null.

Returns:boolean

true, if at least one MonetaryAmountFactory matches the query.

isCurrencyAvailableback to summary
public static boolean isCurrencyAvailable(String code, String... providers)

Allows to check if a CurrencyUnit instance is defined, i.e. accessible from Monetary#getCurrency(String, String...).

Parameters
code:String

the currency code, not null.

providers:String[]

the (optional) specification of providers to consider.

Returns:boolean

true if Monetary#getCurrency(String, java.lang.String...) would return a result for the given code.

isCurrencyAvailableback to summary
public static boolean isCurrencyAvailable(Locale locale, String... providers)

Allows to check if a javax.money.CurrencyUnit instance is defined, i.e. accessible from getCurrency(String, String...).

Parameters
locale:Locale

the target Locale, not null.

providers:String[]

the (optional) specification of providers to consider.

Returns:boolean

true if getCurrencies(Locale, String...) would return a result containing a currency with the given code.

isRoundingAvailableback to summary
public static boolean isRoundingAvailable(String roundingName, String... providers)

Checks if a MonetaryRounding is available given a roundingId.

Parameters
roundingName:String

The rounding identifier.

providers:String[]

the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.

Returns:boolean

true, if a corresponding javax.money.MonetaryRounding is available.

Exceptions
IllegalArgumentException:
if no such rounding is registered using a javax.money.spi.RoundingProviderSpi instance.
isRoundingAvailableback to summary
public static boolean isRoundingAvailable(CurrencyUnit currencyUnit, String... providers)

Checks if a MonetaryRounding is available given a roundingId.

Parameters
currencyUnit:CurrencyUnit

The currency, which determines the required scale. As java.math.RoundingMode, by default, java.math.RoundingMode#HALF_UP is used.

providers:String[]

the providers and ordering to be used. By default providers and ordering as defined in #getDefaultProviders is used.

Returns:boolean

true, if a corresponding javax.money.MonetaryRounding is available.

Exceptions
IllegalArgumentException:
if no such rounding is registered using a javax.money.spi.RoundingProviderSpi instance.
isRoundingAvailableback to summary
public static boolean isRoundingAvailable(RoundingQuery roundingQuery)

Checks if a MonetaryRounding matching the query is available.

Parameters
roundingQuery:RoundingQuery

The javax.money.RoundingQuery that may contains arbitrary parameters to be evaluated.

Returns:boolean

true, if a corresponding javax.money.MonetaryRounding is available.

Exceptions
IllegalArgumentException:
if no such rounding is registered using a javax.money.spi.RoundingProviderSpi instance.
monetaryAmountsSingletonQuerySpiback to summary
private static MonetaryAmountsSingletonQuerySpi monetaryAmountsSingletonQuerySpi()

The used javax.money.spi.MonetaryAmountsSingletonSpi instance.

monetaryAmountsSingletonSpiback to summary
private static MonetaryAmountsSingletonSpi monetaryAmountsSingletonSpi()

The used javax.money.spi.MonetaryAmountsSingletonSpi instance.

monetaryCurrenciesSingletonSpiback to summary
private static MonetaryCurrenciesSingletonSpi monetaryCurrenciesSingletonSpi()

The used javax.money.spi.MonetaryCurrenciesSingletonSpi instance.

Returns:MonetaryCurrenciesSingletonSpi

the used javax.money.spi.MonetaryCurrenciesSingletonSpi instance, never null

monetaryRoundingsSingletonSpiback to summary
private static MonetaryRoundingsSingletonSpi monetaryRoundingsSingletonSpi()

The used javax.money.spi.MonetaryCurrenciesSingletonSpi instance.

Returns:MonetaryRoundingsSingletonSpi

the used javax.money.spi.MonetaryCurrenciesSingletonSpi instance, never null