Module java.money
Package javax.money

Class Monetary

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

      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:
      the (shared) default rounding instance.
    • getRounding

      public static MonetaryRounding getRounding​(CurrencyUnit currencyUnit, java.lang.String... providers)
      Creates an MonetaryOperator for rounding MonetaryAmount instances given a currency.
      Parameters:
      currencyUnit - The currency, which determines the required scale. 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:
      a new instance MonetaryOperator implementing the rounding, never null.
    • getRounding

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

      public static MonetaryRounding getRounding​(RoundingQuery roundingQuery)
      Access a MonetaryRounding using a possibly complex query.
      Parameters:
      roundingQuery - The RoundingQuery that may contains arbitrary parameters to be evaluated.
      Returns:
      the corresponding MonetaryRounding, never null.
      Throws:
      java.lang.IllegalArgumentException - if no such rounding is registered using a RoundingProviderSpi instance.
    • isRoundingAvailable

      public static boolean isRoundingAvailable​(java.lang.String roundingName, java.lang.String... providers)
      Checks if a MonetaryRounding 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 a RoundingProviderSpi instance.
    • isRoundingAvailable

      public static boolean isRoundingAvailable​(CurrencyUnit currencyUnit, java.lang.String... providers)
      Checks if a MonetaryRounding is available given a roundingId.
      Parameters:
      currencyUnit - The currency, which determines the required scale. 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.
    • isRoundingAvailable

      public static boolean isRoundingAvailable​(RoundingQuery roundingQuery)
      Checks if a MonetaryRounding matching the query is available.
      Parameters:
      roundingQuery - The RoundingQuery 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 a RoundingProviderSpi instance.
    • getRoundings

      public static java.util.Collection<MonetaryRounding> getRoundings​(RoundingQuery roundingQuery)
      Access multiple MonetaryRounding instances using a possibly complex query
      Parameters:
      roundingQuery - The RoundingQuery that may contains arbitrary parameters to be evaluated.
      Returns:
      all MonetaryRounding instances matching the query, never null.
    • 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 an MonetaryAmountFactory for the given MonetaryAmount implementation type.
      Parameters:
      amountType - MonetaryAmount implementation type, nor null.
      Returns:
      the corresponding MonetaryAmountFactory, never null.
      Throws:
      MonetaryException - if no MonetaryAmountFactory targeting the given MonetaryAmount implementation class is registered.
    • getDefaultAmountFactory

      public static MonetaryAmountFactory<?> getDefaultAmountFactory()
      Returns:
      the MonetaryAmountFactory corresponding to default amount type, never null.
      Throws:
      MonetaryException - if no MonetaryAmountFactory targeting the default amount type implementation class is registered.
    • getAmountFactories

      public static java.util.Collection<MonetaryAmountFactory<?>> getAmountFactories()
      Access all currently available MonetaryAmount implementation classes that are accessible from this MonetaryAmount singleton.
      Returns:
      all currently available MonetaryAmount implementation classes that have corresponding MonetaryAmountFactory instances provided, never null
    • getAmountTypes

      public static java.util.Collection<java.lang.Class<? extends MonetaryAmount>> getAmountTypes()
      Access all currently available MonetaryAmount implementation classes that are accessible from this MonetaryAmount singleton.
      Returns:
      all currently available MonetaryAmount implementation classes that have corresponding MonetaryAmountFactory instances provided, never null
    • getDefaultAmountType

      public static java.lang.Class<? extends MonetaryAmount> getDefaultAmountType()
      Access the default MonetaryAmount implementation class that is accessible from this MonetaryAmount singleton.
      Returns:
      all current default MonetaryAmount implementation class, never null
    • getAmountFactory

      public static MonetaryAmountFactory 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 - 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

      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 - 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 by CurrencyProviderSpi instances registered with the Bootstrap.
      Parameters:
      currencyCode - the ISO currency code, not null.
      providers - the (optional) specification of providers to consider.
      Returns:
      the corresponding CurrencyUnit instance.
      Throws:
      UnknownCurrencyException - if no such currency exists.
    • getCurrency

      public static CurrencyUnit getCurrency​(java.util.Locale locale, java.lang.String... providers)
      Access a new instance based on the Locale. Currencies are available as provided by CurrencyProviderSpi instances registered with the Bootstrap.
      Parameters:
      locale - the target Locale, typically representing an ISO country, not null.
      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 the Locale. Currencies are available as provided by CurrencyProviderSpi instances registered with the Bootstrap.
      Parameters:
      locale - the target Locale, typically representing an ISO country, not null.
      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 a CurrencyUnit instance is defined, i.e. accessible from getCurrency(String, String...).
      Parameters:
      code - the currency code, not null.
      providers - the (optional) specification of providers to consider.
      Returns:
      true if getCurrency(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 a CurrencyUnit instance is defined, i.e. accessible from getCurrency(String, String...).
      Parameters:
      locale - the target Locale, not null.
      providers - the (optional) specification of providers to consider.
      Returns:
      true if getCurrencies(Locale, String...) would return a result containing a currency with the given code.
    • getCurrencies

      public static java.util.Collection<CurrencyUnit> getCurrencies​(java.lang.String... providers)
      Access all currencies known.
      Parameters:
      providers - the (optional) specification of providers to consider.
      Returns:
      the list of known currencies, never null.
    • getCurrency

      public static CurrencyUnit getCurrency​(CurrencyQuery query)
      Query all currencies matching the given query.
      Parameters:
      query - The CurrencyQuery, not null.
      Returns:
      the list of known currencies, never null.
    • getCurrencies

      public static java.util.Collection<CurrencyUnit> getCurrencies​(CurrencyQuery query)
      Query all currencies matching the given query.
      Parameters:
      query - The CurrencyQuery, 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.