Enum CurrencyUtils

java.lang.Object
java.lang.Enum<CurrencyUtils>
com.erudika.para.core.i18n.CurrencyUtils
All Implemented Interfaces:
Serializable, Comparable<CurrencyUtils>

public enum CurrencyUtils extends Enum<CurrencyUtils>
Helper utility class for currency operations.
Author:
Alex Bogdanovski [[email protected]]
  • Enum Constant Details

    • INSTANCE

      public static final CurrencyUtils INSTANCE
      Singleton.
  • Method Details

    • values

      public static CurrencyUtils[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static CurrencyUtils valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • formatPrice

      public abstract String formatPrice(Double price, String cur)
      Formats a price for its specific locale, depending on the currency code.
      Parameters:
      price - the amount
      cur - the 3-letter currency code
      Returns:
      a formatted price with its currency symbol
    • getCurrencyName

      public abstract String getCurrencyName(String cur, Locale locale)
      Returns the full name of the currency in the language of the given locale. Defaults to English.
      Parameters:
      cur - the 3-letter currency code
      locale - the locale
      Returns:
      the currency name or "" if the currency is unknown
    • getLocaleForCountry

      public abstract Locale getLocaleForCountry(String countryCode)
      Returns the locale for a given country code.
      Parameters:
      countryCode - the 2-letter country code
      Returns:
      a locale or null if countryCode is null
    • getCurrency

      public abstract Currency getCurrency(String cur)
      Returns the currency instance for a given currency code.
      Parameters:
      cur - the 3-letter currency code
      Returns:
      the currency
    • getCurrency

      public abstract Currency getCurrency(Locale loc)
      Returns the currency instance for a given locale.
      Parameters:
      loc - locale
      Returns:
      the currency instance or null if not found
    • getCurrenciesMap

      public abstract Map<String,String> getCurrenciesMap()
      Returns a map of all available currencies in the form: currency code - full currency name and symbol.
      Returns:
      a map of known currencies
    • isValidCurrency

      public abstract boolean isValidCurrency(String cur)
      Validate the currency code.
      Parameters:
      cur - a 3-letter curency code
      Returns:
      true if the code corresponds to a valid currency
    • getInstance

      public static CurrencyUtils getInstance()
      Returns an instance of this class.
      Returns:
      an instance