Enum Class NumberSystem
- All Implemented Interfaces:
Serializable
,Comparable<NumberSystem>
,java.lang.constant.Constable
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 ConstantDescriptionArabic 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.LikeCHINESE_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 TypeMethodDescriptionboolean
contains(char digit)
Does this number system contains given digit char?getCode()
Obtains an identifier which can be used together with the unicode extension "nu" inLocale
-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
Converts given text numeral to an integer in smart mode.int
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.static NumberSystem
Returns the enum constant of this class with the specified name.static NumberSystem[]
values()
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
-
Enum Constant Details
-
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
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
Extended Arabic-Indic numbers (used for example in Iran).Note: Must not be negative.
Code
: "arabext".- Since:
- 3.23/4.19
-
BENGALI
The Bengali digits used in parts of India.Note: Must not be negative.
Code
: "beng".- Since:
- 3.23/4.19
-
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 ofNumberSystem.CHINESE_DECIMAL.toInteger("二零零九")
will be2009
, 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 resultfalse
, 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
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
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.
- Since:
- 5.9
- See Also:
CHINESE_DECIMAL
,CHINESE_SIMPLIFIED
-
CHINESE_SIMPLIFIED
LikeCHINESE_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
The Devanagari digits used in parts of India.Note: Must not be negative.
Code
: "deva".- Since:
- 3.23/4.19
-
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
Ethiopic numerals (always positive).See also A Look at Ethiopic Numerals. Attention: This enum is not a decimal system.
Code
: "ethiopic". -
GUJARATI
The Gujarati digits used in parts of India.Note: Must not be negative.
Code
: "gujr".- Since:
- 3.23/4.19
-
GURMUKHI
The Gurmukhi digits used mainly by Sikhs in parts of India.Note: Must not be negative.
Code
: "guru".- Since:
- 5.9
-
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
Traditional number system used by Khmer people in Cambodia.Note: Must not be negative.
Code
: "khmr".- Since:
- 3.23/4.19
-
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
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
령
and공
for zero or륙
for the digit six are accepted in parsing, too, ifleniency
is not strict. Thecode
is: "koreansino" (no CLDR-equivalent).- Since:
- 5.9
- See Also:
KOREAN_NATIVE
-
LAO
Traditional number system used in Laos.Note: Must not be negative.
Code
: "laoo".- Since:
- 5.9
-
MYANMAR
The number system used in Myanmar (Burma).Note: Must not be negative.
Code
: "mymr".- Since:
- 3.23/4.19
-
ORYA
The Orya digits used in parts of India.Note: Must not be negative.
Code
: "orya".- Since:
- 3.37/4.32
-
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
The Telugu digits used in parts of India.Note: Must not be negative.
Code
: "telu".- Since:
- 3.23/4.19
-
THAI
The Thai digits used in Thailand (Siam).Note: Must not be negative.
Code
: "thai".- Since:
- 3.23/4.19
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-
toNumeral
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
Converts given integer to a text numeral which will then be written into buffer.
- Parameters:
number
- number to be displayed as textbuffer
- 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 numberIOException
- if writing to the buffer fails- Since:
- 3.27/4.22
-
toInteger
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 formatArithmeticException
- if int-range overflows- Since:
- 3.11/4.8
-
toInteger
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 numberleniency
- determines how lenient the parsing of given numeral should be- Returns:
- integer
- Throws:
IllegalArgumentException
- if given number has wrong formatArithmeticException
- 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
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
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
-