Enum 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.
CLDR category names are mnemonics whose membership is locale-specific; they do not imply cardinal singular or plural
meaning. For English ordinals, values ending in 1, 2, or 3 normally select ONE, TWO, or
FEW, except for values ending in 11, 12, or 13; remaining values select OTHER. French ordinals use
ONE for 1 and OTHER for other values. Applications should always use the generated locale rules
rather than inferring ordinal categories from their names.
- Author:
- Mark Allen
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe form that falls betweenTWOandMANY.The form that falls betweenFEWandOTHER.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 TypeMethodDescriptionGets a mapping of ordinalities to example integer values for the given locale.static @NonNull OrdinalityGets an appropriate plural ordinality for the given number and locale.static @NonNull OrdinalityforOperands(@NonNull PluralOperands operands, @NonNull Locale locale) Gets an appropriate plural ordinality for the given CLDR plural operands and locale.Gets the BCP 47 locale tags represented directly in the generated CLDR plural-rule data and supported for ordinality operations.static @NonNull SortedSet<@NonNull Ordinality> Gets the set of ordinalities supported for the given locale.static OrdinalityReturns the enum constant of this type with the specified name.static Ordinality[]values()Returns an array containing the constants of this enum type, in the order they are declared.Methods inherited from class 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 cimeans "0th dog" in English. -
ONE
The form used with 1.For example: the Welsh
ci 1afmeans1st dogin 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 gimeans2nd dogin English. -
FEW
The form that falls betweenTWOandMANY.For example: the Welsh
3ydd cimeans3rd dogin English. -
MANY
The form that falls betweenFEWandOTHER.For example: the Welsh
5ed cimeans5th dogin English. -
OTHER
General "catchall" form which comprises any cases not handled by the other forms.For example: the Welsh
ci rhif 10means10th dogin English.
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
forNumber
Gets an appropriate plural ordinality for the given number and locale.Negative numbers are evaluated using their absolute value. Supported
Numberimplementations and their conversion semantics are documented byPluralOperands.forNumber(Number). This convenience method usesTranslationRuntimeLimits.defaults(). To apply different limits, constructPluralOperandswithPluralOperands.Builder.runtimeLimits(TranslationRuntimeLimits)and callforOperands(PluralOperands, Locale).See CLDR 48 Language Plural Rules 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 supportedIllegalArgumentException- if the locale is malformed, the number implementation is unsupported, the number is non-finite, or the number exceeds the safety limits documented byPluralOperands
-
forOperands
public static @NonNull Ordinality forOperands(@NonNull PluralOperands operands, @NonNull Locale locale) Gets an appropriate plural ordinality for the given CLDR plural operands and locale.Most applications should use
forNumber(Number, Locale). Use this overload when the displayed number has details that are not fully represented by the JavaNumber, such as a compact-decimal exponent.See CLDR 48 Language Plural Rules for a cheat sheet.
- Parameters:
operands- the CLDR plural operands that drive pluralization, not nulllocale- the locale that drives pluralization, not null- Returns:
- an appropriate plural ordinality, not null
- Throws:
UnsupportedLocaleException- if the locale is not supportedIllegalArgumentException- if the locale is malformed- Since:
- 3.0.0
-
supportedOrdinalitiesForLocale
public static @NonNull SortedSet<@NonNull Ordinality> supportedOrdinalitiesForLocale(@NonNull Locale locale) 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
Ordinalityenumeration.- Parameters:
locale- the locale to use for lookup, not null- Returns:
- the ordinalities supported by the given locale, not null
- Throws:
IllegalArgumentException- if the locale is malformed
-
exampleIntegerValuesForLocale
public static @NonNull SortedMap<@NonNull Ordinality, @NonNull Range<@NonNull 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
Ordinalityenumeration.- Parameters:
locale- the locale to use for lookup, not null- Returns:
- a mapping of ordinalities to example integer values, not null
- Throws:
IllegalArgumentException- if the locale is malformed
-
getSupportedLocaleTags
Gets the BCP 47 locale tags represented directly in the generated CLDR plural-rule data and supported for ordinality operations.This is not an exhaustive list of concrete locale tags accepted by ordinality operations. A locale with additional region or script subtags may be supported through fallback to a less-specific rule tag. Use
supportedOrdinalitiesForLocale(Locale)to check a concrete locale.The set's values are sorted by natural string ordering.
- Returns:
- the directly represented BCP 47 locale tags supported for ordinality operations, not null
- Since:
- 3.0.0
-