Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/icu/text/MessagePattern#nestedclasses) \| [Constants](https://developer.android.com/reference/android/icu/text/MessagePattern#constants) \| [Ctors](https://developer.android.com/reference/android/icu/text/MessagePattern#pubctors) \| [Methods](https://developer.android.com/reference/android/icu/text/MessagePattern#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/icu/text/MessagePattern#inhmethods)

# MessagePattern

*** ** * ** ***

` public final class MessagePattern `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/lang/Cloneable, https://developer.android.com/reference/android/icu/util/Freezable<https://developer.android.com/reference/android/icu/text/MessagePattern> `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.icu.text.MessagePattern |

<br />

*** ** * ** ***

Parses and represents ICU MessageFormat patterns. Also handles patterns for ChoiceFormat, PluralFormat and SelectFormat. Used in the implementations of those classes as well as in tools for message validation, translation and format conversion.

The parser handles all syntax relevant for identifying message arguments. This includes "complex" arguments whose style strings contain nested MessageFormat pattern substrings. For "simple" arguments (with no nested MessageFormat pattern substrings), the argument style is not parsed any further.

The parser handles named and numbered message arguments and allows both in one message.

Once a pattern has been parsed successfully, iterate through the parsed data with countParts(), getPart() and related methods.

The data logically represents a parse tree, but is stored and accessed as a list of "parts" for fast and simple parsing and to minimize object allocations. Arguments and nested messages are best handled via recursion. For every _START "part", `https://developer.android.com/reference/android/icu/text/MessagePattern#getLimitPartIndex(int)` efficiently returns the index of the corresponding _LIMIT "part".

List of "parts":

```
message = MSG_START (SKIP_SYNTAX | INSERT_CHAR | REPLACE_NUMBER | argument)* MSG_LIMIT
argument = noneArg | simpleArg | complexArg
complexArg = choiceArg | pluralArg | selectArg

noneArg = ARG_START.NONE (ARG_NAME | ARG_NUMBER) ARG_LIMIT.NONE
simpleArg = ARG_START.SIMPLE (ARG_NAME | ARG_NUMBER) ARG_TYPE [ARG_STYLE] ARG_LIMIT.SIMPLE
choiceArg = ARG_START.CHOICE (ARG_NAME | ARG_NUMBER) choiceStyle ARG_LIMIT.CHOICE
pluralArg = ARG_START.PLURAL (ARG_NAME | ARG_NUMBER) pluralStyle ARG_LIMIT.PLURAL
selectArg = ARG_START.SELECT (ARG_NAME | ARG_NUMBER) selectStyle ARG_LIMIT.SELECT

choiceStyle = ((ARG_INT | ARG_DOUBLE) ARG_SELECTOR message)+
pluralStyle = [ARG_INT | ARG_DOUBLE] (ARG_SELECTOR [ARG_INT | ARG_DOUBLE] message)+
selectStyle = (ARG_SELECTOR message)+
```

- Literal output text is not represented directly by "parts" but accessed between parts of a message, from one part's getLimit() to the next part's getIndex().
- `ARG_START.CHOICE` stands for an ARG_START Part with ArgType CHOICE.
- In the choiceStyle, the ARG_SELECTOR has the '\<', the '#' or the less-than-or-equal-to sign (U+2264).
- In the pluralStyle, the first, optional numeric Part has the "offset:" value. The optional numeric Part between each (ARG_SELECTOR, message) pair is the value of an explicit-number selector like "=2", otherwise the selector is a non-numeric identifier.
- The REPLACE_NUMBER Part can occur only in an immediate sub-message of the pluralStyle.

This class is not intended for public subclassing.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/icu/text/MessagePattern.Part` A message pattern "part", representing a pattern parsing event. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/icu/text/MessagePattern#ARG_NAME_NOT_NUMBER` Return value from `https://developer.android.com/reference/android/icu/text/MessagePattern#validateArgumentName(java.lang.String)` for when the string is a valid "pattern identifier" but not a number. |
| `int` | `https://developer.android.com/reference/android/icu/text/MessagePattern#ARG_NAME_NOT_VALID` Return value from `https://developer.android.com/reference/android/icu/text/MessagePattern#validateArgumentName(java.lang.String)` for when the string is invalid. |
| `double` | `https://developer.android.com/reference/android/icu/text/MessagePattern#NO_NUMERIC_VALUE` Special value that is returned by getNumericValue(Part) when no numeric value is defined for a part. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/icu/text/MessagePattern#MessagePattern()() ` Constructs an empty MessagePattern with default ApostropheMode. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern#MessagePattern(android.icu.text.MessagePattern.ApostropheMode)(https://developer.android.com/reference/android/icu/text/MessagePattern.ApostropheMode mode) ` Constructs an empty MessagePattern. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern#MessagePattern(java.lang.String)(https://developer.android.com/reference/java/lang/String pattern) ` Constructs a MessagePattern with default ApostropheMode and parses the MessageFormat pattern string. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#autoQuoteApostropheDeep()() ` Returns a version of the parsed pattern string where each ASCII apostrophe is doubled (escaped) if it is not already, and if it is not interpreted as quoting syntax. |
| ` void` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#clear()() ` Clears this MessagePattern. |
| ` void` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#clearPatternAndSetApostropheMode(android.icu.text.MessagePattern.ApostropheMode)(https://developer.android.com/reference/android/icu/text/MessagePattern.ApostropheMode mode) ` Clears this MessagePattern and sets the ApostropheMode. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#clone()() ` Creates and returns a copy of this object. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#cloneAsThawed()() ` Creates and returns an unfrozen copy of this object. |
| ` int` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#countParts()() ` Returns the number of "parts" created by parsing the pattern string. |
| ` boolean` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object other) ` Indicates whether some other object is "equal to" this one. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#freeze()() ` Freezes this object, making it immutable and thread-safe. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern.ApostropheMode` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getApostropheMode()() ` |
| ` int` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getLimitPartIndex(int)(int start) ` Returns the index of the ARG\|MSG_LIMIT part corresponding to the ARG\|MSG_START at start. |
| ` double` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getNumericValue(android.icu.text.MessagePattern.Part)(https://developer.android.com/reference/android/icu/text/MessagePattern.Part part) ` Returns the numeric value associated with an ARG_INT or ARG_DOUBLE. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern.Part` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getPart(int)(int i) ` Gets the i-th pattern "part". |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern.Part.Type` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getPartType(int)(int i) ` Returns the Part.Type of the i-th pattern "part". |
| ` int` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getPatternIndex(int)(int partIndex) ` Returns the pattern index of the specified pattern "part". |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getPatternString()() ` |
| ` double` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getPluralOffset(int)(int pluralStart) ` Returns the "offset:" value of a PluralFormat argument, or 0 if none is specified. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#getSubstring(android.icu.text.MessagePattern.Part)(https://developer.android.com/reference/android/icu/text/MessagePattern.Part part) ` Returns the substring of the pattern string indicated by the Part. |
| ` boolean` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#hasNamedArguments()() ` Does the parsed pattern have named arguments like {first_name}? |
| ` boolean` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#hasNumberedArguments()() ` Does the parsed pattern have numbered arguments like {2}? |
| ` int` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#hashCode()() ` Returns a hash code value for the object. |
| ` boolean` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#isFrozen()() ` Determines whether this object is frozen (immutable) or not. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#parse(java.lang.String)(https://developer.android.com/reference/java/lang/String pattern) ` Parses a MessageFormat pattern string. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#parseChoiceStyle(java.lang.String)(https://developer.android.com/reference/java/lang/String pattern) ` Parses a ChoiceFormat pattern string. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#parsePluralStyle(java.lang.String)(https://developer.android.com/reference/java/lang/String pattern) ` Parses a PluralFormat pattern string. |
| ` https://developer.android.com/reference/android/icu/text/MessagePattern` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#parseSelectStyle(java.lang.String)(https://developer.android.com/reference/java/lang/String pattern) ` Parses a SelectFormat pattern string. |
| ` boolean` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#partSubstringMatches(android.icu.text.MessagePattern.Part,%20java.lang.String)(https://developer.android.com/reference/android/icu/text/MessagePattern.Part part, https://developer.android.com/reference/java/lang/String s) ` Compares the part's substring with the input string s. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#toString()() ` Returns a string representation of the object. |
| ` static int` | ` https://developer.android.com/reference/android/icu/text/MessagePattern#validateArgumentName(java.lang.String)(https://developer.android.com/reference/java/lang/String name) ` Validates and parses an argument name or argument number string. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/icu/util/Freezable ` ` abstract https://developer.android.com/reference/android/icu/text/MessagePattern` ` https://developer.android.com/reference/android/icu/util/Freezable#cloneAsThawed()() `

Provides for the clone operation.
` abstract https://developer.android.com/reference/android/icu/text/MessagePattern` ` https://developer.android.com/reference/android/icu/util/Freezable#freeze()() `

Freezes the object.
` abstract boolean` ` https://developer.android.com/reference/android/icu/util/Freezable#isFrozen()() `

Determines whether the object has been frozen or not.

## Constants

### ARG_NAME_NOT_NUMBER

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ARG_NAME_NOT_NUMBER
```

Return value from `https://developer.android.com/reference/android/icu/text/MessagePattern#validateArgumentName(java.lang.String)` for when the string is a valid "pattern identifier" but not a number.

<br />

Constant Value: -1 (0xffffffff)

### ARG_NAME_NOT_VALID

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ARG_NAME_NOT_VALID
```

Return value from `https://developer.android.com/reference/android/icu/text/MessagePattern#validateArgumentName(java.lang.String)` for when the string is invalid. It might not be a valid "pattern identifier", or it have only ASCII digits but there is a leading zero or the number is too large.

<br />

Constant Value: -2 (0xfffffffe)

### NO_NUMERIC_VALUE

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final double NO_NUMERIC_VALUE
```

Special value that is returned by getNumericValue(Part) when no numeric value is defined for a part.

<br />

**See also:**

- `https://developer.android.com/reference/android/icu/text/MessagePattern#getNumericValue(android.icu.text.MessagePattern.Part)`

Constant Value: -1.23456789E8

## Public constructors

### MessagePattern

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern ()
```

Constructs an empty MessagePattern with default ApostropheMode.

<br />

### MessagePattern

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern (MessagePattern.ApostropheMode mode)
```

Constructs an empty MessagePattern.

<br />

| Parameters ||
|---|---|
| `mode` | `MessagePattern.ApostropheMode`: Explicit ApostropheMode. <br /> |

### MessagePattern

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern (String pattern)
```

Constructs a MessagePattern with default ApostropheMode and parses the MessageFormat pattern string.

<br />

| Parameters ||
|---|---|
| `pattern` | `String`: a MessageFormat pattern string <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | for syntax errors in the pattern string |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if certain limits are exceeded (e.g., argument number too high, argument name too long, etc.) |
| `https://developer.android.com/reference/java/lang/NumberFormatException` | if a number could not be parsed |

## Public methods

### autoQuoteApostropheDeep

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String autoQuoteApostropheDeep ()
```

Returns a version of the parsed pattern string where each ASCII apostrophe is doubled (escaped) if it is not already, and if it is not interpreted as quoting syntax.

For example, this turns "I don't '{know}' {gender,select,female{h''er}other{h'im}}." into "I don''t '{know}' {gender,select,female{h''er}other{h''im}}."

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the deep-auto-quoted version of the parsed pattern string. <br /> |

**See also:**

- `https://developer.android.com/reference/android/icu/text/MessageFormat#autoQuoteApostrophe(java.lang.String)`

### clear

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clear ()
```

Clears this MessagePattern. countParts() will return 0.

<br />

### clearPatternAndSetApostropheMode

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clearPatternAndSetApostropheMode (MessagePattern.ApostropheMode mode)
```

Clears this MessagePattern and sets the ApostropheMode. countParts() will return 0.

<br />

| Parameters ||
|---|---|
| `mode` | `MessagePattern.ApostropheMode`: The new ApostropheMode. <br /> |

### clone

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object clone ()
```

Creates and returns a copy of this object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | a copy of this object (or itself if frozen). <br /> |

### cloneAsThawed

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern cloneAsThawed ()
```

Creates and returns an unfrozen copy of this object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern` | a copy of this object. <br /> |

### countParts

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int countParts ()
```

Returns the number of "parts" created by parsing the pattern string. Returns 0 if no pattern has been parsed or clear() was called.

<br />

| Returns ||
|---|---|
| `int` | the number of pattern parts. <br /> |

### equals

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object other)
```

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.

<br />

| Parameters ||
|---|---|
| `other` | `Object`: another object to compare with. <br /> |

| Returns ||
|---|---|
| `boolean` | true if this object is equivalent to the other one. <br /> |

### freeze

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern freeze ()
```

Freezes this object, making it immutable and thread-safe.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern` | this <br /> |

### getApostropheMode

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern.ApostropheMode getApostropheMode ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern.ApostropheMode` | this instance's ApostropheMode. <br /> |

### getLimitPartIndex

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getLimitPartIndex (int start)
```

Returns the index of the ARG\|MSG_LIMIT part corresponding to the ARG\|MSG_START at start.

<br />

| Parameters ||
|---|---|
| `start` | `int`: The index of some Part data (0..countParts()-1); this Part should be of Type ARG_START or MSG_START. <br /> |

| Returns ||
|---|---|
| `int` | The first i\>start where getPart(i).getType()==ARG\|MSG_LIMIT at the same nesting level, or start itself if getPartType(msgStart)!=ARG\|MSG_START. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if start is outside the (0..countParts()-1) range |

### getNumericValue

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public double getNumericValue (MessagePattern.Part part)
```

Returns the numeric value associated with an ARG_INT or ARG_DOUBLE.

<br />

| Parameters ||
|---|---|
| `part` | `MessagePattern.Part`: a part of this MessagePattern. <br /> |

| Returns ||
|---|---|
| `double` | the part's numeric value, or NO_NUMERIC_VALUE if this is not a numeric part. <br /> |

### getPart

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern.Part getPart (int i)
```

Gets the i-th pattern "part".

<br />

| Parameters ||
|---|---|
| `i` | `int`: The index of the Part data. (0..countParts()-1) <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern.Part` | the i-th pattern "part". <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if i is outside the (0..countParts()-1) range |

### getPartType

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern.Part.Type getPartType (int i)
```

Returns the Part.Type of the i-th pattern "part". Convenience method for getPart(i).getType().

<br />

| Parameters ||
|---|---|
| `i` | `int`: The index of the Part data. (0..countParts()-1) <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern.Part.Type` | The Part.Type of the i-th Part. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if i is outside the (0..countParts()-1) range |

### getPatternIndex

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getPatternIndex (int partIndex)
```

Returns the pattern index of the specified pattern "part". Convenience method for getPart(partIndex).getIndex().

<br />

| Parameters ||
|---|---|
| `partIndex` | `int`: The index of the Part data. (0..countParts()-1) <br /> |

| Returns ||
|---|---|
| `int` | The pattern index of this Part. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if partIndex is outside the (0..countParts()-1) range |

### getPatternString

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getPatternString ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the parsed pattern string (null if none was parsed). <br /> |

### getPluralOffset

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public double getPluralOffset (int pluralStart)
```

Returns the "offset:" value of a PluralFormat argument, or 0 if none is specified.

<br />

| Parameters ||
|---|---|
| `pluralStart` | `int`: the index of the first PluralFormat argument style part. (0..countParts()-1) <br /> |

| Returns ||
|---|---|
| `double` | the "offset:" value. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if pluralStart is outside the (0..countParts()-1) range |

### getSubstring

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getSubstring (MessagePattern.Part part)
```

Returns the substring of the pattern string indicated by the Part. Convenience method for getPatternString().substring(part.getIndex(), part.getLimit()).

<br />

| Parameters ||
|---|---|
| `part` | `MessagePattern.Part`: a part of this MessagePattern. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the substring associated with part. <br /> |

### hasNamedArguments

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean hasNamedArguments ()
```

Does the parsed pattern have named arguments like {first_name}?

<br />

| Returns ||
|---|---|
| `boolean` | true if the parsed pattern has at least one named argument. <br /> |

### hasNumberedArguments

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean hasNumberedArguments ()
```

Does the parsed pattern have numbered arguments like {2}?

<br />

| Returns ||
|---|---|
| `boolean` | true if the parsed pattern has at least one numbered argument. <br /> |

### hashCode

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by `https://developer.android.com/reference/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 `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` 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 `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` 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.

<br />

<br />

| Returns ||
|---|---|
| `int` | a hash code value for this object. <br /> |

### isFrozen

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isFrozen ()
```

Determines whether this object is frozen (immutable) or not.

<br />

| Returns ||
|---|---|
| `boolean` | true if this object is frozen. <br /> |

### parse

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern parse (String pattern)
```

Parses a MessageFormat pattern string.

<br />

| Parameters ||
|---|---|
| `pattern` | `String`: a MessageFormat pattern string <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern` | this <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | for syntax errors in the pattern string |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if certain limits are exceeded (e.g., argument number too high, argument name too long, etc.) |
| `https://developer.android.com/reference/java/lang/NumberFormatException` | if a number could not be parsed |

### parseChoiceStyle

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern parseChoiceStyle (String pattern)
```

Parses a ChoiceFormat pattern string.

<br />

| Parameters ||
|---|---|
| `pattern` | `String`: a ChoiceFormat pattern string <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern` | this <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | for syntax errors in the pattern string |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if certain limits are exceeded (e.g., argument number too high, argument name too long, etc.) |
| `https://developer.android.com/reference/java/lang/NumberFormatException` | if a number could not be parsed |

### parsePluralStyle

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern parsePluralStyle (String pattern)
```

Parses a PluralFormat pattern string.

<br />

| Parameters ||
|---|---|
| `pattern` | `String`: a PluralFormat pattern string <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern` | this <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | for syntax errors in the pattern string |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if certain limits are exceeded (e.g., argument number too high, argument name too long, etc.) |
| `https://developer.android.com/reference/java/lang/NumberFormatException` | if a number could not be parsed |

### parseSelectStyle

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagePattern parseSelectStyle (String pattern)
```

Parses a SelectFormat pattern string.

<br />

| Parameters ||
|---|---|
| `pattern` | `String`: a SelectFormat pattern string <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/MessagePattern` | this <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | for syntax errors in the pattern string |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if certain limits are exceeded (e.g., argument number too high, argument name too long, etc.) |
| `https://developer.android.com/reference/java/lang/NumberFormatException` | if a number could not be parsed |

### partSubstringMatches

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean partSubstringMatches (MessagePattern.Part part, 
                String s)
```

Compares the part's substring with the input string s.

<br />

| Parameters ||
|---|---|
| `part` | `MessagePattern.Part`: a part of this MessagePattern. <br /> |
| `s` | `String`: a string. <br /> |

| Returns ||
|---|---|
| `boolean` | true if getSubstring(part).equals(s). <br /> |

### toString

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

### validateArgumentName

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int validateArgumentName (String name)
```

Validates and parses an argument name or argument number string. An argument name must be a "pattern identifier", that is, it must contain no Unicode Pattern_Syntax or Pattern_White_Space characters. If it only contains ASCII digits, then it must be a small integer with no leading zero.

<br />

| Parameters ||
|---|---|
| `name` | `String`: Input string. <br /> |

| Returns ||
|---|---|
| `int` | \>=0 if the name is a valid number, ARG_NAME_NOT_NUMBER (-1) if it is a "pattern identifier" but not all ASCII digits, ARG_NAME_NOT_VALID (-2) if it is neither. <br /> |