Package org.slf4j.instrumentation
Class ToStringHelper
- java.lang.Object
-
- org.slf4j.instrumentation.ToStringHelper
-
public class ToStringHelper extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ARRAY_PREFIX
Prefix to use at the start of the representation.private static char
ARRAY_SUFFIX
Suffix to use at the end of the representation.private static char[]
ELEMENT_SEPARATOR
String separating each element when rendering an array.(package private) static java.util.Map<java.lang.Class<?>,java.lang.Object>
unrenderableClasses
unrenderableClasses is essentially a Set of Class objects which has for some reason failed to render properly when invoked through a toString method call.
-
Constructor Summary
Constructors Constructor Description ToStringHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
render(java.lang.Object o)
Returns o.toString() unless it throws an exception (which causes it to be stored in unrenderableClasses) or already was present in unrenderableClasses.private static java.lang.StringBuilder
renderArray(java.lang.Object o, java.lang.Class<?> objectClass)
renderArray returns an array similar to a List.
-
-
-
Field Detail
-
ARRAY_PREFIX
private static final java.lang.String ARRAY_PREFIX
Prefix to use at the start of the representation. Always used.- See Also:
- Constant Field Values
-
ARRAY_SUFFIX
private static final char ARRAY_SUFFIX
Suffix to use at the end of the representation. Always used.- See Also:
- Constant Field Values
-
ELEMENT_SEPARATOR
private static final char[] ELEMENT_SEPARATOR
String separating each element when rendering an array. To be compatible with lists comma-space is used.
-
unrenderableClasses
static final java.util.Map<java.lang.Class<?>,java.lang.Object> unrenderableClasses
unrenderableClasses is essentially a Set of Class objects which has for some reason failed to render properly when invoked through a toString method call. To avoid memory leaks a data structure using weak references is needed, but unfortunately the runtime library does not contain a WeakHashSet class, so the behavior is emulated with a WeakHashmap with the class as the key, and a Long containing the value of System.currentTimeMilis when an instance of the class failed to render.
-
-
Method Detail
-
render
public static java.lang.String render(java.lang.Object o)
Returns o.toString() unless it throws an exception (which causes it to be stored in unrenderableClasses) or already was present in unrenderableClasses. If so, the same string is returned as would have been returned by Object.toString(). Arrays get special treatment as they don't have usable toString methods.- Parameters:
o
- incoming object to render.- Returns:
-
renderArray
private static java.lang.StringBuilder renderArray(java.lang.Object o, java.lang.Class<?> objectClass)
renderArray returns an array similar to a List. If the array type is an object they are rendered with "render(object)" for each. If the array type is a primitive each element is added directly to the string buffer collecting the result.- Parameters:
o
-objectClass
-- Returns:
-
-