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, returning the implied attribute map.
|
static String |
mergeTemplateLocations(String location1,
String location2,
int message1Length)
Merges two template locations.
|
static String |
recreateTemplate(String message,
String templateLocation)
Recreates the template from the message and templateLocation code.
|
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": "abc"}.
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.
If the template contains a named placeholder, then the output will contain a populated attribute map for all placeholders including those without names. The output will include a 'templateLocation' attribute identifying the location of the named placeholders.
messageTemplate - the message template with "{}" and "{name}" placeholders, null returns empty stringargs - the message arguments, null treated as empty arraypublic static String recreateTemplate(String message, String templateLocation)
This method returns the input message if the input is not valid.
message - the message, null toleranttemplateLocation - the template location, null tolerantpublic static String mergeTemplateLocations(String location1, String location2, int message1Length)
This takes two template locations and the length of the first message and returns the combined template.
location1 - the first location, null tolerantlocation2 - the second location, null tolerantmessage1Length - the length of the formatted message associated with location1Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.