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

public final Class MessagePatternUtil

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collections, .List

Utilities for working with a MessagePattern. Intended for use in tools when convenience is more important than minimizing runtime and object creations.

This class only has static methods. Each of the nested classes is immutable and thread-safe.

This class and its nested classes are not intended for public subclassing.

Author
Markus Scherer
ICU Status
Stable since ICU 49.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
MessagePatternUtil.ArgNode

A piece of MessageNode contents representing a message argument and its details.

public static class
MessagePatternUtil.ComplexArgStyleNode

A Node representing details of the argument style of a complex argument.

public static class
MessagePatternUtil.MessageContentsNode

A piece of MessageNode contents.

public static class
MessagePatternUtil.MessageNode

A Node representing a parsed MessageFormat pattern string.

public static class
MessagePatternUtil.Node

Common base class for all elements in a tree of nodes returned by MessagePatternUtil#buildMessageNode(MessagePattern).

public static class
MessagePatternUtil.TextNode

Literal text, a piece of MessageNode contents.

public static class
MessagePatternUtil.VariantNode

A Node representing a nested message (nested inside an argument) with its selection criterion.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static MessagePatternUtil.ArgNode
buildArgNode(MessagePattern pattern, int start, int limit)

private static MessagePatternUtil.ComplexArgStyleNode
buildChoiceStyleNode(MessagePattern pattern, int start, int limit)

public static MessagePatternUtil.MessageNode

Returns:

a MessageNode or a ComplexArgStyleNode
buildMessageNode
(String
a MessageFormat pattern string
patternString
)

Factory method, builds and returns a MessageNode from a MessageFormat pattern string.

public static MessagePatternUtil.MessageNode

Returns:

a MessageNode or a ComplexArgStyleNode
buildMessageNode
(MessagePattern
a parsed MessageFormat pattern string
pattern
)

Factory method, builds and returns a MessageNode from a MessagePattern.

private static MessagePatternUtil.MessageNode
buildMessageNode(MessagePattern pattern, int start, int limit)

private static MessagePatternUtil.ComplexArgStyleNode
buildPluralStyleNode(MessagePattern pattern, int start, int limit, MessagePattern.ArgType argType)

private static MessagePatternUtil.ComplexArgStyleNode
buildSelectStyleNode(MessagePattern pattern, int start, int limit)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MessagePatternUtilback to summary
private MessagePatternUtil()

Method Detail

buildArgNodeback to summary
private static MessagePatternUtil.ArgNode buildArgNode(MessagePattern pattern, int start, int limit)
buildChoiceStyleNodeback to summary
private static MessagePatternUtil.ComplexArgStyleNode buildChoiceStyleNode(MessagePattern pattern, int start, int limit)
buildMessageNodeback to summary
public static MessagePatternUtil.MessageNode buildMessageNode(String patternString)

Factory method, builds and returns a MessageNode from a MessageFormat pattern string.

Parameters
patternString:String

a MessageFormat pattern string

Returns:MessagePatternUtil.MessageNode

a MessageNode or a ComplexArgStyleNode

Exceptions
IllegalArgumentException:
if the MessagePattern is empty or does not represent a MessageFormat pattern
ICU Status
Stable since ICU 49.
buildMessageNodeback to summary
public static MessagePatternUtil.MessageNode buildMessageNode(MessagePattern pattern)

Factory method, builds and returns a MessageNode from a MessagePattern.

Parameters
pattern:MessagePattern

a parsed MessageFormat pattern string

Returns:MessagePatternUtil.MessageNode

a MessageNode or a ComplexArgStyleNode

Exceptions
IllegalArgumentException:
if the MessagePattern is empty or does not represent a MessageFormat pattern
ICU Status
Stable since ICU 49.
buildMessageNodeback to summary
private static MessagePatternUtil.MessageNode buildMessageNode(MessagePattern pattern, int start, int limit)
buildPluralStyleNodeback to summary
private static MessagePatternUtil.ComplexArgStyleNode buildPluralStyleNode(MessagePattern pattern, int start, int limit, MessagePattern.ArgType argType)
buildSelectStyleNodeback to summary
private static MessagePatternUtil.ComplexArgStyleNode buildSelectStyleNode(MessagePattern pattern, int start, int limit)
com.ibm.icu.text back to summary

public Class MessagePatternUtil.ArgNode

extends MessageContentsNode
Class Inheritance

A piece of MessageNode contents representing a message argument and its details.
ICU Status
Stable since ICU 49.

Field Summary

Modifier and TypeField and Description
private MessagePattern.ArgType
private MessagePatternUtil.ComplexArgStyleNode
private String
private int
private String
private String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static MessagePatternUtil.ArgNode
public MessagePattern.ArgType

Returns:

the argument type
getArgType
()

public MessagePatternUtil.ComplexArgStyleNode

Returns:

the complex-argument-style object, or null if the argument type is NONE_ARG or SIMPLE_ARG
getComplexStyle
()

public String

Returns:

the argument name string (the decimal-digit string if the argument has a number)
getName
()

public int

Returns:

the argument number, or -1 if none (for a named argument)
getNumber
()

public String

Returns:

the simple-argument style string, or null if no style is specified and for other argument types
getSimpleStyle
()

public String

Returns:

the argument type string, or null if none was specified
getTypeName
()

public String
toString()

Overrides com.ibm.icu.text.MessagePatternUtil.MessageContentsNode.toString.

Returns a string representation of the object.
Inherited from com.ibm.icu.text.MessagePatternUtil.MessageContentsNode:
getType

Field Detail

argTypeback to summary
private MessagePattern.ArgType argType
complexStyleback to summary
private MessagePatternUtil.ComplexArgStyleNode complexStyle
nameback to summary
private String name
numberback to summary
private int number
styleback to summary
private String style
typeNameback to summary
private String typeName

Constructor Detail

ArgNodeback to summary
private ArgNode()

Method Detail

createArgNodeback to summary
private static MessagePatternUtil.ArgNode createArgNode()
getArgTypeback to summary
public MessagePattern.ArgType getArgType()
Returns:MessagePattern.ArgType

the argument type

ICU Status
Stable since ICU 49.
getComplexStyleback to summary
public MessagePatternUtil.ComplexArgStyleNode getComplexStyle()
Returns:MessagePatternUtil.ComplexArgStyleNode

the complex-argument-style object, or null if the argument type is NONE_ARG or SIMPLE_ARG

ICU Status
Stable since ICU 49.
getNameback to summary
public String getName()
Returns:String

the argument name string (the decimal-digit string if the argument has a number)

ICU Status
Stable since ICU 49.
getNumberback to summary
public int getNumber()
Returns:int

the argument number, or -1 if none (for a named argument)

ICU Status
Stable since ICU 49.
getSimpleStyleback to summary
public String getSimpleStyle()
Returns:String

the simple-argument style string, or null if no style is specified and for other argument types

ICU Status
Stable since ICU 49.
getTypeNameback to summary
public String getTypeName()
Returns:String

the argument type string, or null if none was specified

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

Overrides com.ibm.icu.text.MessagePatternUtil.MessageContentsNode.toString.

Doc from com.ibm.icu.text.MessagePatternUtil.MessageContentsNode.toString.

Returns a string representation of the object.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

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

public Class MessagePatternUtil.ComplexArgStyleNode

extends Node
Class Inheritance

A Node representing details of the argument style of a complex argument. (Which is a choice/plural/select argument which selects among nested messages.)
ICU Status
Stable since ICU 49.

Field Summary

Modifier and TypeField and Description
private MessagePattern.ArgType
private boolean
private volatile List<MessagePatternUtil.VariantNode>
private double

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
private MessagePatternUtil.ComplexArgStyleNode
public MessagePattern.ArgType

Returns:

the argument type (same as getArgType() on the parent ArgNode)
getArgType
()

public double

Returns:

the plural offset, or 0 if this is not a plural style or the offset is explicitly or implicitly 0
getOffset
()

public List<MessagePatternUtil.VariantNode>

Returns:

the list of variants: the nested messages with their selection criteria
getVariants
()

public MessagePatternUtil.VariantNode

Returns:

the "other" variant (the first one if there are several), null if none (choice style)
getVariantsByType
(List<MessagePatternUtil.VariantNode>
Variants with numeric-value selectors (if any) are added here. Can be null for a select argument style.
numericVariants
,
List<MessagePatternUtil.VariantNode>
Variants with keyword selectors, except "other", are added here. For a plural argument, if this list is empty after the call, then all variants except "other" have explicit values and PluralRules need not be called.
keywordVariants
)

Separates the variants by type.

public boolean

Returns:

true if this is a plural style with an explicit offset
hasExplicitOffset
()

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

argTypeback to summary
private MessagePattern.ArgType argType
explicitOffsetback to summary
private boolean explicitOffset
listback to summary
private volatile List<MessagePatternUtil.VariantNode> list
offsetback to summary
private double offset

Constructor Detail

ComplexArgStyleNodeback to summary
private ComplexArgStyleNode(MessagePattern.ArgType argType)

Method Detail

addVariantback to summary
private void addVariant(MessagePatternUtil.VariantNode variant)
freezeback to summary
private MessagePatternUtil.ComplexArgStyleNode freeze()
getArgTypeback to summary
public MessagePattern.ArgType getArgType()
Returns:MessagePattern.ArgType

the argument type (same as getArgType() on the parent ArgNode)

ICU Status
Stable since ICU 49.
getOffsetback to summary
public double getOffset()
Returns:double

the plural offset, or 0 if this is not a plural style or the offset is explicitly or implicitly 0

ICU Status
Stable since ICU 49.
getVariantsback to summary
public List<MessagePatternUtil.VariantNode> getVariants()
Returns:List<MessagePatternUtil.VariantNode>

the list of variants: the nested messages with their selection criteria

ICU Status
Stable since ICU 49.
getVariantsByTypeback to summary
public MessagePatternUtil.VariantNode getVariantsByType(List<MessagePatternUtil.VariantNode> numericVariants, List<MessagePatternUtil.VariantNode> keywordVariants)

Separates the variants by type. Intended for use with plural and select argument styles, not useful for choice argument styles.

Both parameters are used only for output, and are first cleared.

Parameters
numericVariants:List<MessagePatternUtil.VariantNode>

Variants with numeric-value selectors (if any) are added here. Can be null for a select argument style.

keywordVariants:List<MessagePatternUtil.VariantNode>

Variants with keyword selectors, except "other", are added here. For a plural argument, if this list is empty after the call, then all variants except "other" have explicit values and PluralRules need not be called.

Returns:MessagePatternUtil.VariantNode

the "other" variant (the first one if there are several), null if none (choice style)

ICU Status
Stable since ICU 49.
hasExplicitOffsetback to summary
public boolean hasExplicitOffset()
Returns:boolean

true if this is a plural style with an explicit offset

ICU Status
Stable since ICU 49.
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 49.
com.ibm.icu.text back to summary

public Class MessagePatternUtil.MessageContentsNode

extends Node
Class Inheritance
Known Direct Subclasses
com.ibm.icu.text.MessagePatternUtil.TextNode, com.ibm.icu.text.MessagePatternUtil.ArgNode

A piece of MessageNode contents. Use getType() to determine the type and the actual Node subclass.
ICU Status
Stable since ICU 49.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
MessagePatternUtil.MessageContentsNode.Type

The type of a piece of MessageNode contents.

Field Summary

Modifier and TypeField and Description
private MessagePatternUtil.MessageContentsNode.Type

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static MessagePatternUtil.MessageContentsNode
public MessagePatternUtil.MessageContentsNode.Type
getType()

Returns the type of this piece of MessageNode contents.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

typeback to summary
private MessagePatternUtil.MessageContentsNode.Type type

Constructor Detail

MessageContentsNodeback to summary
private MessageContentsNode(MessagePatternUtil.MessageContentsNode.Type type)

Method Detail

createReplaceNumberNodeback to summary
private static MessagePatternUtil.MessageContentsNode createReplaceNumberNode()
getTypeback to summary
public MessagePatternUtil.MessageContentsNode.Type getType()

Returns the type of this piece of MessageNode contents.

ICU Status
Stable since ICU 49.
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 49.
com.ibm.icu.text back to summary

public final Enum MessagePatternUtil.MessageContentsNode.Type

extends Enum<MessagePatternUtil.MessageContentsNode.Type>
Class Inheritance

The type of a piece of MessageNode contents.
ICU Status
Stable since ICU 49.

Field Summary

Modifier and TypeField and Description
public static final MessagePatternUtil.MessageContentsNode.Type
ARG

This is an ArgNode representing a message argument (downcast and use specific methods).

public static final MessagePatternUtil.MessageContentsNode.Type
REPLACE_NUMBER

This Node represents a place in a plural argument's variant where the formatted (plural-offset) value is to be put.

public static final MessagePatternUtil.MessageContentsNode.Type
TEXT

This is a TextNode containing literal text (downcast and call getText()).

Constructor Summary

AccessConstructor and Description
private
Type()

Field Detail

ARGback to summary
public static final MessagePatternUtil.MessageContentsNode.Type ARG

This is an ArgNode representing a message argument (downcast and use specific methods).

ICU Status
Stable since ICU 49.
REPLACE_NUMBERback to summary
public static final MessagePatternUtil.MessageContentsNode.Type REPLACE_NUMBER

This Node represents a place in a plural argument's variant where the formatted (plural-offset) value is to be put.

ICU Status
Stable since ICU 49.
TEXTback to summary
public static final MessagePatternUtil.MessageContentsNode.Type TEXT

This is a TextNode containing literal text (downcast and call getText()).

ICU Status
Stable since ICU 49.

Constructor Detail

Typeback to summary
private Type()

Method Detail

valueOfback to summary
public static MessagePatternUtil.MessageContentsNode.Type valueOf(String name)
valuesback to summary
public static MessagePatternUtil.MessageContentsNode.Type[] values()
com.ibm.icu.text back to summary

public Class MessagePatternUtil.MessageNode

extends Node
Class Inheritance

A Node representing a parsed MessageFormat pattern string.
ICU Status
Stable since ICU 49.

Field Summary

Modifier and TypeField and Description
private volatile List<MessagePatternUtil.MessageContentsNode>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
private MessagePatternUtil.MessageNode
public List<MessagePatternUtil.MessageContentsNode>

Returns:

the list of MessageContentsNode nodes that this message contains
getContents
()

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

listback to summary
private volatile List<MessagePatternUtil.MessageContentsNode> list

Constructor Detail

MessageNodeback to summary
private MessageNode()

Method Detail

addContentsNodeback to summary
private void addContentsNode(MessagePatternUtil.MessageContentsNode node)
freezeback to summary
private MessagePatternUtil.MessageNode freeze()
getContentsback to summary
public List<MessagePatternUtil.MessageContentsNode> getContents()
Returns:List<MessagePatternUtil.MessageContentsNode>

the list of MessageContentsNode nodes that this message contains

ICU Status
Stable since ICU 49.
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 49.
com.ibm.icu.text back to summary

public Class MessagePatternUtil.Node

extends Object
Class Inheritance
Known Direct Subclasses
com.ibm.icu.text.MessagePatternUtil.MessageNode, com.ibm.icu.text.MessagePatternUtil.MessageContentsNode, com.ibm.icu.text.MessagePatternUtil.ComplexArgStyleNode, com.ibm.icu.text.MessagePatternUtil.VariantNode

Common base class for all elements in a tree of nodes returned by MessagePatternUtil#buildMessageNode(MessagePattern). This class and all subclasses are immutable and thread-safe.
ICU Status
Stable since ICU 49.

Constructor Summary

AccessConstructor and Description
private
Node()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Nodeback to summary
private Node()
com.ibm.icu.text back to summary

public Class MessagePatternUtil.TextNode

extends MessageContentsNode
Class Inheritance

Literal text, a piece of MessageNode contents.
ICU Status
Stable since ICU 49.

Field Summary

Modifier and TypeField and Description
private String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the literal text at this point in the message
getText
()

public String
toString()

Overrides com.ibm.icu.text.MessagePatternUtil.MessageContentsNode.toString.

Returns a string representation of the object.
Inherited from com.ibm.icu.text.MessagePatternUtil.MessageContentsNode:
getType

Field Detail

textback to summary
private String text

Constructor Detail

TextNodeback to summary
private TextNode(String text)

Method Detail

getTextback to summary
public String getText()
Returns:String

the literal text at this point in the message

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

Overrides com.ibm.icu.text.MessagePatternUtil.MessageContentsNode.toString.

Doc from com.ibm.icu.text.MessagePatternUtil.MessageContentsNode.toString.

Returns a string representation of the object.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

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

public Class MessagePatternUtil.VariantNode

extends Node
Class Inheritance

A Node representing a nested message (nested inside an argument) with its selection criterion.
ICU Status
Stable since ICU 49.

Field Summary

Modifier and TypeField and Description
private MessagePatternUtil.MessageNode
private double
private String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public MessagePatternUtil.MessageNode

Returns:

the nested message
getMessage
()

public String

Returns:

the selector string
getSelector
()

Returns the selector string.

public double

Returns:

the selector's numeric value, or NO_NUMERIC_VALUE if !isSelectorNumeric()
getSelectorValue
()

public boolean

Returns:

true for choice variants and for plural explicit values
isSelectorNumeric
()

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

msgNodeback to summary
private MessagePatternUtil.MessageNode msgNode
numericValueback to summary
private double numericValue
selectorback to summary
private String selector

Constructor Detail

VariantNodeback to summary
private VariantNode()

Method Detail

getMessageback to summary
public MessagePatternUtil.MessageNode getMessage()
Returns:MessagePatternUtil.MessageNode

the nested message

ICU Status
Stable since ICU 49.
getSelectorback to summary
public String getSelector()

Returns the selector string. For example: A plural/select keyword ("few"), a plural explicit value ("=1"), a choice comparison operator ("#").

Returns:String

the selector string

ICU Status
Stable since ICU 49.
getSelectorValueback to summary
public double getSelectorValue()
Returns:double

the selector's numeric value, or NO_NUMERIC_VALUE if !isSelectorNumeric()

ICU Status
Stable since ICU 49.
isSelectorNumericback to summary
public boolean isSelectorNumeric()
Returns:boolean

true for choice variants and for plural explicit values

ICU Status
Stable since ICU 49.
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 49.