public final class Messages extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
format(String messageTemplate,
Object... args)
Formats a templated message inserting arguments.
|
static String |
format(String messageTemplate,
Object arg)
Formats a templated message inserting a single argument.
|
static Pair<String,Map<String,String>> |
formatWithAttributes(String messageTemplate,
Object... args)
Formats a templated message inserting named arguments.
|
public static String format(String messageTemplate, Object arg)
This method combines a template message with a single argument. It can be useful to delay string concatenation, which is sometimes a performance issue. The approach is similar to SLF4J MessageFormat, Guava Preconditions and String format().
The message template contains zero to many "{}" placeholders. The first placeholder is replaced by the string form of the argument. Subsequent placeholders are not replaced. If there is no placeholder, then the argument is appended to the end of the message. No attempt is made to format the argument.
This method is null tolerant to ensure that use in exception construction will not throw another exception, which might hide the intended exception.
messageTemplate - the message template with "{}" placeholders, null returns empty stringarg - the message argument, null treated as string "null"public static String format(String messageTemplate, Object... args)
This method combines a template message with a list of specific arguments. It can be useful to delay string concatenation, which is sometimes a performance issue. The approach is similar to SLF4J MessageFormat, Guava Preconditions and String format().
The message template contains zero to many "{}" placeholders. Each placeholder is replaced by the next available argument. If there are too few arguments, then the message will be left with placeholders. If there are too many arguments, then the excess arguments are appended to the end of the message. No attempt is made to format the arguments.
This method is null tolerant to ensure that use in exception construction will not throw another exception, which might hide the intended exception.
messageTemplate - the message template with "{}" placeholders, null returns empty stringargs - the message arguments, null treated as empty arraypublic static Pair<String,Map<String,String>> formatWithAttributes(String messageTemplate, Object... args)
A typical template would look like:
Messages.formatWithAttributes("Foo={foo}, Bar={}", "abc", 123)
This will return a Pair with a String and a Map.
The String will be the formatted message: "Foo=abc, Bar=123".
The Map will look like: {"foo": "123"}.
This method combines a template message with a list of specific arguments. It can be useful to delay string concatenation, which is sometimes a performance issue. The approach is similar to SLF4J MessageFormat, Guava Preconditions and String format().
The message template contains zero to many "{name}" placeholders. Each placeholder is replaced by the next available argument. If there are too few arguments, then the message will be left with placeholders. If there are too many arguments, then the excess arguments are appended to the message. No attempt is made to format the arguments.
This method is null tolerant to ensure that use in exception construction will not throw another exception, which might hide the intended exception.
messageTemplate - the message template with "{}" placeholders, null returns empty stringargs - the message arguments, null treated as empty arrayCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.