On this page

ToStringStyle

public abstract class org.apache.commons.lang3.builder.ToStringStyle implements Serializable[source]

Controls 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);
    }
}
Since:

1.0

Constructors

ToStringStyle()

Constructs a new instance.

protected ToStringStyle()[source]

Constructs a new instance.

Fields and constants

static final ToStringStyle

DEFAULT_STYLE

The default toString style.

static final ToStringStyle

JSON_STYLE

The JSON toString style.

static final ToStringStyle

MULTI_LINE_STYLE

The multi line toString style.

static final ToStringStyle

NO_CLASS_NAME_STYLE

The no class name toString style.

static final ToStringStyle

NO_FIELD_NAMES_STYLE

The no field names toString style.

static final ToStringStyle

SHORT_PREFIX_STYLE

The short prefix toString style.

static final ToStringStyle

SIMPLE_STYLE

The simple toString style.

public static final ToStringStyle DEFAULT_STYLE[source]

The default toString style. Using the Person example from ToStringBuilder, the output would look like this:

Person@182f0db[name=John Doe,age=33,smoker=false]
public static final ToStringStyle JSON_STYLE[source]

The JSON toString style. Using the Person example from ToStringBuilder, the output would look like this:

{"name": "John Doe", "age": 33, "smoker": true}

Note: Since field names are mandatory in JSON, this ToStringStyle will throw an UnsupportedOperationException if no field name is passed in while appending. Furthermore This ToStringStyle will only generate valid JSON if referenced objects also produce JSON when calling toString() on them.

Since:

3.4

See also:

json.org

public static final ToStringStyle MULTI_LINE_STYLE[source]

The multi line toString style. Using the Person example from ToStringBuilder, the output would look like this:

Person@182f0db[
  name=John Doe
  age=33
  smoker=false
]
public static final ToStringStyle NO_CLASS_NAME_STYLE[source]

The no class name toString style. Using the Person example from ToStringBuilder, the output would look like this:

[name=John Doe,age=33,smoker=false]
Since:

3.4

public static final ToStringStyle NO_FIELD_NAMES_STYLE[source]

The no field names toString style. Using the Person example from ToStringBuilder, the output would look like this:

Person@182f0db[John Doe,33,false]
public static final ToStringStyle SHORT_PREFIX_STYLE[source]

The short prefix toString style. Using the Person example from ToStringBuilder, the output would look like this:

Person[name=John Doe,age=33,smoker=false]
Since:

2.1

public static final ToStringStyle SIMPLE_STYLE[source]

The simple toString style. Using the Person example from ToStringBuilder, the output would look like this:

John Doe,33,false

Methods

void

append(StringBuffer buffer, String fieldName, boolean value)

Appends to the toString a boolean value.

void

append(StringBuffer buffer, String fieldName, boolean[] array, Boolean fullDetail)

Appends to the toString a boolean array.

void

append(StringBuffer buffer, String fieldName, byte value)

Appends to the toString a byte value.

void

append(StringBuffer buffer, String fieldName, byte[] array, Boolean fullDetail)

Appends to the toString a byte array.

void

append(StringBuffer buffer, String fieldName, char value)

Appends to the toString a char value.

void

append(StringBuffer buffer, String fieldName, char[] array, Boolean fullDetail)

Appends to the toString a char array.

void

append(StringBuffer buffer, String fieldName, double value)

Appends to the toString a double value.

void

append(StringBuffer buffer, String fieldName, double[] array, Boolean fullDetail)

Appends to the toString a double array.

void

append(StringBuffer buffer, String fieldName, float value)

Appends to the toString a float value.

void

append(StringBuffer buffer, String fieldName, float[] array, Boolean fullDetail)

Appends to the toString a float array.

void

append(StringBuffer buffer, String fieldName, int value)

Appends to the toString an int value.

void

append(StringBuffer buffer, String fieldName, int[] array, Boolean fullDetail)

Appends to the toString an int array.

void

append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail)

Appends to the toString an Object value, printing the full toString of the Object passed in.

void

append(StringBuffer buffer, String fieldName, Object[] array, Boolean fullDetail)

Appends to the toString an Object array.

void

append(StringBuffer buffer, String fieldName, long value)

Appends to the toString a long value.

void

append(StringBuffer buffer, String fieldName, long[] array, Boolean fullDetail)

Appends to the toString a long array.

void

append(StringBuffer buffer, String fieldName, short value)

Appends to the toString a short value.

void

append(StringBuffer buffer, String fieldName, short[] array, Boolean fullDetail)

Appends to the toString a short array.

protected void

appendClassName(StringBuffer buffer, Object object)

Appends to the toString the class name.

protected void

appendContentEnd(StringBuffer buffer)

Appends to the toString the content end.

protected void

appendContentStart(StringBuffer buffer)

Appends to the toString the content start.

protected void

appendCyclicObject(StringBuffer buffer, String fieldName, Object value)

Appends to the toString an Object value that has been detected to participate in a cycle.

protected void

appendDetail(StringBuffer buffer, String fieldName, boolean value)

Appends to the toString a boolean value.

protected void

appendDetail(StringBuffer buffer, String fieldName, boolean[] array)

Appends to the toString the detail of a boolean array.

protected void

appendDetail(StringBuffer buffer, String fieldName, byte value)

Appends to the toString a byte value.

protected void

appendDetail(StringBuffer buffer, String fieldName, byte[] array)

Appends to the toString the detail of a byte array.

protected void

appendDetail(StringBuffer buffer, String fieldName, char value)

Appends to the toString a char value.

protected void

appendDetail(StringBuffer buffer, String fieldName, char[] array)

Appends to the toString the detail of a char array.

protected void

appendDetail(StringBuffer buffer, String fieldName, double value)

Appends to the toString a double value.

protected void

appendDetail(StringBuffer buffer, String fieldName, double[] array)

Appends to the toString the detail of a double array.

protected void

appendDetail(StringBuffer buffer, String fieldName, float value)

Appends to the toString a float value.

protected void

appendDetail(StringBuffer buffer, String fieldName, float[] array)

Appends to the toString the detail of a float array.

protected void

appendDetail(StringBuffer buffer, String fieldName, int value)

Appends to the toString an int value.

protected void

appendDetail(StringBuffer buffer, String fieldName, int i, Object item)

Appends to the toString the detail of an Object array item.

protected void

appendDetail(StringBuffer buffer, String fieldName, int[] array)

Appends to the toString the detail of an int array.

protected void

appendDetail(StringBuffer buffer, String fieldName, Object value)

Appends to the toString an Object value, printing the full detail of the Object.

protected void

appendDetail(StringBuffer buffer, String fieldName, Object[] array)

Appends to the toString the detail of an Object array.

protected void

appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll)

Appends to the toString a Collection.

protected void

appendDetail(StringBuffer buffer, String fieldName, Map<?, ?> map)

Appends to the toString a Map.

protected void

appendDetail(StringBuffer buffer, String fieldName, long value)

Appends to the toString a long value.

protected void

appendDetail(StringBuffer buffer, String fieldName, long[] array)

Appends to the toString the detail of a long array.

protected void

appendDetail(StringBuffer buffer, String fieldName, short value)

Appends to the toString a short value.

protected void

appendDetail(StringBuffer buffer, String fieldName, short[] array)

Appends to the toString the detail of a short array.

void

appendEnd(StringBuffer buffer, Object object)

Appends to the toString the end of data indicator.

protected void

appendFieldEnd(StringBuffer buffer, String fieldName)

Appends to the toString the field end.

protected void

appendFieldSeparator(StringBuffer buffer)

Appends to the toString the field separator.

protected void

appendFieldStart(StringBuffer buffer, String fieldName)

Appends to the toString the field start.

protected void

appendIdentityHashCode(StringBuffer buffer, Object object)

Appends the System.identityHashCode(java.lang.Object).

protected void

appendInternal(StringBuffer buffer, String fieldName, Object value, boolean detail)

Appends to the toString an Object, correctly interpreting its type.

protected void

appendNullText(StringBuffer buffer, String fieldName)

Appends to the toString an indicator for null.

void

appendStart(StringBuffer buffer, Object object)

Appends to the toString the start of data indicator.

protected void

appendSummary(StringBuffer buffer, String fieldName, boolean[] array)

Appends to the toString a summary of a boolean array.

protected void

appendSummary(StringBuffer buffer, String fieldName, byte[] array)

Appends to the toString a summary of a byte array.

protected void

appendSummary(StringBuffer buffer, String fieldName, char[] array)

Appends to the toString a summary of a char array.

protected void

appendSummary(StringBuffer buffer, String fieldName, double[] array)

Appends to the toString a summary of a double array.

protected void

appendSummary(StringBuffer buffer, String fieldName, float[] array)

Appends to the toString a summary of a float array.

protected void

appendSummary(StringBuffer buffer, String fieldName, int[] array)

Appends to the toString a summary of an int array.

protected void

appendSummary(StringBuffer buffer, String fieldName, Object value)

Appends to the toString an Object value, printing a summary of the Object.

protected void

appendSummary(StringBuffer buffer, String fieldName, Object[] array)

Appends to the toString a summary of an Object array.

protected void

appendSummary(StringBuffer buffer, String fieldName, long[] array)

Appends to the toString a summary of a long array.

protected void

appendSummary(StringBuffer buffer, String fieldName, short[] array)

Appends to the toString a summary of a short array.

protected void

appendSummarySize(StringBuffer buffer, String fieldName, int size)

Appends to the toString a size summary.

void

appendSuper(StringBuffer buffer, String superToString)

Appends to the toString the superclass toString.

void

appendToString(StringBuffer buffer, String toString)

Appends to the toString another toString.

protected String

getArrayEnd()

Gets the array end text.

protected String

getArraySeparator()

Gets the array separator text.

protected String

getArrayStart()

Gets the array start text.

protected String

getContentEnd()

Gets the content end text.

protected String

getContentStart()

Gets the content start text.

protected String

getFieldNameValueSeparator()

Gets the field name value separator text.

protected String

getFieldSeparator()

Gets the field separator text.

protected String

getNullText()

Gets the text to output when null found.

static Map<Object, Object>

getRegistry()

Gets the registry of objects being traversed by the reflectionToString methods in the current thread.

protected String

getShortClassName(Class<?> cls)

Gets the short class name for a class.

protected String

getSizeEndText()

Gets the end text to output when a Collection, Map or array size is output.

protected String

getSizeStartText()

Gets the start text to output when a Collection, Map or array size is output.

protected String

getSummaryObjectEndText()

Gets the end text to output when an Object is output in summary mode.

protected String

getSummaryObjectStartText()

Gets the start text to output when an Object is output in summary mode.

protected boolean

isArrayContentDetail()

Tests whether to output array content detail.

protected boolean

isDefaultFullDetail()

Tests whether full detail is used when the caller does not specify a detail level.

protected boolean

isFieldSeparatorAtEnd()

Tests whether the field separator should be added at the end of each buffer.

protected boolean

isFieldSeparatorAtStart()

Tests whether the field separator should be added at the start of each buffer.

protected boolean

isFullDetail(Boolean fullDetailRequest)

Tests whether this field should be output in full detail.

protected boolean

isUseClassName()

Tests whether to use the class name.

protected boolean

isUseFieldNames()

Tests whether to use the field names passed in.

protected boolean

isUseIdentityHashCode()

Tests whether to use the identity hash code.

protected boolean

isUseShortClassName()

Tests whether short class names should be output.

protected void

reflectionAppendArrayDetail(StringBuffer buffer, String fieldName, Object array)

Appends to the toString the detail of an array type.

protected void

removeLastFieldSeparator(StringBuffer buffer)

Remove the last field separator from the buffer.

protected void

setArrayContentDetail(boolean arrayContentDetail)

Sets whether to output array content detail.

protected void

setArrayEnd(String arrayEnd)

Sets the array end text.

protected void

setArraySeparator(String arraySeparator)

Sets the array separator text.

protected void

setArrayStart(String arrayStart)

Sets the array start text.

protected void

setContentEnd(String contentEnd)

Sets the content end text.

protected void

setContentStart(String contentStart)

Sets the content start text.

protected void

setDefaultFullDetail(boolean defaultFullDetail)

Sets whether to use full detail when the caller doesn't specify.

protected void

setFieldNameValueSeparator(String fieldNameValueSeparator)

Sets the field name value separator text.

protected void

setFieldSeparator(String fieldSeparator)

Sets the field separator text.

protected void

setFieldSeparatorAtEnd(boolean fieldSeparatorAtEnd)

Sets whether the field separator should be added at the end of each buffer.

protected void

setFieldSeparatorAtStart(boolean fieldSeparatorAtStart)

Sets whether the field separator should be added at the start of each buffer.

protected void

setNullText(String nullText)

Sets the text to output when null found.

protected void

setSizeEndText(String sizeEndText)

Sets the end text to output when a Collection, Map or array size is output.

protected void

setSizeStartText(String sizeStartText)

Sets the start text to output when a Collection, Map or array size is output.

protected void

setSummaryObjectEndText(String summaryObjectEndText)

Sets the end text to output when an Object is output in summary mode.

protected void

setSummaryObjectStartText(String summaryObjectStartText)

Sets the start text to output when an Object is output in summary mode.

protected void

setUseClassName(boolean useClassName)

Sets whether to use the class name.

protected void

setUseFieldNames(boolean useFieldNames)

Sets whether to use the field names passed in.

protected void

setUseIdentityHashCode(boolean useIdentityHashCode)

Sets whether to use the identity hash code.

protected void

setUseShortClassName(boolean useShortClassName)

Sets whether to output short or long class names.

public void append(StringBuffer buffer, String fieldName, boolean value)[source]

Appends to the toString a boolean value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

public void append(StringBuffer buffer, String fieldName, boolean[] array, Boolean fullDetail)[source]

Appends to the toString a boolean array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, byte value)[source]

Appends to the toString a byte value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

public void append(StringBuffer buffer, String fieldName, byte[] array, Boolean fullDetail)[source]

Appends to the toString a byte array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, char value)[source]

Appends to the toString a char value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

public void append(StringBuffer buffer, String fieldName, char[] array, Boolean fullDetail)[source]

Appends to the toString a char array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, double value)[source]

Appends to the toString a double value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

public void append(StringBuffer buffer, String fieldName, double[] array, Boolean fullDetail)[source]

Appends to the toString a double array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, float value)[source]

Appends to the toString a float value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

public void append(StringBuffer buffer, String fieldName, float[] array, Boolean fullDetail)[source]

Appends to the toString a float array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, int value)[source]

Appends to the toString an int value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

public void append(StringBuffer buffer, String fieldName, int[] array, Boolean fullDetail)[source]

Appends to the toString an int array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail)[source]

Appends to the toString an Object value, printing the full toString of the Object passed in.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, Object[] array, Boolean fullDetail)[source]

Appends to the toString an Object array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, long value)[source]

Appends to the toString a long value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

public void append(StringBuffer buffer, String fieldName, long[] array, Boolean fullDetail)[source]

Appends to the toString a long array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

public void append(StringBuffer buffer, String fieldName, short value)[source]

Appends to the toString a short value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • value – The value to add to the toString.

public void append(StringBuffer buffer, String fieldName, short[] array, Boolean fullDetail)[source]

Appends to the toString a short array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

  • array – The array to add to the toString.

  • fullDetail – true for detail, false for summary info, null for style decides.

protected void appendClassName(StringBuffer buffer, Object object)[source]

Appends to the toString the class name.

Parameters:
protected void appendContentEnd(StringBuffer buffer)[source]

Appends to the toString the content end.

Parameters:

buffer – The StringBuffer to populate.

protected void appendContentStart(StringBuffer buffer)[source]

Appends to the toString the content start.

Parameters:

buffer – The StringBuffer to populate.

protected void appendCyclicObject(StringBuffer buffer, String fieldName, Object value)[source]

Appends to the toString an Object value that has been detected to participate in a cycle. This implementation will print the standard string value of the value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended

  • value – The value to add to the toString, not null.

Since:

2.2

protected void appendDetail(StringBuffer buffer, String fieldName, boolean value)[source]

Appends to the toString a boolean value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString.

protected void appendDetail(StringBuffer buffer, String fieldName, boolean[] array)[source]

Appends to the toString the detail of a boolean array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, byte value)[source]

Appends to the toString a byte value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString.

protected void appendDetail(StringBuffer buffer, String fieldName, byte[] array)[source]

Appends to the toString the detail of a byte array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, char value)[source]

Appends to the toString a char value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString.

protected void appendDetail(StringBuffer buffer, String fieldName, char[] array)[source]

Appends to the toString the detail of a char array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, double value)[source]

Appends to the toString a double value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString.

protected void appendDetail(StringBuffer buffer, String fieldName, double[] array)[source]

Appends to the toString the detail of a double array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended

  • array – The array to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, float value)[source]

Appends to the toString a float value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString.

protected void appendDetail(StringBuffer buffer, String fieldName, float[] array)[source]

Appends to the toString the detail of a float array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, int value)[source]

Appends to the toString an int value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString.

protected void appendDetail(StringBuffer buffer, String fieldName, int i, Object item)[source]

Appends to the toString the detail of an Object array item.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • i – The array item index to add.

  • item – The array item to add.

Since:

3.11

protected void appendDetail(StringBuffer buffer, String fieldName, int[] array)[source]

Appends to the toString the detail of an int array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, Object value)[source]

Appends to the toString an Object value, printing the full detail of the Object.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, Object[] array)[source]

Appends to the toString the detail of an Object array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll)[source]

Appends to the toString a Collection.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • coll – The Collection to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, Map<?, ?> map)[source]

Appends to the toString a Map.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • map – The Map to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, long value)[source]

Appends to the toString a long value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString.

protected void appendDetail(StringBuffer buffer, String fieldName, long[] array)[source]

Appends to the toString the detail of a long array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendDetail(StringBuffer buffer, String fieldName, short value)[source]

Appends to the toString a short value.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString.

protected void appendDetail(StringBuffer buffer, String fieldName, short[] array)[source]

Appends to the toString the detail of a short array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

public void appendEnd(StringBuffer buffer, Object object)[source]

Appends to the toString the end of data indicator.

Parameters:
protected void appendFieldEnd(StringBuffer buffer, String fieldName)[source]

Appends to the toString the field end.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

protected void appendFieldSeparator(StringBuffer buffer)[source]

Appends to the toString the field separator.

Parameters:

buffer – The StringBuffer to populate.

protected void appendFieldStart(StringBuffer buffer, String fieldName)[source]

Appends to the toString the field start.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name.

protected void appendIdentityHashCode(StringBuffer buffer, Object object)[source]

Appends the System.identityHashCode(java.lang.Object).

Parameters:
protected void appendInternal(StringBuffer buffer, String fieldName, Object value, boolean detail)[source]

Appends to the toString an Object, correctly interpreting its type.

This method performs the main lookup by Class type to correctly route arrays, Collections, Maps and Objects to the appropriate method.

Either detail or summary views can be specified.

If a cycle is detected, an object will be appended with the Object.toString() format.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString, not null.

  • detail – output detail or not.

protected void appendNullText(StringBuffer buffer, String fieldName)[source]

Appends to the toString an indicator for null.

The default indicator is "<null>".

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

public void appendStart(StringBuffer buffer, Object object)[source]

Appends to the toString the start of data indicator.

Parameters:
protected void appendSummary(StringBuffer buffer, String fieldName, boolean[] array)[source]

Appends to the toString a summary of a boolean array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendSummary(StringBuffer buffer, String fieldName, byte[] array)[source]

Appends to the toString a summary of a byte array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendSummary(StringBuffer buffer, String fieldName, char[] array)[source]

Appends to the toString a summary of a char array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendSummary(StringBuffer buffer, String fieldName, double[] array)[source]

Appends to the toString a summary of a double array.

Parameters:
  • buffer – The StringBuffer to populate

  • fieldName – The field name, typically not used as already appended

  • array – The array to add to the toString, not null

protected void appendSummary(StringBuffer buffer, String fieldName, float[] array)[source]

Appends to the toString a summary of a float array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendSummary(StringBuffer buffer, String fieldName, int[] array)[source]

Appends to the toString a summary of an int array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendSummary(StringBuffer buffer, String fieldName, Object value)[source]

Appends to the toString an Object value, printing a summary of the Object.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • value – The value to add to the toString, not null.

protected void appendSummary(StringBuffer buffer, String fieldName, Object[] array)[source]

Appends to the toString a summary of an Object array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendSummary(StringBuffer buffer, String fieldName, long[] array)[source]

Appends to the toString a summary of a long array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendSummary(StringBuffer buffer, String fieldName, short[] array)[source]

Appends to the toString a summary of a short array.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

protected void appendSummarySize(StringBuffer buffer, String fieldName, int size)[source]

Appends to the toString a size summary.

The size summary is used to summarize the contents of Collections, Maps and arrays.

The output consists of a prefix, the passed in size and a suffix.

The default format is "<size=n>".

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • size – The size to append.

public void appendSuper(StringBuffer buffer, String superToString)[source]

Appends to the toString the superclass toString.

NOTE: It assumes that the toString has been created from the same ToStringStyle.

A null superToString is ignored.

Parameters:
  • buffer – The StringBuffer to populate.

  • superToString – The super.toString().

Since:

2.0

public void appendToString(StringBuffer buffer, String toString)[source]

Appends to the toString another toString.

NOTE: It assumes that the toString has been created from the same ToStringStyle.

A null toString is ignored.

Parameters:
  • buffer – The StringBuffer to populate.

  • toString – The additional toString.

Since:

2.0

protected String getArrayEnd()[source]

Gets the array end text.

Returns:

The current array end text.

protected String getArraySeparator()[source]

Gets the array separator text.

Returns:

The current array separator text.

protected String getArrayStart()[source]

Gets the array start text.

Returns:

The current array start text.

protected String getContentEnd()[source]

Gets the content end text.

Returns:

The current content end text.

protected String getContentStart()[source]

Gets the content start text.

Returns:

The current content start text.

protected String getFieldNameValueSeparator()[source]

Gets the field name value separator text.

Returns:

The current field name value separator text.

protected String getFieldSeparator()[source]

Gets the field separator text.

Returns:

The current field separator text.

protected String getNullText()[source]

Gets the text to output when null found.

Returns:

The current text to output when null found.

public static Map<Object, Object> getRegistry()[source]

Gets the registry of objects being traversed by the reflectionToString methods in the current thread.

Returns:

Set the registry of objects being traversed.

protected String getShortClassName(Class<?> cls)[source]

Gets the short class name for a class.

The short class name is the class name excluding the package name.

Parameters:

cls – The Class to get the short name of.

Returns:

The short name.

protected String getSizeEndText()[source]

Gets the end text to output when a Collection, Map or array size is output.

This is output after the size value.

Returns:

The current end of size text.

protected String getSizeStartText()[source]

Gets the start text to output when a Collection, Map or array size is output.

This is output before the size value.

Returns:

The current start of size text.

protected String getSummaryObjectEndText()[source]

Gets the end text to output when an Object is output in summary mode.

This is output after the size value.

Returns:

The current end of summary text.

protected String getSummaryObjectStartText()[source]

Gets the start text to output when an Object is output in summary mode.

This is output before the size value.

Returns:

The current start of summary text.

protected boolean isArrayContentDetail()[source]

Tests whether to output array content detail.

Returns:

The current array content detail setting.

protected boolean isDefaultFullDetail()[source]

Tests whether full detail is used when the caller does not specify a detail level.

Returns:

The current defaultFullDetail flag.

protected boolean isFieldSeparatorAtEnd()[source]

Tests whether the field separator should be added at the end of each buffer.

Returns:

fieldSeparatorAtEnd flag.

Since:

2.0

protected boolean isFieldSeparatorAtStart()[source]

Tests whether the field separator should be added at the start of each buffer.

Returns:

The fieldSeparatorAtStart flag.

Since:

2.0

protected boolean isFullDetail(Boolean fullDetailRequest)[source]

Tests whether this field should be output in full detail.

This method converts a detail request into a detail level. The calling code may request full detail (true), but a subclass might ignore that and always return false. The calling code may pass in null indicating that it doesn't care about the detail level. In this case the default detail level is used.

Parameters:

fullDetailRequest – The detail level requested.

Returns:

whether full detail is to be shown.

protected boolean isUseClassName()[source]

Tests whether to use the class name.

Returns:

The current useClassName flag.

protected boolean isUseFieldNames()[source]

Tests whether to use the field names passed in.

Returns:

The current useFieldNames flag.

protected boolean isUseIdentityHashCode()[source]

Tests whether to use the identity hash code.

Returns:

The current useIdentityHashCode flag.

protected boolean isUseShortClassName()[source]

Tests whether short class names should be output.

Returns:

The current useShortClassName flag.

Since:

2.0

protected void reflectionAppendArrayDetail(StringBuffer buffer, String fieldName, Object array)[source]

Appends to the toString the detail of an array type.

Parameters:
  • buffer – The StringBuffer to populate.

  • fieldName – The field name, typically not used as already appended.

  • array – The array to add to the toString, not null.

Since:

2.0

protected void removeLastFieldSeparator(StringBuffer buffer)[source]

Remove the last field separator from the buffer.

Parameters:

buffer – The StringBuffer to populate.

Since:

2.0

protected void setArrayContentDetail(boolean arrayContentDetail)[source]

Sets whether to output array content detail.

Parameters:

arrayContentDetail – The new arrayContentDetail flag.

protected void setArrayEnd(String arrayEnd)[source]

Sets the array end text.

null is accepted, but will be converted to an empty String.

Parameters:

arrayEnd – The new array end text.

protected void setArraySeparator(String arraySeparator)[source]

Sets the array separator text.

null is accepted, but will be converted to an empty String.

Parameters:

arraySeparator – The new array separator text.

protected void setArrayStart(String arrayStart)[source]

Sets the array start text.

null is accepted, but will be converted to an empty String.

Parameters:

arrayStart – The new array start text.

protected void setContentEnd(String contentEnd)[source]

Sets the content end text.

null is accepted, but will be converted to an empty String.

Parameters:

contentEnd – The new content end text.

protected void setContentStart(String contentStart)[source]

Sets the content start text.

null is accepted, but will be converted to an empty String.

Parameters:

contentStart – The new content start text.

protected void setDefaultFullDetail(boolean defaultFullDetail)[source]

Sets whether to use full detail when the caller doesn't specify.

Parameters:

defaultFullDetail – The new defaultFullDetail flag.

protected void setFieldNameValueSeparator(String fieldNameValueSeparator)[source]

Sets the field name value separator text.

null is accepted, but will be converted to an empty String.

Parameters:

fieldNameValueSeparator – The new field name value separator text.

protected void setFieldSeparator(String fieldSeparator)[source]

Sets the field separator text.

null is accepted, but will be converted to an empty String.

Parameters:

fieldSeparator – The new field separator text.

protected void setFieldSeparatorAtEnd(boolean fieldSeparatorAtEnd)[source]

Sets whether the field separator should be added at the end of each buffer.

Parameters:

fieldSeparatorAtEnd – The fieldSeparatorAtEnd flag.

Since:

2.0

protected void setFieldSeparatorAtStart(boolean fieldSeparatorAtStart)[source]

Sets whether the field separator should be added at the start of each buffer.

Parameters:

fieldSeparatorAtStart – The fieldSeparatorAtStart flag.

Since:

2.0

protected void setNullText(String nullText)[source]

Sets the text to output when null found.

null is accepted, but will be converted to an empty String.

Parameters:

nullText – The new text to output when null found.

protected void setSizeEndText(String sizeEndText)[source]

Sets the end text to output when a Collection, Map or array size is output.

This is output after the size value.

null is accepted, but will be converted to an empty String.

Parameters:

sizeEndText – The new end of size text.

protected void setSizeStartText(String sizeStartText)[source]

Sets the start text to output when a Collection, Map or array size is output.

This is output before the size value.

null is accepted, but will be converted to an empty String.

Parameters:

sizeStartText – The new start of size text.

protected void setSummaryObjectEndText(String summaryObjectEndText)[source]

Sets the end text to output when an Object is output in summary mode.

This is output after the size value.

null is accepted, but will be converted to an empty String.

Parameters:

summaryObjectEndText – The new end of summary text.

protected void setSummaryObjectStartText(String summaryObjectStartText)[source]

Sets the start text to output when an Object is output in summary mode.

This is output before the size value.

null is accepted, but will be converted to an empty String.

Parameters:

summaryObjectStartText – The new start of summary text.

protected void setUseClassName(boolean useClassName)[source]

Sets whether to use the class name.

Parameters:

useClassName – The new useClassName flag.

protected void setUseFieldNames(boolean useFieldNames)[source]

Sets whether to use the field names passed in.

Parameters:

useFieldNames – The new useFieldNames flag.

protected void setUseIdentityHashCode(boolean useIdentityHashCode)[source]

Sets whether to use the identity hash code.

Parameters:

useIdentityHashCode – The new useIdentityHashCode flag.

protected void setUseShortClassName(boolean useShortClassName)[source]

Sets whether to output short or long class names.

Parameters:

useShortClassName – The new useShortClassName flag.

Since:

2.0