String formatting for ToStringBuilder. The main public interface is always via ToStringBuilder.
These classes are intended to be used as singletons. There is no need to instantiate a new style each time. A program will generally use one of the
predefined constants on this class. Alternatively, the StandardToStringStyle class can be used to set the individual settings. Thus most styles can
be achieved without subclassing.
If required, a subclass can override as many or as few of the methods as it requires. Each object type (from boolean to long to
Object to int[]) has its own methods to output it. Most have two versions, detail and summary.
For example, the detail version of the array based methods will output the whole array, whereas the summary method will just output the array length.
If you want to format the output of certain objects, such as dates, you must create a subclass and override a method.
public class MyStyle extends ToStringStyle {
protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
if (value instanceof Date) {
value = new SimpleDateFormat("yyyy-MM-dd").format(value);
}
buffer.append(value);
}
}
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class | ToStringStyle.
|
| private static class | ToStringStyle.
|
| private static class | ToStringStyle.
|
| private static class | ToStringStyle.
|
| private static class | ToStringStyle.
|
| private static class | ToStringStyle.
|
| Modifier and Type | Field and Description |
|---|---|
| private boolean | arrayContentDetail
The detail for array content. |
| private String | arrayEnd
The array end |
| private String | arraySeparator
The array separator |
| private String | arrayStart
The array start |
| private String | contentEnd
The content end |
| private String | contentStart
The content start |
| public static final ToStringStyle | DEFAULT_STYLE
The default toString style. |
| private boolean | defaultFullDetail
The value to use when fullDetail is |
| private String | fieldNameValueSeparator
The field name value separator |
| private String | fieldSeparator
The field separator |
| private boolean | fieldSeparatorAtEnd
Whether the field separator should be added after any other fields. |
| private boolean | fieldSeparatorAtStart
Whether the field separator should be added before any other fields. |
| public static final ToStringStyle | JSON_STYLE
The JSON toString style. |
| public static final ToStringStyle | MULTI_LINE_STYLE
The multi line toString style. |
| public static final ToStringStyle | NO_CLASS_NAME_STYLE
The no class name toString style. |
| public static final ToStringStyle | NO_FIELD_NAMES_STYLE
The no field names toString style. |
| private String | nullText
The |
| private static final ThreadLocal | REGISTRY
A registry of objects used by |
| private static final long | serialVersionUID
Serialization version ID. |
| public static final ToStringStyle | SHORT_PREFIX_STYLE
The short prefix toString style. |
| public static final ToStringStyle | SIMPLE_STYLE
The simple toString style. |
| private String | sizeEndText
The summary size text start |
| private String | sizeStartText
The summary size text start |
| private String | summaryObjectEndText
The summary object text start |
| private String | summaryObjectStartText
The summary object text start |
| private boolean | useClassName
Whether to use the class name, the default is |
| private boolean | useFieldNames
Whether to use the field names, the default is |
| private boolean | useIdentityHashCode
Whether to use the identity hash code, the default is |
| private boolean | useShortClassName
Whether to use short class names, the default is |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final boolean the value to add to the value)toString.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final boolean[] the array to add to the toString. array, final Boolean true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final byte the value to add to the value)toString.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final byte[] the array to add to the array, final Boolean toString.true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final char the value to add to the value)toString.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final char[] the array to add to the array, final Boolean toString.true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final double the value to add to the value)toString.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final double[] the array to add to the toString. array, final Boolean true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final float the value to add to the value)toString.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final float[] the array to add to the toString. array, final Boolean true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final int the value to add to the value)toString.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final int[] the array to add to the array, final Boolean toString.true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final long the value to add to the value)toString.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final long[] the array to add to the array, final Boolean toString.true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final Object the value to add to the value, final Boolean toString.true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final Object[] the array to add to the toString. array, final Boolean true for detail, false for summary info, null for style decides.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final short the value to add to the value)toString.Appends to the |
| public void | append(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName, final short[] the array to add to the array, final Boolean toString.true for detail, false for summary info, null for style decides.Appends to the |
| protected void | appendClassName(final StringBuffer
the buffer, final Object StringBuffer to populate.the object)Object whose name to output.Appends to the |
| protected void | appendContentEnd(final StringBuffer
the buffer)StringBuffer to populate.Appends to the |
| protected void | appendContentStart(final StringBuffer
the buffer)StringBuffer to populate.Appends to the |
| protected void | appendCyclicObject(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended fieldName, final Object the value to add to the value)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final boolean the value to add to the value)toString.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final boolean[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final byte the value to add to the value)toString.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final byte[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final char the value to add to the value)toString.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final char[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final Collection<?> coll)Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final double the value to add to the value)toString.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended fieldName, final double[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final float the value to add to the value)toString.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final float[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final int the value to add to the value)toString.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final int the array item index to add. i, final Object the array item to add. item)Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final int[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final long the value to add to the value)toString.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final long[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final Map<?, ?> map)Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final Object the value to add to the value)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final Object[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final short the value to add to the value)toString.Appends to the |
| protected void | appendDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final short[] the array to add to the array)toString, not null.Appends to the |
| public void | appendEnd(final StringBuffer
the buffer, final Object StringBuffer to populate.the object)Object to build a toString for.Appends to the |
| protected void | appendFieldEnd(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName)Appends to the |
| protected void | appendFieldSeparator(final StringBuffer
the buffer)StringBuffer to populate.Appends to the |
| protected void | appendFieldStart(final StringBuffer
the buffer, final String StringBuffer to populate.the field name. fieldName)Appends to the |
| protected void | appendIdentityHashCode(final StringBuffer
the buffer, final Object StringBuffer to populate.the object)Object whose id to output.Appends the |
| protected void | appendInternal(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final Object the value to add to the value, final boolean toString, not null.output detail or not. detail)Appends to the |
| protected void | appendNullText(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName)Appends to the |
| public void | appendStart(final StringBuffer
the buffer, final Object StringBuffer to populate.the object)Object to build a toString for.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final boolean[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final byte[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final char[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populatethe field name, typically not used as already appended fieldName, final double[] the array to add to the array)toString, not nullAppends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final float[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final int[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final long[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final Object the value to add to the value)toString, not null.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final Object[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendSummary(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final short[] the array to add to the array)toString, not null.Appends to the |
| protected void | appendSummarySize(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final int the size to append. size)Appends to the |
| public void | appendSuper(final StringBuffer
the buffer, final String StringBuffer to populate.the superToString)super.toString().Appends to the |
| public void | appendToString(final StringBuffer
the buffer, final String StringBuffer to populate.the additional toString)toString.Appends to the |
| protected String | |
| protected String | |
| protected String | |
| protected String | |
| protected String | |
| protected String | Returns: the current field name value separator text.Gets the field name value separator text. |
| protected String | |
| protected String | Returns: the current text to output when null found.Gets the text to output when |
| public static Map | Returns: Set the registry of objects being traversed.Gets the registry of objects being traversed by the |
| protected String | Returns: the short name.the cls)Class to get the short name of.Gets the short class name for a class. |
| protected String | Returns: the current end of size text.Gets the end text to output when a |
| protected String | Returns: the current start of size text.Gets the start text to output when a |
| protected String | Returns: the current end of summary text.Gets the end text to output when an |
| protected String | Returns: the current start of summary text.Gets the start text to output when an |
| protected boolean | Returns: the current array content detail setting.Gets whether to output array content detail. |
| protected boolean | Returns: the current defaultFullDetail flag.Gets whether to use full detail when the caller doesn't specify. |
| protected boolean | Returns: fieldSeparatorAtEnd flag.Gets whether the field separator should be added at the end of each buffer. |
| protected boolean | Returns: the fieldSeparatorAtStart flag.Gets whether the field separator should be added at the start of each buffer. |
| protected boolean | Returns: whether full detail is to be shown.the detail level requested. fullDetailRequest)Is this field to be output in full detail. |
| pack-priv static boolean | Returns: booleantrue if the registry contains the given object.The object to lookup in the registry. value)Tests whether the registry contains the given object. |
| protected boolean | |
| protected boolean | Returns: the current useFieldNames flag.Gets whether to use the field names passed in. |
| protected boolean | Returns: the current useIdentityHashCode flag.Gets whether to use the identity hash code. |
| protected boolean | Returns: the current useShortClassName flag.Gets whether to output short or long class names. |
| protected void | reflectionAppendArrayDetail(final StringBuffer
the buffer, final String StringBuffer to populate.the field name, typically not used as already appended. fieldName, final Object the array to add to the array)toString, not null.Appends to the |
| pack-priv static void | |
| protected void | removeLastFieldSeparator(final StringBuffer
the buffer)StringBuffer to populate.Remove the last field separator from the buffer. |
| protected void | setArrayContentDetail(final boolean
the new arrayContentDetail flag. arrayContentDetail)Sets whether to output array content detail. |
| protected void | |
| protected void | setArraySeparator(final String
the new array separator text. arraySeparator)Sets the array separator text. |
| protected void | |
| protected void | |
| protected void | |
| protected void | setDefaultFullDetail(final boolean
the new defaultFullDetail flag. defaultFullDetail)Sets whether to use full detail when the caller doesn't specify. |
| protected void | setFieldNameValueSeparator(final String
the new field name value separator text. fieldNameValueSeparator)Sets the field name value separator text. |
| protected void | setFieldSeparator(final String
the new field separator text. fieldSeparator)Sets the field separator text. |
| protected void | setFieldSeparatorAtEnd(final boolean
the fieldSeparatorAtEnd flag. fieldSeparatorAtEnd)Sets whether the field separator should be added at the end of each buffer. |
| protected void | setFieldSeparatorAtStart(final boolean
the fieldSeparatorAtStart flag. fieldSeparatorAtStart)Sets whether the field separator should be added at the start of each buffer. |
| protected void | setNullText(final String
the new text to output when null found. nullText)Sets the text to output when |
| protected void | setSizeEndText(final String
the new end of size text. sizeEndText)Sets the end text to output when a |
| protected void | setSizeStartText(final String
the new start of size text. sizeStartText)Sets the start text to output when a |
| protected void | setSummaryObjectEndText(final String
the new end of summary text. summaryObjectEndText)Sets the end text to output when an |
| protected void | setSummaryObjectStartText(final String
the new start of summary text. summaryObjectStartText)Sets the start text to output when an |
| protected void | setUseClassName(final boolean
the new useClassName flag. useClassName)Sets whether to use the class name. |
| protected void | setUseFieldNames(final boolean
the new useFieldNames flag. useFieldNames)Sets whether to use the field names passed in. |
| protected void | setUseIdentityHashCode(final boolean
the new useIdentityHashCode flag. useIdentityHashCode)Sets whether to use the identity hash code. |
| protected void | setUseShortClassName(final boolean
the new useShortClassName flag. useShortClassName)Sets whether to output short or long class names. |
| pack-priv static void |