Module java.money
Package javax.money

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

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