Class PluralRules

java.lang.Object
net.time4j.format.PluralRules

public abstract class PluralRules extends Object

Helps to determine the plural category for a given number of units.

The predefined rules for any given language are based on CLDR-version 26 but can be overridden if necessary. The source data of the underlying algorithms to determine the plural category can be found in CLDR-repository-file "core.zip" along the path "common/supplemental/plurals.xml" for cardinal numbers and "common/supplemental/ordinals.xml" for ordinal numbers.

Note: All concrete subclasses must be immutable.

Since:
1.2
Author:
Meno Hochschild
  • Constructor Details

    • PluralRules

      public PluralRules()
  • Method Details

    • of

      public static PluralRules of(Locale locale, NumberType numType)

      Gets the localized plural rules for given language or country.

      If no rules can be found then Time4J will choose the default rules for cardinals which apply PluralCategory.ONE to n=1 and else apply the fallback category PluralCategory.OTHER.

      Parameters:
      locale - locale which specifies the suitable plural rules
      numType - number type
      Returns:
      localized plural rules
      Since:
      1.2
    • register

      public static void register(Locale locale, PluralRules rules)

      Registers given plural rules for a language, possibly overriding CLDR-default setting.

      Parameters:
      locale - language or country which the rules shall be assigned to
      rules - localized plural rules
      Since:
      1.2
    • getCategory

      public abstract PluralCategory getCategory(long count)

      Determines the plural category for given number of units.

      Parameters:
      count - integral number of units
      Returns:
      plural category, never null
      Since:
      1.2
    • getNumberType

      public abstract NumberType getNumberType()

      Yields the number type these rules are referring to.

      Returns:
      number type
      Since:
      1.2