Class MessageFormats
See also java.text.MessageFormat.
- Author:
- tomyeh
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe name info returned byparseByName(java.lang.String)). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final StringBufferformat(StringBuffer result, String pattern, Object[] args) Creates a MessageFormat with the given pattern and uses it to format the given arguments, by use of StringBuffer andLocales.getCurrent().static final StringBufferformat(StringBuffer result, String pattern, Object[] args, Locale locale) Creates a MessageFormat with the given pattern and uses it to format the given arguments, by use of StringBuffer.static final StringCreates a MessageFormat with the given pattern and uses it to format the given arguments, by use ofLocales.getCurrent().static final StringCreates a MessageFormat with the given pattern and uses it to format the given arguments.static final StringformatByName(String pattern, Map<String, ?> mapping) Formats a pattern by substituting names with values found in the giving map, by use ofLocales.getCurrent().static final StringformatByName(String pattern, Map<String, ?> mapping, Locale locale) Formats a pattern by substituting names, enclosing with {}, with values found in the giving map.static final MessageFormats.NameInfoparseByName(String pattern) Parses a pattern and converts it to the format of java.text.MessageFormat.
-
Constructor Details
-
MessageFormats
public MessageFormats()
-
-
Method Details
-
format
Creates a MessageFormat with the given pattern and uses it to format the given arguments.An extension to java.text.MessageFormat.format by allowing to specify a Locale.
- Parameters:
locale- the locale; null forLocales.getCurrent()
-
format
Creates a MessageFormat with the given pattern and uses it to format the given arguments, by use ofLocales.getCurrent().Note: java.text.MessageFormat.format uses Locale.getDefault, which might not be correct in a multi-user environment.
-
format
public static final StringBuffer format(StringBuffer result, String pattern, Object[] args, Locale locale) Creates a MessageFormat with the given pattern and uses it to format the given arguments, by use of StringBuffer.If you want to concatenate a sequence of formated string, use this method.
-
format
Creates a MessageFormat with the given pattern and uses it to format the given arguments, by use of StringBuffer andLocales.getCurrent(). -
parseByName
Parses a pattern and converts it to the format of java.text.MessageFormat. Names are the first element of a substring enclosing with {} in the pattern.Example: "{a} is {b,number} of {a}" will return
new NameInfo("{0} is {1,number} of {0}", {"a", "b"}).- See Also:
-
formatByName
Formats a pattern by substituting names, enclosing with {}, with values found in the giving map.This is an extension to java.text.MessageFormat. The only difference is that this method use arbitrary name instead of a number. For example, it use {name} instead of {0}. The quotation rule and formating pattern are the same as java.text.MessageFormat. Example, {var,number,$'#',###}.
It actually uses
parseByName(java.lang.String)to convert names to numbers, and then passes to java.text.MessageFormat.- Parameters:
locale- the locale; null forLocales.getCurrent()- Throws:
IllegalArgumentException- if the pattern is invalid- See Also:
-
formatByName
Formats a pattern by substituting names with values found in the giving map, by use ofLocales.getCurrent().- See Also:
-