Enum Class CurrencyCode

java.lang.Object
java.lang.Enum<CurrencyCode>
com.luna.common.i18n.CurrencyCode
All Implemented Interfaces:
Serializable, Comparable<CurrencyCode>, java.lang.constant.Constable

public enum CurrencyCode extends Enum<CurrencyCode>
Currency code (ISO 4217).

The initial entries in this enum was created based on the official currency & funds code list (ISO 4217) of January 1, 2014.

Since:
1.9
Author:
Takahiko Kawasaki
See Also:
  • Enum Constant Details

  • Method Details

    • values

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

      public static CurrencyCode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified name
      NullPointerException - if the argument is null
    • getByCode

      public static CurrencyCode getByCode(String code)
      Get a CurrencyCode that corresponds to the given ISO 4217 alpha-3 code.

      This method calls getByCode(code, true). Note that the behavior has changed since the version 1.13. In the older versions, this method was an alias of getByCode(code, false).

      Parameters:
      code - ISO 4217 alpha-3 code. When "UNDEFINED" is given, CurrencyCode.UNDEFINED is returned.
      Returns:
      A CurrencyCode instance, or null if not found.
      See Also:
    • getByCodeIgnoreCase

      public static CurrencyCode getByCodeIgnoreCase(String code)
      Get a CurrencyCode that corresponds to the given ISO 4217 alpha-3 code.

      This method calls getByCode(code, false).

      Parameters:
      code - ISO 4217 alpha-3 code. Or "UNDEFINED" (case insensitive).
      Returns:
      A CurrencyCode instance, or null if not found.
      Since:
      1.13
      See Also:
    • getByCode

      public static CurrencyCode getByCode(String code, boolean caseSensitive)
      Get a CurrencyCode that corresponds to the given ISO 4217 alpha-3 code.
      Parameters:
      code - ISO 4217 alpha-3 code. Or "UNDEFINED" (its case sensitivity depends on the value of caseSensitive).
      caseSensitive - If true, the given code should consist of upper-case letters only. If false, this method internally canonicalizes the given code by String.toUpperCase() and then performs search. For example, getByCode("jpy", true) returns null, but on the other hand, getByCode("jpy", false) returns CurrencyCode.JPY.
      Returns:
      A CurrencyCode instance, or null if not found.
    • getByCode

      public static CurrencyCode getByCode(int code)
      Get a CurrencyCode that corresponds to the given ISO 4217 numeric code.
      Parameters:
      code - ISO 4217 numeric code.
      Returns:
      A CurrencyCode instance, or null if not found. If 0 or a negative value is given, null is returned.
    • getByCountry

      public static List<CurrencyCode> getByCountry(String country)
      Get a list of CurrencyCode instances whose country list contains the specified country.

      This method is an alias of getByCountry(country, true). Note that the behavior has changed since the version 1.13. In the older versions, this method was an alias of getByCountry(code, false).

      Parameters:
      country - Country code. ISO 3166-1 alpha-2 or alpha-3.
      Returns:
      List of CurrencyCode instances. If there is no CurrencyCode instance whose country list contains the specified country, the size of the returned list is zero.
    • getByCountryIgnoreCase

      public static List<CurrencyCode> getByCountryIgnoreCase(String country)
      Get a list of CurrencyCode instances whose country list contains the specified country.

      This method is an alias of getByCountry(country, false).

      Parameters:
      country - Country code. ISO 3166-1 alpha-2 or alpha-3.
      Returns:
      List of CurrencyCode instances. If there is no CurrencyCode instance whose country list contains the specified country, the size of the returned list is zero.
      Since:
      1.13
    • getByCountry

      public static List<CurrencyCode> getByCountry(String country, boolean caseSensitive)
      Get a list of CurrencyCode instances whose country list contains the specified country.

      This method is an alias of getByCountry(CountryCode.getByCode (country, caseSensitive)).

      Parameters:
      country - Country code. ISO 3166-1 alpha-2 or alpha-3.
      caseSensitive - If true, the given code should consist of uppercase letters only. If false, case is ignored.
      Returns:
      List of CurrencyCode instances. If there is no CurrencyCode instance whose country list contains the specified country, the size of the returned list is zero.
    • getByCountry

      public static List<CurrencyCode> getByCountry(CountryCode country)
      Get a list of CurrencyCode instances whose country list contains the specified country.
      Parameters:
      country - CountryCode instance that represents a country.
      Returns:
      List of CurrencyCode instances. If there is no CurrencyCode instance whose country list contains the specified country, the size of the returned list is zero.
    • findByName

      public static List<CurrencyCode> findByName(String regex)
      Get a list of CurrencyCode by a name regular expression.

      This method is almost equivalent to findByName(Pattern.compile(regex)).

      Parameters:
      regex - Regular expression for names.
      Returns:
      List of CurrencyCode. If nothing has matched, an empty list is returned.
      Throws:
      IllegalArgumentException - regex is null.
      PatternSyntaxException - regex failed to be compiled.
      Since:
      1.11
    • findByName

      public static List<CurrencyCode> findByName(Pattern pattern)
      Get a list of CurrencyCode by a name pattern.

      For example, the list obtained by the code snippet below:

       Pattern pattern = Pattern.compile(".*Ruble");
       List<CurrencyCode> list = CurrencyCode.findByName(pattern);
       

      contains 4 CurrencyCodes as listed below.

      1. BYN : Belarusian Ruble
      2. BYR : Belarusian Ruble
      3. RUB : Russian Ruble
      4. RUR : Russian Ruble
      Parameters:
      pattern - Pattern to match names.
      Returns:
      List of CurrencyCde. If nothing has matched, an empty list is returned.
      Throws:
      IllegalArgumentException - pattern is null.
      Since:
      1.11
    • getName

      public String getName()
      Get the currency name.
      Returns:
      The currency name.
    • getNumeric

      public int getNumeric()
      Get the ISO 4217 numeric code.
      Returns:
      The ISO 4217 numeric code.
    • getMinorUnit

      public int getMinorUnit()
      Get the minor unit.
      Returns:
      The minor unit. -1 means N.A.
    • getCountryList

      public List<CountryCode> getCountryList()
      Get the list of countries using this currency.
      Returns:
      The list of countries using this currency.
    • isFund

      public boolean isFund()
      Check if this currency code represents a fund.

      CurrencyCode instances listed below return true.

      • BOV Mvdol
      • CHE WIR EUro
      • CHW WIR Franc
      • CLF Unidad de Fomento
      • COU Unidad de Valor Real
      • MXV Mexican Unidad de Inversion (UDI)
      • USN US Dollar (Next day)
      • USS US Dollar (Same day)
      • UYI Uruguay Peso en Unidades
      Returns:
      True if this currency code represents a fund.
    • isPreciousMetal

      public boolean isPreciousMetal()
      Check if this currency code represents a precious metal.

      CurrencyCode instances listed below return true.

      Returns:
      True if this currency code represents a precious metal.
    • getCurrency

      public Currency getCurrency()
      Get the Currency instance that corresponds to this currency code.

      This method is an alias of Currency.getInstance(this.name()). The only difference is that this method returns null when Currency.getInstance(String) throws IllegalArgumentException.

      Returns:
      A Currency instance, or null if this ISO 4217 code is not supported by the implementation of Currency.getInstance(String).
      See Also: