public class ParameterizedMessage extends Objectimplements Message
This class was originally written for Lilith by Joern Huxhorn where it is licensed under the LGPL. It has been relicensed here with his permission providing that this attribution remain.
| Modifier and Type | Field and Description |
|---|---|
static String |
ERROR_MSG_SEPARATOR
Separator for error messages.
|
static String |
ERROR_PREFIX
Prefix for errors.
|
static String |
ERROR_SEPARATOR
Separator for errors.
|
static String |
ERROR_SUFFIX
Suffix for errors.
|
static String |
RECURSION_PREFIX
Prefix for recursion.
|
static String |
RECURSION_SUFFIX
Suffix for recursion.
|
| Constructor and Description |
|---|
ParameterizedMessage(String
Constructor with a pattern and a single parameter.
|
ParameterizedMessage(String
Constructs a ParameterizedMessage which contains the arguments converted to String as well as an optional Throwable.
|
ParameterizedMessage(String
Creates a parameterized message.
|
ParameterizedMessage(String
Constructor with a pattern and two parameters.
|
ParameterizedMessage(String
Creates a parameterized message.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
countArgumentPlaceholders(String
Counts the number of unescaped placeholders in the given messagePattern.
|
static String |
deepToString(Object
This method performs a deep toString of the given Object.
|
boolean |
equals(Object
|
static String |
format(String
Replace placeholders in the given messagePattern with arguments.
|
protected String |
formatMessage(String
|
String |
getFormat()
Returns the message pattern.
|
String |
getFormattedMessage()
Returns the formatted message.
|
Object |
getParameters()
Returns the message parameters.
|
Throwable |
getThrowable()
Returns the Throwable that was given as the last argument, if any.
|
int |
hashCode()
|
static String |
identityToString(Object
This method returns the same as if Object.toString() would not have been overridden in obj.
|
String |
toString()
|
public static final StringRECURSION_PREFIX
public static final StringRECURSION_SUFFIX
public static final StringERROR_PREFIX
public static final StringERROR_SEPARATOR
public static final StringERROR_MSG_SEPARATOR
public static final StringERROR_SUFFIX
public ParameterizedMessage(StringmessagePattern, String [] stringArgs, Throwable throwable)
messagePattern - The message "format" string. This will be a String containing "{}" placeholders where parameters should be substituted.
stringArgs - The arguments for substitution.
throwable - A Throwable.
public ParameterizedMessage(StringmessagePattern, Object [] objectArgs, Throwable throwable)
messagePattern - The message "format" string. This will be a String containing "{}" placeholders where parameters should be substituted.
objectArgs - The arguments for substitution.
throwable - A Throwable.
public ParameterizedMessage(StringmessagePattern, Object [] arguments)
If the last argument is a Throwable and is NOT used up by a placeholder in the message pattern it is returned in getThrowable() and won't be contained in the created String[]. If it is used up getThrowable() will return null even if the last argument was a Throwable!
messagePattern - the message pattern that to be checked for placeholders.
arguments - the argument array to be converted.
public ParameterizedMessage(StringmessagePattern, Object arg)
messagePattern - The message pattern.
arg - The parameter.
public StringgetFormattedMessage()
getFormattedMessage in interface
Message
public StringgetFormat()
public Object[] getParameters()
getParameters in interface
Message
public ThrowablegetThrowable()
getThrowable in interface
Message
public boolean equals(Objecto)
public int hashCode()
public static Stringformat(String messagePattern, Object [] arguments)
messagePattern - the message pattern containing placeholders.
arguments - the arguments to be used to replace placeholders.
public static int countArgumentPlaceholders(StringmessagePattern)
messagePattern - the message pattern to be analyzed.
public static StringdeepToString(Object o)
It should be noted that neither AbstractMap.toString() nor AbstractCollection.toString() implement such a behavior. They only check if the container is directly contained in itself, but not if a contained container contains the original one. Because of that, Arrays.toString(Object[]) isn't safe either. Confusing? Just read the last paragraph again and check the respective toString() implementation.
This means, in effect, that logging would produce a usable output even if an ordinary System.out.println(o) would produce a relatively hard-to-debug StackOverflowError.
o - The object.
public static StringidentityToString(Object obj)
Note that this isn't 100% secure as collisions can always happen with hash codes.
Copied from Object.hashCode():
As much as is reasonably practical, the hashCode method defined by class
Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.)
obj - the Object that is to be converted into an identity string.
public StringtoString()