Plural Rule
Wrapper class for PluralRules, designed for ease-of-use and safety.
A PluralRule is created by using a create() method. Create methods will return empty Optionals if a no plural rule is found for a given language. Optional method chaining can be used to return a default rule, or createOrDefault() can be used (less error-prone).
For example:
PluralRule rule = PluralRule.createOrDefault(Locale.ENGLISH, PluralRuleType.ORDINAL);
assert (rule.select(1) == PluralCategory.ONE); // e.g., "1 day"
assert (rule.select(10) == PluralCategory.OTHER); // e.g., "10 days"
assert (rule.select("1100.00") == PluralCategory.OTHER); // e.g., "1100.00 days"
<p>
PluralRule rule = PluralRule.createOrDefault(Locale.ENGLISH, PluralRuleType.CARDINAL);
assert (rule.select(1) == PluralCategory.ONE); // e.g, "1st" use 'st' suffix
assert (rule.select(2) == PluralCategory.TWO); // e.g., "2nd" use 'nd' suffix
assert (rule.select(3) == PluralCategory.FEW); // e.g., "3rd" use 'rd' suffix
assert (rule.select(4) == PluralCategory.OTHER); // e.g., "4th" use 'th' suffix
assert (rule.select(43) == PluralCategory.FEW); // e.g., "43rd"
assert (rule.select(50) == PluralCategory.OTHER); // e.g., "50th"The PluralCategory returned determines how subsequent localization logic then handles the number, ranking, or quantity, which is locale-dependent.
When matching a language, the empty String "" and String "root" are equivalent to Locale.ROOT. The Locale.ROOT rule can be used if there is no match for a language. This is particularly important when using cardinal rules; many languages do not have specific cardinal rules.
Properties
Functions
Returns the PluralRuleType corresponding to this PluralRule. Never null.
Returns the rule as a Function. Never null.
Determine the PluralCategory for the given PluralOperand.
Determine the PluralCategory for the given double value.
Determine the PluralCategory for the given long value.
Determine the PluralCategory for the given Number.
Determine the PluralCategory for the given numeric String.
Determine the PluralCategory for the given "compact" double
Determine the PluralCategory for the given "compact" long