|
SLF4J API Version 1.4.3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.slf4j.helpers.MessageFormatter
public class MessageFormatter
Formats messages according to very simple substitution rules. Substitutions can be made 1, 2 or more arguments.
For example,
MessageFormatter.format("Hi {}.", "there");will return the string "Hi there.".
The {} pair is called the formatting anchor. It serves to designate the location where arguments need to be substituted within the message pattern.
In the rare case where you need to place the '{' or '}' in the message pattern itself but do not want them to be interpreted as a formatting anchors, you can espace the '{' character with '\', that is the backslash character. Only the '{' character should be escaped. There is no need to escape the '}' character. For example,
MessageFormatter.format("File name is \\{{}}.", "App folder.zip");will return the string "File name is {App folder.zip}.". See
format(String, Object)
, format(String, Object, Object)
and arrayFormat(String, Object[])
methods for more details.
Constructor Summary | |
---|---|
MessageFormatter()
|
Method Summary | |
---|---|
static String |
arrayFormat(String messagePattern,
Object[] argArray)
Same principle as the format(String, Object) and
format(String, Object, Object) methods except that
any number of arguments can be passed in an array. |
static String |
format(String messagePattern,
Object arg)
Performs single argument substitution for the 'messagePattern' passed as parameter. |
static String |
format(String messagePattern,
Object arg1,
Object arg2)
Performs a two argument substitution for the 'messagePattern' passed as parameter. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MessageFormatter()
Method Detail |
---|
public static String format(String messagePattern, Object arg)
For example,
MessageFormatter.format("Hi {}.", "there");will return the string "Hi there.".
messagePattern
- The message pattern which will be parsed and formattedargument
- The argument to be substituted in place of the formatting anchor
public static String format(String messagePattern, Object arg1, Object arg2)
For example,
MessageFormatter.format("Hi {}. My name is {}.", "Alice", "Bob");will return the string "Hi Alice. My name is Bob.".
messagePattern
- The message pattern which will be parsed and formattedarg1
- The argument to be substituted in place of the first formatting anchorarg2
- The argument to be substituted in place of the second formatting anchor
public static String arrayFormat(String messagePattern, Object[] argArray)
format(String, Object)
and
format(String, Object, Object)
methods except that
any number of arguments can be passed in an array.
messagePattern
- The message pattern which will be parsed and formattedargArray
- An array of arguments to be substituted in place of formatting anchors
|
SLF4J API Version 1.4.3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |