Module java.money

Interface MonetaryRoundingsSingletonSpi

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

      java.util.Collection<MonetaryRounding> getRoundings​(RoundingQuery query)
      Execute a query for MonetaryRounding. 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 a MonetaryRounding that can be added as MonetaryOperator to chained calculations. The instance must lookup the concrete MonetaryRounding instance from the MonetaryRoundingsSingletonSpi based on the input MonetaryAmount's CurrencyUnit.
      Returns:
      the (shared) default rounding instance.
    • getRounding

      default MonetaryRounding getRounding​(CurrencyUnit currencyUnit, java.lang.String... providers)
      Access a MonetaryRounding for rounding MonetaryAmount instances given a currency.
      Parameters:
      currencyUnit - The currency, which determines the required precision. As RoundingMode, 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, never null.
      Throws:
      MonetaryException - if no such rounding could be provided.
    • getRounding

      default MonetaryRounding getRounding​(java.lang.String roundingName, java.lang.String... providers)
      Access a MonetaryRounding 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, never null.
      Throws:
      java.lang.IllegalArgumentException - if no such rounding is registered using a RoundingProviderSpi instance.
    • getRounding

      default MonetaryRounding getRounding​(RoundingQuery query)
      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 setting AbstractQuery.getProviderNames().
      Parameters:
      query - the rounding query, not null.
      Returns:
      the rounding found, or null, if no rounding matches the query.
    • isRoundingAvailable

      default boolean isRoundingAvailable​(RoundingQuery query)
      Checks if any MonetaryRounding 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 a MonetaryRounding 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 a RoundingProviderSpi instance.
    • isRoundingAvailable

      default boolean isRoundingAvailable​(CurrencyUnit currencyUnit, java.lang.String... providers)
      Checks if a MonetaryRounding is available given a CurrencyUnit.
      Parameters:
      currencyUnit - The currency, which determines the required precision. As RoundingMode, 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 a RoundingProviderSpi instance.