PluralRules Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
[Android.Runtime.Register("android/icu/text/PluralRules", ApiSince=24, DoNotGenerateAcw=true)]
public class PluralRules : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable
[<Android.Runtime.Register("android/icu/text/PluralRules", ApiSince=24, DoNotGenerateAcw=true)>]
type PluralRules = class
inherit Object
interface ISerializable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
- Inheritance
- Attributes
- Implements
Remarks
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Rules are constructed from a text description, consisting of a series of keywords and conditions. The #select
method examines each condition in order and returns the keyword for the first condition that matches the number. If none match, #KEYWORD_OTHER
is returned.
A PluralRules object is immutable. It contains caches for sample values, but those are synchronized.
PluralRules is Serializable so that it can be used in formatters, which are serializable.
For more information, details, and tips for writing rules, see the LDML spec, Part 3.5 Language Plural Rules
Examples:
"one: n is 1; few: n in 2..4"
This defines two rules, for 'one' and 'few'. The condition for 'one' is "n is 1" which means that the number must be equal to 1 for this condition to pass. The condition for 'few' is "n in 2..4" which means that the number must be between 2 and 4 inclusive - and be an integer - for this condition to pass. All other numbers are assigned the keyword "other" by the default rule.
"zero: n is 0; one: n is 1; zero: n mod 100 in 1..19"
This illustrates that the same keyword can be defined multiple times. Each rule is examined in order, and the first keyword whose condition passes is the one returned. Also notes that a modulus is applied to n in the last rule. Thus its condition holds for 119, 219, 319...
"one: n is 1; few: n mod 10 in 2..4 and n mod 100 not in 12..14"
This illustrates conjunction and negation. The condition for 'few' has two parts, both of which must be met: "n mod 10 in 2..4" and "n mod 100 not in 12..14". The first part applies a modulus to n before the test as in the previous example. The second part applies a different modulus and also uses negation, thus it matches all numbers not in 12, 13, 14, 112, 113, 114, 212, 213, 214...
Syntax:
rules = rule (';' rule)*
rule = keyword ':' condition
keyword = <identifier>
condition = and_condition ('or' and_condition)*
and_condition = relation ('and' relation)*
relation = not? expr not? rel not? range_list
expr = ('n' | 'i' | 'f' | 'v' | 't') (mod value)?
not = 'not' | '!'
rel = 'in' | 'is' | '=' | '≠' | 'within'
mod = 'mod' | '%'
range_list = (range | value) (',' range_list)*
value = digit+
digit = 0|1|2|3|4|5|6|7|8|9
range = value'..'value
Each <b>not</b> term inverts the meaning; however, there should not be more than one of them.
The i, f, t, and v values are defined as follows:
<ul> <li>i to be the integer digits.</li> <li>f to be the visible decimal digits, as an integer.</li> <li>t to be the visible decimal digits—without trailing zeros—as an integer.</li> <li>v to be the number of visible fraction digits.</li> <li>j is defined to only match integers. That is j is 3 fails if v != 0 (eg for 3.1 or 3.0).</li> </ul>
Examples are in the following table:
<table border='1' style="border-collapse:collapse"> <tbody> <tr> <th>n</th> <th>i</th> <th>f</th> <th>v</th> </tr> <tr> <td>1.0</td> <td>1</td> <td align="right">0</td> <td>1</td> </tr> <tr> <td>1.00</td> <td>1</td> <td align="right">0</td> <td>2</td> </tr> <tr> <td>1.3</td> <td>1</td> <td align="right">3</td> <td>1</td> </tr> <tr> <td>1.03</td> <td>1</td> <td align="right">3</td> <td>2</td> </tr> <tr> <td>1.23</td> <td>1</td> <td align="right">23</td> <td>2</td> </tr> </tbody> </table>
An "identifier" is a sequence of characters that do not have the Unicode Pattern_Syntax or Pattern_White_Space properties.
The difference between 'in' and 'within' is that 'in' only includes integers in the specified range, while 'within' includes all values. Using 'within' with a range_list consisting entirely of values is the same as using 'in' (it's not an error).
Java documentation for android.icu.text.PluralRules
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
PluralRules(IntPtr, JniHandleOwnership) |
Fields
KeywordFew |
Common name for the 'paucal' or other special plural form. |
KeywordMany |
Common name for the arabic (11 to 99) plural form. |
KeywordOne |
Common name for the 'singular' plural form. |
KeywordOther |
Common name for the default plural form. |
KeywordTwo |
Common name for the 'dual' plural form. |
KeywordZero |
Common name for the 'zero' plural form. |
NoUniqueValue |
Value returned by |
Properties
Class |
Returns the runtime class of this |
Default |
The default rules that accept any number and return
|
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
Keywords |
Returns a set of all rule keywords used in this |
PeerReference | (Inherited from Object) |
ThresholdClass | |
ThresholdType |
Methods
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
CreateRules(String) |
Creates a PluralRules from a description if it is parsable, otherwise returns null. |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
Equals(PluralRules) |
Returns true if rhs is equal to this. |
ForLocale(Locale, PluralRules+PluralType) | |
ForLocale(Locale) |
Provides access to the predefined cardinal-number |
ForLocale(ULocale, PluralRules+PluralType) | |
ForLocale(ULocale) |
Provides access to the predefined cardinal-number |
GetAllKeywordValues(String) |
Returns all the values that trigger this keyword, or null if the number of such values is unlimited. |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
GetSamples(String) |
Returns a list of integer values for which select() would return that keyword, or null if the keyword is not defined. |
GetUniqueKeywordValue(String) |
Returns the unique value that this keyword matches, or |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
ParseDescription(String) |
Parses a plural rules description and returns a PluralRules. |
Select(Double) |
Given a floating-point number, returns the keyword of the first rule that applies to the number. |
Select(FormattedNumber) |
Given a formatted number, returns the keyword of the first rule that applies to the number. |
Select(FormattedNumberRange) |
Given a formatted number range, returns the overall plural form of the range. |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
ToArray<T>() | (Inherited from Object) |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |
Gets the JNI name of the type of the instance |
JavaAs<TResult>(IJavaPeerable) |
Try to coerce |
TryJavaCast<TResult>(IJavaPeerable, TResult) |
Try to coerce |