Package com.lokalized

Enum Class Ordinality

java.lang.Object
java.lang.Enum<Ordinality>
com.lokalized.Ordinality
All Implemented Interfaces:
LanguageForm, Serializable, Comparable<Ordinality>, Constable

public enum Ordinality extends Enum<Ordinality> implements LanguageForm
Language plural ordinality forms.

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
  • Enum Constant Details

    • ZERO

      public static final Ordinality 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

      public static final Ordinality ONE
      The form used with 1.

      For example: the Welsh ci 1af means 1st dog in English.

    • TWO

      public static final Ordinality 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 means 2nd dog in English.

    • FEW

      public static final Ordinality FEW
      The form that falls between TWO and MANY.

      For example: the Welsh 3ydd ci means 3rd dog in English.

    • MANY

      public static final Ordinality MANY
      The form that falls between FEW and OTHER.

      For example: the Welsh 5ed ci means 5th dog in English.

    • OTHER

      public static final Ordinality OTHER
      General "catchall" form which comprises any cases not handled by the other forms.

      For example: the Welsh ci rhif 10 means 10th dog in English.

  • Method Details

    • values

      public static Ordinality[] 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 Ordinality 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
    • forNumber

      @Nonnull public static Ordinality forNumber(@Nonnull Number number, @Nonnull Locale locale)
      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 null
      locale - the locale that drives pluralization, not null
      Returns:
      an appropriate plural ordinality, not null
      Throws:
      UnsupportedLocaleException - if the locale is not supported
    • supportedOrdinalitiesForLocale

      @Nonnull public static SortedSet<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 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

      @Nonnull public static SortedSet<String> 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