Enum Class Ordinality
- All Implemented Interfaces:
LanguageForm
,Serializable
,Comparable<Ordinality>
,Constable
For example, English has four: 1st, 2nd, 3rd, 4th
, while Swedish has two: 1:a, 3:e
.
See the Unicode Common Locale Data Repository and its Language Plural Rules for details.
Per the CLDR:
These categories are only mnemonics -- the names don't necessarily imply the exact contents of the category. For example, for both English and French the number 1 has the category one (singular).In English, every other number has a plural form, and is given the category other. French is similar, except that the number 0 also has the category one and not other or zero, because the form of units qualified by 0 is also singular.
This is worth emphasizing: A common mistake is to think that "one" is only for only the number 1. Instead, "one" is a category for any number that behaves like 1. So in some languages, for example, one → numbers that end in "1" (like 1, 21, 151) but that don't end in 11 (like "11, 111, 10311).
- Author:
- Mark Allen
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionThe form that falls betweenTWO
andMANY
.The form that falls betweenFEW
andOTHER
.The form used with 1.General "catchall" form which comprises any cases not handled by the other forms.Normally the form used with 2, if it is limited to numbers whose integer values end with 2.Normally the form used with 0, if it is limited to numbers whose integer values end with 0. -
Method Summary
Modifier and TypeMethodDescriptionstatic SortedMap<Ordinality,
Range<Integer>> exampleIntegerValuesForLocale
(Locale locale) Gets a mapping of ordinalities to example integer values for the given locale.static Ordinality
Gets an appropriate plural ordinality for the given number and locale.Gets the ISO 639 language codes for which ordinality operations are supported.static SortedSet<Ordinality>
supportedOrdinalitiesForLocale
(Locale locale) Gets the set of ordinalities supported for the given locale.static Ordinality
Returns the enum constant of this class with the specified name.static Ordinality[]
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
-
ZERO
Normally the form used with 0, if it is limited to numbers whose integer values end with 0.For example: the Welsh
0fed ci
means "0th dog
" in English. -
ONE
The form used with 1.For example: the Welsh
ci 1af
means1st dog
in English. -
TWO
Normally the form used with 2, if it is limited to numbers whose integer values end with 2.For example: the Welsh
2il gi
means2nd dog
in English. -
FEW
The form that falls betweenTWO
andMANY
.For example: the Welsh
3ydd ci
means3rd dog
in English. -
MANY
The form that falls betweenFEW
andOTHER
.For example: the Welsh
5ed ci
means5th dog
in English. -
OTHER
General "catchall" form which comprises any cases not handled by the other forms.For example: the Welsh
ci rhif 10
means10th dog
in English.
-
-
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
-
forNumber
Gets an appropriate plural ordinality for the given number and locale.See http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html for a cheat sheet.
- Parameters:
number
- the number that drives pluralization, not nulllocale
- the locale that drives pluralization, not null- Returns:
- an appropriate plural ordinality, not null
- Throws:
UnsupportedLocaleException
- if the locale is not supported
-
supportedOrdinalitiesForLocale
Gets the set of ordinalities supported for the given locale.The empty set will be returned if the locale is not supported.
The set's values are sorted by the natural ordering of the
Ordinality
enumeration.- Parameters:
locale
- the locale to use for lookup, not null- Returns:
- the ordinalities supported by the given locale, not null
-
exampleIntegerValuesForLocale
@Nonnull public static SortedMap<Ordinality,Range<Integer>> exampleIntegerValuesForLocale(@Nonnull Locale locale) Gets a mapping of ordinalities to example integer values for the given locale.The empty map will be returned if the locale is not supported or if no example values are available.
The map's keys are sorted by the natural ordering of the
Ordinality
enumeration.- Parameters:
locale
- the locale to use for lookup, not null- Returns:
- a mapping of ordinalities to example integer values, not null
-
getSupportedLanguageCodes
Gets the ISO 639 language codes for which ordinality operations are supported.The set's values are ISO 639 codes and therefore sorted using English collation.
- Returns:
- the ISO 639 language codes for which ordinality operations are supported, not null
-