java.text

Class MessageFormat

public class MessageFormat extends Format

Nested Class Summary
static classMessageFormat.Field
Constructor Summary
MessageFormat(String pattern)
Creates a new MessageFormat object with the specified pattern
MessageFormat(String pattern, Locale locale)
Creates a new MessageFormat object with the specified pattern
Method Summary
voidapplyPattern(String newPattern)
Applies the specified pattern to this MessageFormat.
Objectclone()
Overrides Format.clone()
booleanequals(Object obj)
Overrides Format.equals(Object obj)
static Stringformat(String pattern, Object... arguments)
A convinience method to format patterns.
StringBufferformat(Object[] arguments, StringBuffer appendBuf, FieldPosition fp)
Returns the pattern with the formatted objects.
StringBufferformat(Object objectArray, StringBuffer appendBuf, FieldPosition fpos)
Returns the pattern with the formatted objects.
AttributedCharacterIteratorformatToCharacterIterator(Object arguments)
A convinience method to format patterns.
Format[]getFormats()
Returns an array with the Formats for the arguments.
Format[]getFormatsByArgumentIndex()
Return the formatters used sorted by argument index.
LocalegetLocale()
Returns the locale.
inthashCode()
Overrides Format.hashCode()
Object[]parse(String sourceStr, ParsePosition pos)
Parse a string sourceStr against the pattern specified to the MessageFormat constructor.
Object[]parse(String sourceStr)
ObjectparseObject(String sourceStr, ParsePosition pos)
voidsetFormat(int variableNum, Format newFormat)
Sets the format for the argument at an specified index.
voidsetFormatByArgumentIndex(int argumentIndex, Format newFormat)
Set the format to used using the argument index number.
voidsetFormats(Format[] newFormats)
Sets the formats for the arguments.
voidsetFormatsByArgumentIndex(Format[] newFormats)
Set the format for argument using a specified array of formatters which is sorted according to the argument index.
voidsetLocale(Locale loc)
Sets the locale.
StringtoPattern()
Returns the pattern.

Constructor Detail

MessageFormat

public MessageFormat(String pattern)
Creates a new MessageFormat object with the specified pattern

Parameters: pattern The Pattern

MessageFormat

public MessageFormat(String pattern, Locale locale)
Creates a new MessageFormat object with the specified pattern

Parameters: pattern The Pattern locale The Locale to use

Since: 1.4

Method Detail

applyPattern

public void applyPattern(String newPattern)
Applies the specified pattern to this MessageFormat.

Parameters: newPattern The Pattern

clone

public Object clone()
Overrides Format.clone()

equals

public boolean equals(Object obj)
Overrides Format.equals(Object obj)

format

public static String format(String pattern, Object... arguments)
A convinience method to format patterns.

Parameters: pattern The pattern used when formatting. arguments The array containing the objects to be formatted.

format

public final StringBuffer format(Object[] arguments, StringBuffer appendBuf, FieldPosition fp)
Returns the pattern with the formatted objects.

Parameters: arguments The array containing the objects to be formatted. appendBuf The StringBuffer where the text is appened. fp A FieldPosition object (it is ignored).

format

public final StringBuffer format(Object objectArray, StringBuffer appendBuf, FieldPosition fpos)
Returns the pattern with the formatted objects. The first argument must be a array of Objects. This is equivalent to format((Object[]) objectArray, appendBuf, fpos)

Parameters: objectArray The object array to be formatted. appendBuf The StringBuffer where the text is appened. fpos A FieldPosition object (it is ignored).

formatToCharacterIterator

public AttributedCharacterIterator formatToCharacterIterator(Object arguments)
A convinience method to format patterns.

Parameters: arguments The array containing the objects to be formatted.

getFormats

public Format[] getFormats()
Returns an array with the Formats for the arguments.

getFormatsByArgumentIndex

public Format[] getFormatsByArgumentIndex()
Return the formatters used sorted by argument index. It uses the internal table to fill in this array: if a format has been set using setFormat or setFormatByArgumentIndex then it returns it at the right index. If not it uses the detected formatters during a format call. If nothing is known about that argument index it just puts null at that position. To get useful informations you may have to call format at least once.

Returns: an array of formatters sorted by argument index.

getLocale

public Locale getLocale()
Returns the locale.

hashCode

public int hashCode()
Overrides Format.hashCode()

parse

public Object[] parse(String sourceStr, ParsePosition pos)
Parse a string sourceStr against the pattern specified to the MessageFormat constructor.

Parameters: sourceStr the string to be parsed. pos the current parse position (and eventually the error position).

Returns: the array of parsed objects sorted according to their argument number in the pattern.

parse

public Object[] parse(String sourceStr)

parseObject

public Object parseObject(String sourceStr, ParsePosition pos)

setFormat

public void setFormat(int variableNum, Format newFormat)
Sets the format for the argument at an specified index.

Parameters: variableNum The index. newFormat The Format object.

setFormatByArgumentIndex

public void setFormatByArgumentIndex(int argumentIndex, Format newFormat)
Set the format to used using the argument index number.

Parameters: argumentIndex the argument index. newFormat the format to use for this argument.

setFormats

public void setFormats(Format[] newFormats)
Sets the formats for the arguments.

Parameters: newFormats An array of Format objects.

setFormatsByArgumentIndex

public void setFormatsByArgumentIndex(Format[] newFormats)
Set the format for argument using a specified array of formatters which is sorted according to the argument index. If the number of elements in the array is fewer than the number of arguments only the arguments specified by the array are touched.

Parameters: newFormats array containing the new formats to set.

Throws: NullPointerException if newFormats is null

setLocale

public void setLocale(Locale loc)
Sets the locale.

Parameters: loc A Locale

toPattern

public String toPattern()
Returns the pattern.