- 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.MonetaryRoundinggetDefaultRounding()Creates aMonetaryRoundingthat can be added asMonetaryOperatorto chained calculations.java.util.Set<java.lang.String>getProviderNames()Allows to access the names of the current registered rounding providers.default MonetaryRoundinggetRounding(java.lang.String roundingName, java.lang.String... providers)Access aMonetaryRoundingusing the rounding name.default MonetaryRoundinggetRounding(CurrencyUnit currencyUnit, java.lang.String... providers)Access aMonetaryRoundingfor roundingMonetaryAmountinstances given a currency.default MonetaryRoundinggetRounding(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 booleanisRoundingAvailable(java.lang.String roundingId, java.lang.String... providers)Checks if aMonetaryRoundingis available given a roundingId.default booleanisRoundingAvailable(CurrencyUnit currencyUnit, java.lang.String... providers)Checks if aMonetaryRoundingis available given aCurrencyUnit.default booleanisRoundingAvailable(RoundingQuery query)Checks if anyMonetaryRoundingis 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.propertiesis 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 aMonetaryRoundingthat can be added asMonetaryOperatorto chained calculations. The instance must lookup the concreteMonetaryRoundinginstance from theMonetaryRoundingsSingletonSpibased on the inputMonetaryAmount'sCurrencyUnit.- Returns:
- the (shared) default rounding instance.
-
getRounding
Access aMonetaryRoundingfor roundingMonetaryAmountinstances given a currency.- Parameters:
currencyUnit- The currency, which determines the required precision. AsRoundingMode, by default,RoundingMode.HALF_UPis sued.providers- the optional provider list and ordering to be used- Returns:
- a new instance
MonetaryOperatorimplementing the rounding, nevernull. - Throws:
MonetaryException- if no such rounding could be provided.
-
getRounding
Access aMonetaryRoundingusing the rounding name.- Parameters:
roundingName- The rounding name, not null.providers- the optional provider list and ordering to be used- Returns:
- the corresponding
MonetaryOperatorimplementing the rounding, nevernull. - Throws:
java.lang.IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
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 anyMonetaryRoundingis 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 aMonetaryRoundingis 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
MonetaryRoundingis available. - Throws:
java.lang.IllegalArgumentException- if no such rounding is registered using aRoundingProviderSpiinstance.
-
isRoundingAvailable
Checks if aMonetaryRoundingis available given aCurrencyUnit.- Parameters:
currencyUnit- The currency, which determines the required precision. 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.
-