Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public Class PluralFormat

extends UFormat
Class Inheritance
Imports
java.io.IOException, .ObjectInputStream, java.text.FieldPosition, .ParsePosition, java.util.Locale, .Map, .Objects, com.ibm.icu.number.FormattedNumber, .LocalizedNumberFormatter, com.ibm.icu.text.PluralRules.FixedDecimal, .PluralRules.IFixedDecimal, .PluralRules.PluralType, com.ibm.icu.util.ULocale, .ULocale.Category

PluralFormat supports the creation of internationalized messages with plural inflection. It is based on plural selection, i.e. the caller specifies messages for each plural case that can appear in the user's language and the PluralFormat selects the appropriate message based on the number.

The Problem of Plural Forms in Internationalized Messages

Different languages have different ways to inflect plurals. Creating internationalized messages that include plural forms is only feasible when the framework is able to handle plural forms of all languages correctly. ChoiceFormat doesn't handle this well, because it attaches a number interval to each message and selects the message whose interval contains a given number. This can only handle a finite number of intervals. But in some languages, like Polish, one plural case applies to infinitely many intervals (e.g., the paucal case applies to numbers ending with 2, 3, or 4 except those ending with 12, 13, or 14). Thus ChoiceFormat is not adequate.

PluralFormat deals with this by breaking the problem into two parts:

Usage of PluralFormat

Note

Typically, plural formatting is done via MessageFormat with a plural argument type, rather than using a stand-alone PluralFormat.

This discussion assumes that you use PluralFormat with a predefined set of plural rules. You can create one using one of the constructors that takes a ULocale object. To specify the message pattern, you can either pass it to the constructor or set it explicitly using the applyPattern() method. The format() method takes a number object and selects the message of the matching plural case. This message will be returned.

Patterns and Their Interpretation

The pattern text defines the message output for each plural case of the specified locale. Syntax:

pluralStyle = [offsetValue] (selector '{' message '}')+
offsetValue = "offset:" number
selector = explicitValue | keyword
explicitValue = '=' number  // adjacent, no white space in between
keyword = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
message: see MessageFormat
Pattern_White_Space between syntax elements is ignored, except between the {curly braces} and their sub-message, and between the '=' and the number of an explicitValue.

There are 6 predefined case keywords in CLDR/ICU - 'zero', 'one', 'two', 'few', 'many' and 'other'. You always have to define a message text for the default plural case "other" which is contained in every rule set. If you do not specify a message text for a particular plural case, the message text of the plural case "other" gets assigned to this plural case.

When formatting, the input number is first matched against the explicitValue clauses. If there is no exact-number match, then a keyword is selected by calling the PluralRules with the input number minus the offset. (The offset defaults to 0 if it is omitted from the pattern string.) If there is no clause with that keyword, then the "other" clauses is returned.

An unquoted pound sign (#) in the selected sub-message itself (i.e., outside of arguments nested in the sub-message) is replaced by the input number minus the offset. The number-minus-offset value is formatted using a NumberFormat for the PluralFormat's locale. If you need special number formatting, you have to use a MessageFormat and explicitly specify a NumberFormat argument

Note

That argument is formatting without subtracting the offset! If you need a custom format and have a non-zero offset, then you need to pass the number-minus-offset value as a separate parameter.

For a usage example, see the MessageFormat class documentation.

Defining Custom Plural Rules

If you need to use PluralFormat with custom rules, you can create a PluralRules object and pass it to PluralFormat's constructor. If you also specify a locale in this constructor, this locale will be used to format the number in the message texts.

For more information about PluralRules, see PluralRules.

Author
tschumann (Tim Schumann)
ICU Status
Stable since ICU 3.8.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
PluralFormat.PluralSelector

Interface for selecting PluralFormat keywords for numbers.

private class

Field Summary

Modifier and TypeField and Description
private transient MessagePattern
msgPattern

The MessagePattern which contains the parsed structure of the pattern string.

private NumberFormat
numberFormat

This NumberFormat is used for the standard formatting of the number inserted into the message.

private transient double
offset

The offset to subtract before invoking plural rules.

private Map<String, String>
parsedValues

Obsolete with use of MessagePattern since ICU 4.8.

private String
pattern

The applied pattern string.

private PluralRules
pluralRules

The plural rules used for plural selection.

private transient PluralFormat.PluralSelectorAdapter
private static final long
private ULocale
ulocale

The locale used for standard number formatting and getting the predefined plural rules (if they were not defined explicitely).

Constructor Summary

AccessConstructor and Description
public
PluralFormat()

Creates a new cardinal-number PluralFormat for the default FORMAT locale.

public
PluralFormat(ULocale
the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.
ulocale
)

Creates a new cardinal-number PluralFormat for a given locale.

public
PluralFormat(Locale
the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.
locale
)

Creates a new cardinal-number PluralFormat for a given java.util.Locale.

public
PluralFormat(PluralRules
defines the behavior of the PluralFormat object.
rules
)

Creates a new cardinal-number PluralFormat for a given set of rules.

public
PluralFormat(ULocale
the default number formatting will be done using this locale.
ulocale
,
PluralRules
defines the behavior of the PluralFormat object.
rules
)

Creates a new cardinal-number PluralFormat for a given set of rules.

public
PluralFormat(Locale
the default number formatting will be done using this locale.
locale
,
PluralRules
defines the behavior of the PluralFormat object.
rules
)

Creates a new cardinal-number PluralFormat for a given set of rules.

public
PluralFormat(ULocale
the default number formatting will be done using this locale.
ulocale
,
PluralRules.PluralType
The plural type (e.g., cardinal or ordinal).
type
)

Creates a new PluralFormat for the plural type.

public
PluralFormat(Locale
the default number formatting will be done using this locale.
locale
,
PluralRules.PluralType
The plural type (e.g., cardinal or ordinal).
type
)

Creates a new PluralFormat for the plural type.

public
PluralFormat(String
the pattern for this PluralFormat.
pattern
)

Creates a new cardinal-number PluralFormat for a given pattern string.

public
PluralFormat(ULocale
the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.
ulocale
,
String
the pattern for this PluralFormat.
pattern
)

Creates a new cardinal-number PluralFormat for a given pattern string and locale.

public
PluralFormat(PluralRules
defines the behavior of the PluralFormat object.
rules
,
String
the pattern for this PluralFormat.
pattern
)

Creates a new cardinal-number PluralFormat for a given set of rules and a pattern.

public
PluralFormat(ULocale
the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.
ulocale
,
PluralRules
defines the behavior of the PluralFormat object.
rules
,
String
the pattern for this PluralFormat.
pattern
)

Creates a new cardinal-number PluralFormat for a given set of rules, a pattern and a locale.

public
PluralFormat(ULocale
the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.
ulocale
,
PluralRules.PluralType
The plural type (e.g., cardinal or ordinal).
type
,
String
the pattern for this PluralFormat.
pattern
)

Creates a new PluralFormat for a plural type, a pattern and a locale.

pack-priv
PluralFormat(ULocale
the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.
ulocale
,
PluralRules.PluralType
The plural type (e.g., cardinal or ordinal).
type
,
String
the pattern for this PluralFormat.
pattern
,
NumberFormat
The number formatter to use.
numberFormat
)

Creates a new PluralFormat for a plural type, a pattern and a locale.

Method Summary

Modifier and TypeMethod and Description
public void
applyPattern(String
the pattern for this plural format.
pattern
)

Sets the pattern used by this plural format.

public boolean
equals(Object
the reference object with which to compare.
rhs
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public boolean

Returns:

true if this equals rhs
equals
(PluralFormat
the PluralFormat to compare against
rhs
)

Returns true if this equals the provided PluralFormat.

pack-priv static int

Returns:

the sub-message start part index.
findSubMessage
(MessagePattern
A MessagePattern.
pattern
,
int
the index of the first PluralFormat argument style part.
partIndex
,
PluralFormat.PluralSelector
the PluralSelector for mapping the number (minus offset) to a keyword.
selector
,
Object
worker object for the selector.
context
,
double
a number to be matched to one of the PluralFormat argument's explicit values, or mapped via the PluralSelector.
number
)

Finds the PluralFormat sub-message for the given number, or the "other" sub-message.

public final String

Returns:

the string containing the formatted plural message.
format
(double
a number for which the plural message should be formatted. If no pattern has been applied to this PluralFormat object yet, the formatted number will be returned.
number
)

Formats a plural message for a given number.

public StringBuffer

Returns:

the string buffer passed in as toAppendTo, with formatted text appended.
format
(Object
a number object (instance of Number for which the plural message should be formatted. If no pattern has been applied to this PluralFormat object yet, the formatted number will be returned.

Note

If this object is not an instance of Number, the toAppendTo will not be modified.

number
,
StringBuffer
the formatted message will be appended to this StringBuffer.
toAppendTo
,
FieldPosition
will be ignored by this method.
pos
)

Implements abstract java.text.Format.format.

Formats a plural message for a given number and appends the formatted message to the given StringBuffer.
private String
format(Number numberObject, double number)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
private void
init(PluralRules rules, PluralRules.PluralType type, ULocale locale, NumberFormat numberFormat)

public Number

Returns:

nothing because this method is not yet implemented.
parse
(String
the string to be parsed.
text
,
ParsePosition
defines the position where parsing is to begin, and upon return, the position where parsing left off. If the position has not changed upon return, then parsing failed.
parsePosition
)

This method is not yet supported by PluralFormat.

public Object

Returns:

nothing because this method is not yet implemented.
parseObject
(String
the string to be parsed.
source
,
ParsePosition
defines the position where parsing is to begin, and upon return, the position where parsing left off. If the position has not changed upon return, then parsing failed.
pos
)

Implements abstract java.text.Format.parseObject.

This method is not yet supported by PluralFormat.
pack-priv String

Returns:

Returns the PluralRules type. For example, it could be "zero", "one", "two", "few", "many" or "other")
parseType
(String
the string to be parsed.
source
,
RbnfLenientScanner scanner, FieldPosition
defines the position where parsing is to begin, and upon return, the position where parsing left off. If the position is a negative index, then parsing failed.
pos
)

Deprecated as a consequence of RbnfLenientScanner being deprecated.
This method returns the PluralRules type found from parsing.
private void
private void
public void
setLocale(ULocale
the ULocale used to configure the formatter. If ulocale is null, the default FORMAT locale will be used.
ulocale
)

Deprecated ICU 50 This method clears the pattern and might create a different kind of PluralRules instance; use one of the constructors to create a new instance instead.
Sets the locale used by this PluraFormat object.
public void
setNumberFormat(NumberFormat
the number format to use.
format
)

Sets the number format used by this formatter.

public String

Returns:

the pattern string
toPattern
()

Returns the pattern for this PluralFormat.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.ibm.icu.text.UFormat:
getLocalesetLocale

Field Detail

msgPatternback to summary
private transient MessagePattern msgPattern

The MessagePattern which contains the parsed structure of the pattern string.

numberFormatback to summary
private NumberFormat numberFormat

This NumberFormat is used for the standard formatting of the number inserted into the message.

offsetback to summary
private transient double offset

The offset to subtract before invoking plural rules.

parsedValuesback to summary
private Map<String, String> parsedValues

Obsolete with use of MessagePattern since ICU 4.8. Used to be: The format messages for each plural case. It is a mapping: String(plural case keyword) --> String (message for this plural case).

patternback to summary
private String pattern

The applied pattern string.

pluralRulesback to summary
private PluralRules pluralRules

The plural rules used for plural selection.

pluralRulesWrapperback to summary
private transient PluralFormat.PluralSelectorAdapter pluralRulesWrapper
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.ibm.icu.text.UFormat.serialVersionUID.

ulocaleback to summary
private ULocale ulocale

The locale used for standard number formatting and getting the predefined plural rules (if they were not defined explicitely).

Constructor Detail

PluralFormatback to summary
public PluralFormat()

Creates a new cardinal-number PluralFormat for the default FORMAT locale. This locale will be used to get the set of plural rules and for standard number formatting.

ICU Status
Stable since ICU 3.8.
See Also
Category#FORMAT
PluralFormatback to summary
public PluralFormat(ULocale ulocale)

Creates a new cardinal-number PluralFormat for a given locale.

Parameters
ulocale:ULocale

the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.

ICU Status
Stable since ICU 3.8.
PluralFormatback to summary
public PluralFormat(Locale locale)

Creates a new cardinal-number PluralFormat for a given java.util.Locale.

Parameters
locale:Locale

the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.

ICU Status
Stable since ICU 54.
PluralFormatback to summary
public PluralFormat(PluralRules rules)

Creates a new cardinal-number PluralFormat for a given set of rules. The standard number formatting will be done using the default FORMAT locale.

Parameters
rules:PluralRules

defines the behavior of the PluralFormat object.

ICU Status
Stable since ICU 3.8.
See Also
Category#FORMAT
PluralFormatback to summary
public PluralFormat(ULocale ulocale, PluralRules rules)

Creates a new cardinal-number PluralFormat for a given set of rules. The standard number formatting will be done using the given locale.

Parameters
ulocale:ULocale

the default number formatting will be done using this locale.

rules:PluralRules

defines the behavior of the PluralFormat object.

ICU Status
Stable since ICU 3.8.
PluralFormatback to summary
public PluralFormat(Locale locale, PluralRules rules)

Creates a new cardinal-number PluralFormat for a given set of rules. The standard number formatting will be done using the given locale.

Parameters
locale:Locale

the default number formatting will be done using this locale.

rules:PluralRules

defines the behavior of the PluralFormat object.

ICU Status
Stable since ICU 54.
PluralFormatback to summary
public PluralFormat(ULocale ulocale, PluralRules.PluralType type)

Creates a new PluralFormat for the plural type. The standard number formatting will be done using the given locale.

Parameters
ulocale:ULocale

the default number formatting will be done using this locale.

type:PluralRules.PluralType

The plural type (e.g., cardinal or ordinal).

ICU Status
Stable since ICU 50.
PluralFormatback to summary
public PluralFormat(Locale locale, PluralRules.PluralType type)

Creates a new PluralFormat for the plural type. The standard number formatting will be done using the given java.util.Locale.

Parameters
locale:Locale

the default number formatting will be done using this locale.

type:PluralRules.PluralType

The plural type (e.g., cardinal or ordinal).

ICU Status
Stable since ICU 54.
PluralFormatback to summary
public PluralFormat(String pattern)

Creates a new cardinal-number PluralFormat for a given pattern string. The default FORMAT locale will be used to get the set of plural rules and for standard number formatting.

Parameters
pattern:String

the pattern for this PluralFormat.

Exceptions
IllegalArgumentException:
if the pattern is invalid.
ICU Status
Stable since ICU 3.8.
See Also
Category#FORMAT
PluralFormatback to summary
public PluralFormat(ULocale ulocale, String pattern)

Creates a new cardinal-number PluralFormat for a given pattern string and locale. The locale will be used to get the set of plural rules and for standard number formatting.

Example code:{@. jcite com.ibm.icu.samples.text.pluralformat.PluralFormatSample:---PluralFormatExample}

Parameters
ulocale:ULocale

the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.

pattern:String

the pattern for this PluralFormat.

Exceptions
IllegalArgumentException:
if the pattern is invalid.
ICU Status
Stable since ICU 3.8.
PluralFormatback to summary
public PluralFormat(PluralRules rules, String pattern)

Creates a new cardinal-number PluralFormat for a given set of rules and a pattern. The standard number formatting will be done using the default FORMAT locale.

Parameters
rules:PluralRules

defines the behavior of the PluralFormat object.

pattern:String

the pattern for this PluralFormat.

Exceptions
IllegalArgumentException:
if the pattern is invalid.
ICU Status
Stable since ICU 3.8.
See Also
Category#FORMAT
PluralFormatback to summary
public PluralFormat(ULocale ulocale, PluralRules rules, String pattern)

Creates a new cardinal-number PluralFormat for a given set of rules, a pattern and a locale.

Parameters
ulocale:ULocale

the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.

rules:PluralRules

defines the behavior of the PluralFormat object.

pattern:String

the pattern for this PluralFormat.

Exceptions
IllegalArgumentException:
if the pattern is invalid.
ICU Status
Stable since ICU 3.8.
PluralFormatback to summary
public PluralFormat(ULocale ulocale, PluralRules.PluralType type, String pattern)

Creates a new PluralFormat for a plural type, a pattern and a locale.

Parameters
ulocale:ULocale

the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.

type:PluralRules.PluralType

The plural type (e.g., cardinal or ordinal).

pattern:String

the pattern for this PluralFormat.

Exceptions
IllegalArgumentException:
if the pattern is invalid.
ICU Status
Stable since ICU 50.
PluralFormatback to summary
pack-priv PluralFormat(ULocale ulocale, PluralRules.PluralType type, String pattern, NumberFormat numberFormat)

Creates a new PluralFormat for a plural type, a pattern and a locale.

Parameters
ulocale:ULocale

the PluralFormat will be configured with rules for this locale. This locale will also be used for standard number formatting.

type:PluralRules.PluralType

The plural type (e.g., cardinal or ordinal).

pattern:String

the pattern for this PluralFormat.

numberFormat:NumberFormat

The number formatter to use.

Exceptions
IllegalArgumentException:
if the pattern is invalid.

Method Detail

applyPatternback to summary
public void applyPattern(String pattern)

Sets the pattern used by this plural format. The method parses the pattern and creates a map of format strings for the plural rules. Patterns and their interpretation are specified in the class description.

Parameters
pattern:String

the pattern for this plural format.

Exceptions
IllegalArgumentException:
if the pattern is invalid.
ICU Status
Stable since ICU 3.8.
equalsback to summary
public boolean equals(Object rhs)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
rhs:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
ICU Status
Stable since ICU 3.8.
equalsback to summary
public boolean equals(PluralFormat rhs)

Returns true if this equals the provided PluralFormat.

Parameters
rhs:PluralFormat

the PluralFormat to compare against

Returns:boolean

true if this equals rhs

ICU Status
Stable since ICU 3.8.
findSubMessageback to summary
pack-priv static int findSubMessage(MessagePattern pattern, int partIndex, PluralFormat.PluralSelector selector, Object context, double number)

Finds the PluralFormat sub-message for the given number, or the "other" sub-message.

Parameters
pattern:MessagePattern

A MessagePattern.

partIndex:int

the index of the first PluralFormat argument style part.

selector:PluralFormat.PluralSelector

the PluralSelector for mapping the number (minus offset) to a keyword.

context:Object

worker object for the selector.

number:double

a number to be matched to one of the PluralFormat argument's explicit values, or mapped via the PluralSelector.

Returns:int

the sub-message start part index.

formatback to summary
public final String format(double number)

Formats a plural message for a given number.

Parameters
number:double

a number for which the plural message should be formatted. If no pattern has been applied to this PluralFormat object yet, the formatted number will be returned.

Returns:String

the string containing the formatted plural message.

ICU Status
Stable since ICU 4.0.
formatback to summary
public StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos)

Implements abstract java.text.Format.format.

Formats a plural message for a given number and appends the formatted message to the given StringBuffer.

Parameters
number:Object

a number object (instance of Number for which the plural message should be formatted. If no pattern has been applied to this PluralFormat object yet, the formatted number will be returned.

Note

If this object is not an instance of Number, the toAppendTo will not be modified.

toAppendTo:StringBuffer

the formatted message will be appended to this StringBuffer.

pos:FieldPosition

will be ignored by this method.

Returns:StringBuffer

the string buffer passed in as toAppendTo, with formatted text appended.

Annotations
@Override
Exceptions
IllegalArgumentException:
if number is not an instance of Number
ICU Status
Stable since ICU 3.8.
formatback to summary
private String format(Number numberObject, double number)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
ICU Status
Stable since ICU 3.8.
initback to summary
private void init(PluralRules rules, PluralRules.PluralType type, ULocale locale, NumberFormat numberFormat)
parseback to summary
public Number parse(String text, ParsePosition parsePosition)

This method is not yet supported by PluralFormat.

Parameters
text:String

the string to be parsed.

parsePosition:ParsePosition

defines the position where parsing is to begin, and upon return, the position where parsing left off. If the position has not changed upon return, then parsing failed.

Returns:Number

nothing because this method is not yet implemented.

Exceptions
UnsupportedOperationException:
will always be thrown by this method.
ICU Status
Stable since ICU 3.8.
parseObjectback to summary
public Object parseObject(String source, ParsePosition pos)

Implements abstract java.text.Format.parseObject.

This method is not yet supported by PluralFormat.

Parameters
source:String

the string to be parsed.

pos:ParsePosition

defines the position where parsing is to begin, and upon return, the position where parsing left off. If the position has not changed upon return, then parsing failed.

Returns:Object

nothing because this method is not yet implemented.

Annotations
@Override
Exceptions
UnsupportedOperationException:
will always be thrown by this method.
ICU Status
Stable since ICU 3.8.
parseTypeback to summary
pack-priv String parseType(String source, RbnfLenientScanner scanner, FieldPosition pos)

Deprecated

as a consequence of RbnfLenientScanner being deprecated. See corresponding docs for further information.

This method returns the PluralRules type found from parsing.

Parameters
source:String

the string to be parsed.

pos:FieldPosition

defines the position where parsing is to begin, and upon return, the position where parsing left off. If the position is a negative index, then parsing failed.

Returns:String

Returns the PluralRules type. For example, it could be "zero", "one", "two", "few", "many" or "other")

readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
resetPatternback to summary
private void resetPattern()
setLocaleback to summary
public void setLocale(ULocale ulocale)

Deprecated

ICU 50 This method clears the pattern and might create a different kind of PluralRules instance; use one of the constructors to create a new instance instead.

Sets the locale used by this PluraFormat object.

Note

Calling this method resets this PluraFormat object, i.e., a pattern that was applied previously will be removed, and the NumberFormat is set to the default number format for the locale. The resulting format behaves the same as one constructed from PluralFormat(ULocale, PluralRules.PluralType) with PluralType.CARDINAL.

Parameters
ulocale:ULocale

the ULocale used to configure the formatter. If ulocale is null, the default FORMAT locale will be used.

Annotations
@Deprecated
See Also
Category#FORMAT
setNumberFormatback to summary
public void setNumberFormat(NumberFormat format)

Sets the number format used by this formatter. You only need to call this if you want a different number format than the default formatter for the locale.

Parameters
format:NumberFormat

the number format to use.

ICU Status
Stable since ICU 3.8.
toPatternback to summary
public String toPattern()

Returns the pattern for this PluralFormat.

Returns:String

the pattern string

ICU Status
Stable since ICU 4.2.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
ICU Status
Stable since ICU 3.8.
com.ibm.icu.text back to summary

pack-priv Interface PluralFormat.PluralSelector

Known Direct Implementers
com.ibm.icu.text.PluralFormat.PluralSelectorAdapter, com.ibm.icu.text.MessageFormat.PluralSelectorProvider

Interface for selecting PluralFormat keywords for numbers. The PluralRules class was intended to implement this interface, but there is no public API that uses a PluralSelector, only MessageFormat and PluralFormat have PluralSelector implementations. Therefore, PluralRules is not marked to implement this non-public interface, to avoid confusing users.
ICU Status
Internal ICU component.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The selected PluralFormat keyword.
select
(Object
worker object for the selector.
context
,
double
The number to be plural-formatted.
number
)

Given a number, returns the appropriate PluralFormat keyword.

Method Detail

selectback to summary
public String select(Object context, double number)

Given a number, returns the appropriate PluralFormat keyword.

Parameters
context:Object

worker object for the selector.

number:double

The number to be plural-formatted.

Returns:String

The selected PluralFormat keyword.

com.ibm.icu.text back to summary

private final Class PluralFormat.PluralSelectorAdapter

extends Object
implements PluralSelector
Class Inheritance
All Implemented Interfaces
com.ibm.icu.text.PluralFormat.PluralSelector

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
select(Object
worker object for the selector.
context
,
double
The number to be plural-formatted.
number
)

Implements com.ibm.icu.text.PluralFormat.PluralSelector.select.

Given a number, returns the appropriate PluralFormat keyword.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PluralSelectorAdapterback to summary
private PluralSelectorAdapter()

Method Detail

selectback to summary
public String select(Object context, double number)

Implements com.ibm.icu.text.PluralFormat.PluralSelector.select.

Doc from com.ibm.icu.text.PluralFormat.PluralSelector.select.

Given a number, returns the appropriate PluralFormat keyword.

Parameters
context:Object

worker object for the selector.

number:double

The number to be plural-formatted.

Returns:String

The selected PluralFormat keyword.

Annotations
@Override