- All Known Implementing Classes:
DefaultMonetaryRoundingsSingletonSpi
public interface MonetaryRoundingsSingletonSpi
This class models the accessor for rounding instances, modeled as
MonetaryOperator
.
This class is thread-safe.
- Author:
- Anatole Tresch, Werner Keil
-
Method Summary
Modifier and Type Method Description java.util.List<java.lang.String>
getDefaultProviderChain()
Access a list of the currently registered default providers.MonetaryRounding
getDefaultRounding()
Creates aMonetaryRounding
that can be added asMonetaryOperator
to chained calculations.java.util.Set<java.lang.String>
getProviderNames()
Allows to access the names of the current registered rounding providers.default MonetaryRounding
getRounding(java.lang.String roundingName, java.lang.String... providers)
Access aMonetaryRounding
using the rounding name.default MonetaryRounding
getRounding(CurrencyUnit currencyUnit, java.lang.String... providers)
Access aMonetaryRounding
for roundingMonetaryAmount
instances given a currency.default MonetaryRounding
getRounding(RoundingQuery query)
Query a specific rounding with the given query.java.util.Set<java.lang.String>
getRoundingNames(java.lang.String... providers)
Allows to access the names of the current defined roundings.java.util.Collection<MonetaryRounding>
getRoundings(RoundingQuery query)
Execute a query forMonetaryRounding
.default boolean
isRoundingAvailable(java.lang.String roundingId, java.lang.String... providers)
Checks if aMonetaryRounding
is available given a roundingId.default boolean
isRoundingAvailable(CurrencyUnit currencyUnit, java.lang.String... providers)
Checks if aMonetaryRounding
is available given aCurrencyUnit
.default boolean
isRoundingAvailable(RoundingQuery query)
Checks if anyMonetaryRounding
is matching the given query.
-
Method Details
-
getRoundingNames
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
.
-
getProviderNames
java.util.Set<java.lang.String> getProviderNames()Allows to access the names of the current registered rounding providers.- Returns:
- the set of provider names, never
null
.
-
getDefaultProviderChain
java.util.List<java.lang.String> getDefaultProviderChain()Access a list of the currently registered default providers. The default providers are used, when no provider names are passed by the caller.- Returns:
- the provider names in order, defining the provider chain.
The default provider chain configured in
javamoney.properties
is used. - See Also:
RoundingQueryBuilder
-
getRoundings
Execute a query forMonetaryRounding
. This allows to model more complex used cases, such as historic or special roundings.- Parameters:
query
- the query to be expected, not null.- Returns:
- the roundings found, never null.
-
getDefaultRounding
MonetaryRounding getDefaultRounding()Creates aMonetaryRounding
that can be added asMonetaryOperator
to chained calculations. The instance must lookup the concreteMonetaryRounding
instance from theMonetaryRoundingsSingletonSpi
based on the inputMonetaryAmount
'sCurrencyUnit
.- Returns:
- the (shared) default rounding instance.
-
getRounding
Access aMonetaryRounding
for roundingMonetaryAmount
instances given a currency.- Parameters:
currencyUnit
- The currency, which determines the required precision. AsRoundingMode
, by default,RoundingMode.HALF_UP
is sued.providers
- the optional provider list and ordering to be used- Returns:
- a new instance
MonetaryOperator
implementing the rounding, nevernull
. - Throws:
MonetaryException
- if no such rounding could be provided.
-
getRounding
Access aMonetaryRounding
using the rounding name.- Parameters:
roundingName
- The rounding name, not null.providers
- the optional provider list and ordering to be used- Returns:
- the corresponding
MonetaryOperator
implementing the rounding, nevernull
. - Throws:
java.lang.IllegalArgumentException
- if no such rounding is registered using aRoundingProviderSpi
instance.
-
getRounding
Query a specific rounding with the given query. If multiple roundings match the query the first one is selected, since the query allows to determine the providers and their ordering by settingAbstractQuery.getProviderNames()
.- Parameters:
query
- the rounding query, not null.- Returns:
- the rounding found, or null, if no rounding matches the query.
-
isRoundingAvailable
Checks if anyMonetaryRounding
is matching the given query.- Parameters:
query
- the rounding query, not null.- Returns:
- true, if at least one rounding matches the query.
-
isRoundingAvailable
default boolean isRoundingAvailable(java.lang.String roundingId, java.lang.String... providers)Checks if aMonetaryRounding
is available given a roundingId.- Parameters:
roundingId
- 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
Checks if aMonetaryRounding
is available given aCurrencyUnit
.- Parameters:
currencyUnit
- The currency, which determines the required precision. 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.
-