Enum Class NumberSystem

java.lang.Object
java.lang.Enum<NumberSystem>
net.time4j.format.NumberSystem
All Implemented Interfaces:
Serializable, Comparable<NumberSystem>, java.lang.constant.Constable

public enum NumberSystem extends Enum<NumberSystem>

Defines the number system.

Attention: This enum can only handle non-negative integers.

Since:
3.11/4.8
Author:
Meno Hochschild
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Arabic numbers with the decimal digits 0-9 (default setting).
    Arabic-Indic numbers (used in many Arabic countries).
    Extended Arabic-Indic numbers (used for example in Iran).
    The Bengali digits used in parts of India.
    The Chinese decimal system mainly used for years.
    The Chinese day counting system used for the day of month in lunar calendar in the range 1-32.
    The Chinese numbers in the Mandarin dialect limited to the range 0-9999.
    Like CHINESE_MANDARIN but with the main difference of printing the zero character as "〇".
    The Devanagari digits used in parts of India.
    Dozenal numbers describe a 12-based positional numbering system.
    Ethiopic numerals (always positive).
    The Gujarati digits used in parts of India.
    The Gurmukhi digits used mainly by Sikhs in parts of India.
    The Japanese numbers limited to the range 1-9999.
    Traditional number system used by Khmer people in Cambodia.
    The pure Korean numbers in Hangul script limited to the range 1-99.
    The Sino-Korean numbers in Hangul script limited to the range 0-9999.
    Traditional number system used in Laos.
    The number system used in Myanmar (Burma).
    The Orya digits used in parts of India.
    Roman numerals in range 1-3999.
    The Telugu digits used in parts of India.
    The Thai digits used in Thailand (Siam).
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains​(char digit)
    Does this number system contains given digit char?
    Obtains an identifier which can be used together with the unicode extension "nu" in Locale-parameters.
    Defines all digit characters from the smallest to the largest one.
    boolean
    Does this number system describe a decimal system where all associated code points can be mapped to the range 0-9?
    boolean
    Does this number system describe a decimal system where the digits can be mapped to the range 0-9?
    int
    toInteger​(String numeral)
    Converts given text numeral to an integer in smart mode.
    int
    toInteger​(String numeral, Leniency leniency)
    Converts given text numeral to an integer.
    toNumeral​(int number)
    Converts given integer to a text numeral.
    int
    toNumeral​(int number, Appendable buffer)
    Converts given integer to a text numeral which will then be written into buffer.
    valueOf​(String name)
    Returns the enum constant of this class with the specified name.
    static NumberSystem[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Enum

    compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • ARABIC

      public static final NumberSystem ARABIC
      Arabic numbers with the decimal digits 0-9 (default setting).

      This number system is used worldwide. Direct conversion of negative integers is not supported. Code: "latn" as inconsistently defined in CLDR (has nothing to do with Latin).

    • ARABIC_INDIC

      public static final NumberSystem ARABIC_INDIC
      Arabic-Indic numbers (used in many Arabic countries).

      Note: Must not be negative. Code: "arab" as defined shortened in CLDR.

      Since:
      3.23/4.19
    • ARABIC_INDIC_EXT

      public static final NumberSystem ARABIC_INDIC_EXT
      Extended Arabic-Indic numbers (used for example in Iran).

      Note: Must not be negative. Code: "arabext".

      Since:
      3.23/4.19
    • BENGALI

      public static final NumberSystem BENGALI
      The Bengali digits used in parts of India.

      Note: Must not be negative. Code: "beng".

      Since:
      3.23/4.19
    • CHINESE_DECIMAL

      public static final NumberSystem CHINESE_DECIMAL
      The Chinese decimal system mainly used for years.

      Whole numbers will be read as digit by digit. When parsing, the special zero char "〇" will be handled like the default zero char "零". The method getDigits() contains both zero char variants. Example: The output of NumberSystem.CHINESE_DECIMAL.toInteger("二零零九") will be 2009, the same with the input 二〇〇九.

      Important note: Although this number system can be almost handled like other decimal systems, it is not such one. Its method isDecimal() will always yield the result false, because a) the codepoints of all digits are not mappable to the range 0-9 and b) an alternative zero character exists.

      Example of usage:

        ChronoFormatter<PlainDate> f = 
                  ChronoFormatter.setUp(PlainDate.axis(), Locale.CHINA)
                      .startSection(Attributes.NUMBER_SYSTEM, NumberSystem.CHINESE_DECIMAL)
                      .addPattern("yyyy年M月", PatternType.CLDR)
                      .endSection()
                      .startSection(Attributes.NUMBER_SYSTEM, NumberSystem.CHINESE_MANDARIN)
                      .addPattern("d日", PatternType.CLDR)
                      .endSection()
                      .build();
              PlainDate date = f.parse("二零零九年零一月十三日"); 
              System.out.println(date); // 2009-01-13
       

      Note: Must not be negative. Code: "hanidec".

      Since:
      5.9
      See Also:
      CHINESE_MANDARIN
    • CHINESE_LUNAR_DAYS

      public static final NumberSystem CHINESE_LUNAR_DAYS
      The Chinese day counting system used for the day of month in lunar calendar in the range 1-32.

      In Chinese the days of the lunar month have special numbering. Days 1-10 use 初一, 初二, … 初十. For days 21-29 the number is formed using 廿 instead of 二十 to indicate 20. Attention: It is not usual to apply this numbering style in the context of gregorian calendar where arabic digits are far more appropriate, even in Chinese language.

      Note: The numbers 31 and 32 are not used in the Chinese calendar but maybe in other lunar calendars.

      Example of usage:

              ChronoFormatter<ChineseCalendar> formatter =
                  ChronoFormatter.setUp(ChineseCalendar.axis(), Locale.CHINA)
                      .addPattern("r(U)MMMM", PatternType.CLDR_DATE)
                      .startSection(Attributes.NUMBER_SYSTEM, NumberSystem.CHINESE_LUNAR_DAYS)
                      .addPattern("d日(", PatternType.CLDR)
                      .endSection()
                      .addCustomized( // zodiac printer
                          ChineseCalendar.YEAR_OF_CYCLE, 
                          (CyclicYear year, StringBuilder buffer, AttributeQuery attrs) -> {
                              buffer.append(year.getZodiac(Locale.TRADITIONAL_CHINESE));
                              return Collections.emptySet();
                          },
                          ChronoParser.unsupported())
                      .addLiteral(')')
                      .build();
              assertThat(
                  formatter.format(ChineseCalendar.ofNewYear(2024)),
                  is("2024(甲辰)正月初一日(龍)"));
       

      Note: Must not be negative or zero. Code: "hanidays".

      Since:
      5.9.4
      See Also:
      CHINESE_MANDARIN
    • CHINESE_MANDARIN

      public static final NumberSystem CHINESE_MANDARIN
      The Chinese numbers in the Mandarin dialect limited to the range 0-9999.

      It is not a decimal system but simulates the spoken numbers. The sign "兩" will replace the sign "二" (=2) for all numbers 200 or greater. When parsing, both 2-versions are supported. And the special zero char "〇" will be handled like the default zero char "零".

      Note: This numbering system can also be used in Taiwan because traditional Chinese differs from this system only for numbers at 10,000 or above.

      See also Wikibooks. The code is: "mandarin".

      Since:
      5.9
      See Also:
      CHINESE_DECIMAL, CHINESE_SIMPLIFIED
    • CHINESE_SIMPLIFIED

      public static final NumberSystem CHINESE_SIMPLIFIED
      Like CHINESE_MANDARIN but with the main difference of printing the zero character as "〇".

      Furthermore, the 2-char in all numbers greater than 199 will always be printed using "二".

      The code is: "hans".

      Since:
      5.9.4
      See Also:
      CHINESE_MANDARIN
    • DEVANAGARI

      public static final NumberSystem DEVANAGARI
      The Devanagari digits used in parts of India.

      Note: Must not be negative. Code: "deva".

      Since:
      3.23/4.19
    • DOZENAL

      public static final NumberSystem DOZENAL
      Dozenal numbers describe a 12-based positional numbering system.

      See also Wikipedia. Note: Must not be negative. Code: "dozenal" (no CLDR-equivalent).

      Since:
      3.26/4.22
    • ETHIOPIC

      public static final NumberSystem ETHIOPIC
      Ethiopic numerals (always positive).

      See also A Look at Ethiopic Numerals. Attention: This enum is not a decimal system. Code: "ethiopic".

    • GUJARATI

      public static final NumberSystem GUJARATI
      The Gujarati digits used in parts of India.

      Note: Must not be negative. Code: "gujr".

      Since:
      3.23/4.19
    • GURMUKHI

      public static final NumberSystem GURMUKHI
      The Gurmukhi digits used mainly by Sikhs in parts of India.

      Note: Must not be negative. Code: "guru".

      Since:
      5.9
    • JAPANESE

      public static final NumberSystem JAPANESE
      The Japanese numbers limited to the range 1-9999.

      It is not a decimal system but simulates the spoken numbers. See also Wikipedia. The code is: "jpan".

      Since:
      3.32/4.27
    • KHMER

      public static final NumberSystem KHMER
      Traditional number system used by Khmer people in Cambodia.

      Note: Must not be negative. Code: "khmr".

      Since:
      3.23/4.19
    • KOREAN_NATIVE

      public static final NumberSystem KOREAN_NATIVE
      The pure Korean numbers in Hangul script limited to the range 1-99.

      It is not a decimal system and is often used for hour values. See also Wikipedia. The code is: "korean" (no CLDR-equivalent).

      Since:
      5.9
      See Also:
      KOREAN_SINO
    • KOREAN_SINO

      public static final NumberSystem KOREAN_SINO
      The Sino-Korean numbers in Hangul script limited to the range 0-9999.

      It is not really a decimal system but similar to the Japanese system. See also Wikipedia. Alternative characters like &#xB839; and &#xACF5; for zero or &#xB959; for the digit six are accepted in parsing, too, if leniency is not strict. The code is: "koreansino" (no CLDR-equivalent).

      Since:
      5.9
      See Also:
      KOREAN_NATIVE
    • LAO

      public static final NumberSystem LAO
      Traditional number system used in Laos.

      Note: Must not be negative. Code: "laoo".

      Since:
      5.9
    • MYANMAR

      public static final NumberSystem MYANMAR
      The number system used in Myanmar (Burma).

      Note: Must not be negative. Code: "mymr".

      Since:
      3.23/4.19
    • ORYA

      public static final NumberSystem ORYA
      The Orya digits used in parts of India.

      Note: Must not be negative. Code: "orya".

      Since:
      3.37/4.32
    • ROMAN

      public static final NumberSystem ROMAN
      Roman numerals in range 1-3999.

      If the leniency is strict then parsing of Roman numerals will only follow modern usage. The parsing is always case-insensitive. See also Roman Numerals. Code: "roman" (deviation from CLDR).

    • TELUGU

      public static final NumberSystem TELUGU
      The Telugu digits used in parts of India.

      Note: Must not be negative. Code: "telu".

      Since:
      3.23/4.19
    • THAI

      public static final NumberSystem THAI
      The Thai digits used in Thailand (Siam).

      Note: Must not be negative. Code: "thai".

      Since:
      3.23/4.19
  • Method Details

    • values

      public static NumberSystem[] 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 NumberSystem 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
    • toNumeral

      public String toNumeral(int number)

      Converts given integer to a text numeral.

      Parameters:
      number - number to be displayed as text
      Returns:
      text numeral
      Throws:
      IllegalArgumentException - if the conversion is not supported for given number
      Since:
      3.11/4.8
    • toNumeral

      public int toNumeral(int number, Appendable buffer) throws IOException

      Converts given integer to a text numeral which will then be written into buffer.

      Parameters:
      number - number to be displayed as text
      buffer - the buffer where any formatted number goes to
      Returns:
      count of characters written to the buffer
      Throws:
      IllegalArgumentException - if the conversion is not supported for given number
      IOException - if writing to the buffer fails
      Since:
      3.27/4.22
    • toInteger

      public final int toInteger(String numeral)

      Converts given text numeral to an integer in smart mode.

      Parameters:
      numeral - text numeral to be evaluated as number
      Returns:
      integer
      Throws:
      IllegalArgumentException - if given number has wrong format
      ArithmeticException - if int-range overflows
      Since:
      3.11/4.8
    • toInteger

      public int toInteger(String numeral, Leniency leniency)

      Converts given text numeral to an integer.

      In most cases, the leniency will not be taken into account, but parsing of some odd roman numerals can be enabled in non-strict mode (for example: IIXX instead of XVIII).

      Parameters:
      numeral - text numeral to be evaluated as number
      leniency - determines how lenient the parsing of given numeral should be
      Returns:
      integer
      Throws:
      IllegalArgumentException - if given number has wrong format
      ArithmeticException - if int-range overflows
      Since:
      3.15/4.12
    • contains

      public boolean contains(char digit)

      Does this number system contains given digit char?

      Parameters:
      digit - numerical char to be checked
      Returns:
      boolean
      Since:
      3.11/4.8
    • getDigits

      public String getDigits()

      Defines all digit characters from the smallest to the largest one.

      Note: If letters are used as digits then the upper case will be used. Pure decimal systems always use 10 digits here from zero to nine in ascending order.

      Returns:
      String containing all valid digit characters in ascending order
      Since:
      3.23/4.19
    • isDecimal

      public boolean isDecimal()

      Does this number system describe a decimal system where the digits can be mapped to the range 0-9?

      Every decimal system defines the first character of the result of getDigits() as zero character.

      Returns:
      boolean
      Since:
      3.23/4.19
    • hasDecimalCodepoints

      public boolean hasDecimalCodepoints()

      Does this number system describe a decimal system where all associated code points can be mapped to the range 0-9?

      There must be exactly 10 digit characters whose code points are in same numerical order from 0 to 9, each with step width 1. The default implementation just delegates to isDecimal().

      Returns:
      boolean
      Since:
      5.9
    • getCode

      public String getCode()

      Obtains an identifier which can be used together with the unicode extension "nu" in Locale-parameters.

      Example: Locale.forLanguageTag("th-TH-u-nu-" + NumberSystem.THAI.getCode()) would set the Thai-number-system where the code "thai" is used.

      Returns:
      unicode extension identifier (in most cases defined like in CLDR)
      Since:
      4.24