"}.
*/
private String sizeEndText = ">";
/**
* The summary object text start {@code "<"}.
*/
private String summaryObjectStartText = "<";
/**
* The summary object text start {@code ">"}.
*/
private String summaryObjectEndText = ">";
/**
* Constructs a new instance.
*/
protected ToStringStyle() {
}
/**
* Appends to the {@code toString} a {@code boolean}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
*/
public void append(final StringBuffer buffer, final String fieldName, final boolean value) {
appendFieldStart(buffer, fieldName);
appendDetail(buffer, fieldName, value);
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code boolean}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the toString
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final boolean[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code byte}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
*/
public void append(final StringBuffer buffer, final String fieldName, final byte value) {
appendFieldStart(buffer, fieldName);
appendDetail(buffer, fieldName, value);
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code byte}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the {@code toString}
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final byte[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code char}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
*/
public void append(final StringBuffer buffer, final String fieldName, final char value) {
appendFieldStart(buffer, fieldName);
appendDetail(buffer, fieldName, value);
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code char}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the {@code toString}
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final char[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code double}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
*/
public void append(final StringBuffer buffer, final String fieldName, final double value) {
appendFieldStart(buffer, fieldName);
appendDetail(buffer, fieldName, value);
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code double}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the toString
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final double[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code float}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
*/
public void append(final StringBuffer buffer, final String fieldName, final float value) {
appendFieldStart(buffer, fieldName);
appendDetail(buffer, fieldName, value);
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code float}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the toString
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final float[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} an {@code int}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
*/
public void append(final StringBuffer buffer, final String fieldName, final int value) {
appendFieldStart(buffer, fieldName);
appendDetail(buffer, fieldName, value);
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} an {@code int}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the {@code toString}
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final int[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code long}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
*/
public void append(final StringBuffer buffer, final String fieldName, final long value) {
appendFieldStart(buffer, fieldName);
appendDetail(buffer, fieldName, value);
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code long}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the {@code toString}
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final long[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} an {@link Object}
* value, printing the full {@code toString} of the
* {@link Object} passed in.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final Object value, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (value == null) {
appendNullText(buffer, fieldName);
} else {
appendInternal(buffer, fieldName, value, isFullDetail(fullDetail));
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} an {@link Object}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the toString
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final Object[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code short}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param value the value to add to the {@code toString}
*/
public void append(final StringBuffer buffer, final String fieldName, final short value) {
appendFieldStart(buffer, fieldName);
appendDetail(buffer, fieldName, value);
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} a {@code short}
* array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
* @param array the array to add to the {@code toString}
* @param fullDetail {@code true} for detail, {@code false}
* for summary info, {@code null} for style decides
*/
public void append(final StringBuffer buffer, final String fieldName, final short[] array, final Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* Appends to the {@code toString} the class name.
*
* @param buffer the {@link StringBuffer} to populate
* @param object the {@link Object} whose name to output
*/
protected void appendClassName(final StringBuffer buffer, final Object object) {
if (useClassName && object != null) {
register(object);
if (useShortClassName) {
buffer.append(getShortClassName(object.getClass()));
} else {
buffer.append(object.getClass().getName());
}
}
}
/**
* Appends to the {@code toString} the content end.
*
* @param buffer the {@link StringBuffer} to populate
*/
protected void appendContentEnd(final StringBuffer buffer) {
buffer.append(contentEnd);
}
/**
* Appends to the {@code toString} the content start.
*
* @param buffer the {@link StringBuffer} to populate
*/
protected void appendContentStart(final StringBuffer buffer) {
buffer.append(contentStart);
}
/**
* Appends to the {@code toString} an {@link Object}
* value that has been detected to participate in a cycle. This
* implementation will print the standard string value of the value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString},
* not {@code null}
*
* @since 2.2
*/
protected void appendCyclicObject(final StringBuffer buffer, final String fieldName, final Object value) {
ObjectUtils.identityToString(buffer, value);
}
/**
* Appends to the {@code toString} a {@code boolean}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final boolean value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of a
* {@code boolean} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final boolean[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} a {@code byte}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final byte value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of a
* {@code byte} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final byte[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} a {@code char}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final char value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of a
* {@code char} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final char[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} a {@link Collection}.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param coll the {@link Collection} to add to the
* {@code toString}, not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Collection> coll) {
buffer.append(coll);
}
/**
* Appends to the {@code toString} a {@code double}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final double value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of a
* {@code double} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final double[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} a {@code float}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final float value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of a
* {@code float} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final float[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} an {@code int}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final int value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of an
* {@link Object} array item.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param i the array item index to add
* @param item the array item to add
* @since 3.11
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final int i, final Object item) {
if (i > 0) {
buffer.append(arraySeparator);
}
if (item == null) {
appendNullText(buffer, fieldName);
} else {
appendInternal(buffer, fieldName, item, arrayContentDetail);
}
}
/**
* Appends to the {@code toString} the detail of an
* {@code int} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final int[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} a {@code long}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final long value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of a
* {@code long} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final long[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} a {@link Map}.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param map the {@link Map} to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Map, ?> map) {
buffer.append(map);
}
/**
* Appends to the {@code toString} an {@link Object}
* value, printing the full detail of the {@link Object}.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of an
* {@link Object} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Object[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
appendDetail(buffer, fieldName, i, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} a {@code short}
* value.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final short value) {
buffer.append(value);
}
/**
* Appends to the {@code toString} the detail of a
* {@code short} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, final short[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* Appends to the {@code toString} the end of data indicator.
*
* @param buffer the {@link StringBuffer} to populate
* @param object the {@link Object} to build a
* {@code toString} for.
*/
public void appendEnd(final StringBuffer buffer, final Object object) {
if (!this.fieldSeparatorAtEnd) {
removeLastFieldSeparator(buffer);
}
appendContentEnd(buffer);
unregister(object);
}
/**
* Appends to the {@code toString} the field end.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
*/
protected void appendFieldEnd(final StringBuffer buffer, final String fieldName) {
appendFieldSeparator(buffer);
}
/**
* Appends to the {@code toString} the field separator.
*
* @param buffer the {@link StringBuffer} to populate
*/
protected void appendFieldSeparator(final StringBuffer buffer) {
buffer.append(fieldSeparator);
}
/**
* Appends to the {@code toString} the field start.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name
*/
protected void appendFieldStart(final StringBuffer buffer, final String fieldName) {
if (useFieldNames && fieldName != null) {
buffer.append(fieldName);
buffer.append(fieldNameValueSeparator);
}
}
/**
* Appends the {@link System#identityHashCode(java.lang.Object)}.
*
* @param buffer the {@link StringBuffer} to populate
* @param object the {@link Object} whose id to output
*/
protected void appendIdentityHashCode(final StringBuffer buffer, final Object object) {
if (this.isUseIdentityHashCode() && object != null) {
register(object);
buffer.append('@');
buffer.append(ObjectUtils.identityHashCodeHex(object));
}
}
/**
* Appends to the {@code toString} an {@link Object},
* correctly interpreting its type.
*
*
This method performs the main lookup by Class type to correctly
* route arrays, {@link Collection}s, {@link Map}s and
* {@link 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
* {@code Object.toString()} format.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString},
* not {@code null}
* @param detail output detail or not
*/
protected void appendInternal(final StringBuffer buffer, final String fieldName, final Object value, final boolean detail) {
if (isRegistered(value)
&& !(value instanceof Number || value instanceof Boolean || value instanceof Character)) {
appendCyclicObject(buffer, fieldName, value);
return;
}
register(value);
try {
if (value instanceof Collection>) {
if (detail) {
appendDetail(buffer, fieldName, (Collection>) value);
} else {
appendSummarySize(buffer, fieldName, ((Collection>) value).size());
}
} else if (value instanceof Map, ?>) {
if (detail) {
appendDetail(buffer, fieldName, (Map, ?>) value);
} else {
appendSummarySize(buffer, fieldName, ((Map, ?>) value).size());
}
} else if (value instanceof long[]) {
if (detail) {
appendDetail(buffer, fieldName, (long[]) value);
} else {
appendSummary(buffer, fieldName, (long[]) value);
}
} else if (value instanceof int[]) {
if (detail) {
appendDetail(buffer, fieldName, (int[]) value);
} else {
appendSummary(buffer, fieldName, (int[]) value);
}
} else if (value instanceof short[]) {
if (detail) {
appendDetail(buffer, fieldName, (short[]) value);
} else {
appendSummary(buffer, fieldName, (short[]) value);
}
} else if (value instanceof byte[]) {
if (detail) {
appendDetail(buffer, fieldName, (byte[]) value);
} else {
appendSummary(buffer, fieldName, (byte[]) value);
}
} else if (value instanceof char[]) {
if (detail) {
appendDetail(buffer, fieldName, (char[]) value);
} else {
appendSummary(buffer, fieldName, (char[]) value);
}
} else if (value instanceof double[]) {
if (detail) {
appendDetail(buffer, fieldName, (double[]) value);
} else {
appendSummary(buffer, fieldName, (double[]) value);
}
} else if (value instanceof float[]) {
if (detail) {
appendDetail(buffer, fieldName, (float[]) value);
} else {
appendSummary(buffer, fieldName, (float[]) value);
}
} else if (value instanceof boolean[]) {
if (detail) {
appendDetail(buffer, fieldName, (boolean[]) value);
} else {
appendSummary(buffer, fieldName, (boolean[]) value);
}
} else if (ObjectUtils.isArray(value)) {
if (detail) {
appendDetail(buffer, fieldName, (Object[]) value);
} else {
appendSummary(buffer, fieldName, (Object[]) value);
}
} else if (detail) {
appendDetail(buffer, fieldName, value);
} else {
appendSummary(buffer, fieldName, value);
}
} finally {
unregister(value);
}
}
/**
* Appends to the {@code toString} an indicator for {@code null}.
*
* The default indicator is {@code ""}.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
*/
protected void appendNullText(final StringBuffer buffer, final String fieldName) {
buffer.append(nullText);
}
/**
* Appends to the {@code toString} the start of data indicator.
*
* @param buffer the {@link StringBuffer} to populate
* @param object the {@link Object} to build a {@code toString} for
*/
public void appendStart(final StringBuffer buffer, final Object object) {
if (object != null) {
appendClassName(buffer, object);
appendIdentityHashCode(buffer, object);
appendContentStart(buffer);
if (fieldSeparatorAtStart) {
appendFieldSeparator(buffer);
}
}
}
/**
* Appends to the {@code toString} a summary of a
* {@code boolean} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final boolean[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} a summary of a
* {@code byte} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final byte[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} a summary of a
* {@code char} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final char[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} a summary of a
* {@code double} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final double[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} a summary of a
* {@code float} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final float[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} a summary of an
* {@code int} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final int[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} a summary of a
* {@code long} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final long[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} an {@link Object}
* value, printing a summary of the {@link Object}.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final Object value) {
buffer.append(summaryObjectStartText);
buffer.append(getShortClassName(value.getClass()));
buffer.append(summaryObjectEndText);
}
/**
* Appends to the {@code toString} a summary of an
* {@link Object} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final Object[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} a summary of a
* {@code short} array.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
*/
protected void appendSummary(final StringBuffer buffer, final String fieldName, final short[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
/**
* Appends to the {@code toString} a size summary.
*
* The size summary is used to summarize the contents of
* {@link Collection}s, {@link Map}s and arrays.
*
* The output consists of a prefix, the passed in size
* and a suffix.
*
* The default format is {@code ""}.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param size the size to append
*/
protected void appendSummarySize(final StringBuffer buffer, final String fieldName, final int size) {
buffer.append(sizeStartText);
buffer.append(size);
buffer.append(sizeEndText);
}
/**
* Appends to the {@code toString} the superclass toString.
* NOTE: It assumes that the toString has been created from the same ToStringStyle.
*
* A {@code null} {@code superToString} is ignored.
*
* @param buffer the {@link StringBuffer} to populate
* @param superToString the {@code super.toString()}
* @since 2.0
*/
public void appendSuper(final StringBuffer buffer, final String superToString) {
appendToString(buffer, superToString);
}
/**
* Appends to the {@code toString} another toString.
* NOTE: It assumes that the toString has been created from the same ToStringStyle.
*
* A {@code null} {@code toString} is ignored.
*
* @param buffer the {@link StringBuffer} to populate
* @param toString the additional {@code toString}
* @since 2.0
*/
public void appendToString(final StringBuffer buffer, final String toString) {
if (toString != null) {
final int pos1 = toString.indexOf(contentStart) + contentStart.length();
final int pos2 = toString.lastIndexOf(contentEnd);
if (pos1 != pos2 && pos1 >= 0 && pos2 >= 0) {
if (fieldSeparatorAtStart) {
removeLastFieldSeparator(buffer);
}
buffer.append(toString, pos1, pos2);
appendFieldSeparator(buffer);
}
}
}
/**
* Gets the array end text.
*
* @return the current array end text
*/
protected String getArrayEnd() {
return arrayEnd;
}
/**
* Gets the array separator text.
*
* @return the current array separator text
*/
protected String getArraySeparator() {
return arraySeparator;
}
/**
* Gets the array start text.
*
* @return the current array start text
*/
protected String getArrayStart() {
return arrayStart;
}
/**
* Gets the content end text.
*
* @return the current content end text
*/
protected String getContentEnd() {
return contentEnd;
}
/**
* Gets the content start text.
*
* @return the current content start text
*/
protected String getContentStart() {
return contentStart;
}
/**
* Gets the field name value separator text.
*
* @return the current field name value separator text
*/
protected String getFieldNameValueSeparator() {
return fieldNameValueSeparator;
}
/**
* Gets the field separator text.
*
* @return the current field separator text
*/
protected String getFieldSeparator() {
return fieldSeparator;
}
/**
* Gets the text to output when {@code null} found.
*
* @return the current text to output when null found
*/
protected String getNullText() {
return nullText;
}
/**
* Gets the short class name for a class.
*
* The short class name is the class name excluding
* the package name.
*
* @param cls the {@link Class} to get the short name of
* @return the short name
*/
protected String getShortClassName(final Class> cls) {
return ClassUtils.getShortClassName(cls);
}
/**
* Gets the end text to output when a {@link Collection},
* {@link Map} or array size is output.
*
* This is output after the size value.
*
* @return the current end of size text
*/
protected String getSizeEndText() {
return sizeEndText;
}
/**
* Gets the start text to output when a {@link Collection},
* {@link Map} or array size is output.
*
* This is output before the size value.
*
* @return the current start of size text
*/
protected String getSizeStartText() {
return sizeStartText;
}
/**
* Gets the end text to output when an {@link Object} is
* output in summary mode.
*
* This is output after the size value.
*
* @return the current end of summary text
*/
protected String getSummaryObjectEndText() {
return summaryObjectEndText;
}
/**
* Gets the start text to output when an {@link Object} is
* output in summary mode.
*
* This is output before the size value.
*
* @return the current start of summary text
*/
protected String getSummaryObjectStartText() {
return summaryObjectStartText;
}
/**
* Gets whether to output array content detail.
*
* @return the current array content detail setting
*/
protected boolean isArrayContentDetail() {
return arrayContentDetail;
}
/**
* Gets whether to use full detail when the caller doesn't
* specify.
*
* @return the current defaultFullDetail flag
*/
protected boolean isDefaultFullDetail() {
return defaultFullDetail;
}
/**
* Gets whether the field separator should be added at the end
* of each buffer.
*
* @return fieldSeparatorAtEnd flag
* @since 2.0
*/
protected boolean isFieldSeparatorAtEnd() {
return fieldSeparatorAtEnd;
}
/**
* Gets whether the field separator should be added at the start
* of each buffer.
*
* @return the fieldSeparatorAtStart flag
* @since 2.0
*/
protected boolean isFieldSeparatorAtStart() {
return fieldSeparatorAtStart;
}
/**
* Is this field to be output in full detail.
*
* This method converts a detail request into a detail level.
* The calling code may request full detail ({@code true}),
* but a subclass might ignore that and always return
* {@code false}. The calling code may pass in
* {@code null} indicating that it doesn't care about
* the detail level. In this case the default detail level is
* used.
*
* @param fullDetailRequest the detail level requested
* @return whether full detail is to be shown
*/
protected boolean isFullDetail(final Boolean fullDetailRequest) {
if (fullDetailRequest == null) {
return defaultFullDetail;
}
return fullDetailRequest.booleanValue();
}
// Setters and getters for the customizable parts of the style
// These methods are not expected to be overridden, except to make public
// (They are not public so that immutable subclasses can be written)
/**
* Gets whether to use the class name.
*
* @return the current useClassName flag
*/
protected boolean isUseClassName() {
return useClassName;
}
/**
* Gets whether to use the field names passed in.
*
* @return the current useFieldNames flag
*/
protected boolean isUseFieldNames() {
return useFieldNames;
}
/**
* Gets whether to use the identity hash code.
*
* @return the current useIdentityHashCode flag
*/
protected boolean isUseIdentityHashCode() {
return useIdentityHashCode;
}
/**
* Gets whether to output short or long class names.
*
* @return the current useShortClassName flag
* @since 2.0
*/
protected boolean isUseShortClassName() {
return useShortClassName;
}
/**
* Appends to the {@code toString} the detail of an array type.
*
* @param buffer the {@link StringBuffer} to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the {@code toString},
* not {@code null}
* @since 2.0
*/
protected void reflectionAppendArrayDetail(final StringBuffer buffer, final String fieldName, final Object array) {
buffer.append(arrayStart);
final int length = Array.getLength(array);
for (int i = 0; i < length; i++) {
appendDetail(buffer, fieldName, i, Array.get(array, i));
}
buffer.append(arrayEnd);
}
/**
* Remove the last field separator from the buffer.
*
* @param buffer the {@link StringBuffer} to populate
* @since 2.0
*/
protected void removeLastFieldSeparator(final StringBuffer buffer) {
if (StringUtils.endsWith(buffer, fieldSeparator)) {
buffer.setLength(buffer.length() - fieldSeparator.length());
}
}
/**
* Sets whether to output array content detail.
*
* @param arrayContentDetail the new arrayContentDetail flag
*/
protected void setArrayContentDetail(final boolean arrayContentDetail) {
this.arrayContentDetail = arrayContentDetail;
}
/**
* Sets the array end text.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param arrayEnd the new array end text
*/
protected void setArrayEnd(String arrayEnd) {
if (arrayEnd == null) {
arrayEnd = StringUtils.EMPTY;
}
this.arrayEnd = arrayEnd;
}
/**
* Sets the array separator text.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param arraySeparator the new array separator text
*/
protected void setArraySeparator(String arraySeparator) {
if (arraySeparator == null) {
arraySeparator = StringUtils.EMPTY;
}
this.arraySeparator = arraySeparator;
}
/**
* Sets the array start text.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param arrayStart the new array start text
*/
protected void setArrayStart(String arrayStart) {
if (arrayStart == null) {
arrayStart = StringUtils.EMPTY;
}
this.arrayStart = arrayStart;
}
/**
* Sets the content end text.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param contentEnd the new content end text
*/
protected void setContentEnd(String contentEnd) {
if (contentEnd == null) {
contentEnd = StringUtils.EMPTY;
}
this.contentEnd = contentEnd;
}
/**
* Sets the content start text.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param contentStart the new content start text
*/
protected void setContentStart(String contentStart) {
if (contentStart == null) {
contentStart = StringUtils.EMPTY;
}
this.contentStart = contentStart;
}
/**
* Sets whether to use full detail when the caller doesn't
* specify.
*
* @param defaultFullDetail the new defaultFullDetail flag
*/
protected void setDefaultFullDetail(final boolean defaultFullDetail) {
this.defaultFullDetail = defaultFullDetail;
}
/**
* Sets the field name value separator text.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param fieldNameValueSeparator the new field name value separator text
*/
protected void setFieldNameValueSeparator(String fieldNameValueSeparator) {
if (fieldNameValueSeparator == null) {
fieldNameValueSeparator = StringUtils.EMPTY;
}
this.fieldNameValueSeparator = fieldNameValueSeparator;
}
/**
* Sets the field separator text.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param fieldSeparator the new field separator text
*/
protected void setFieldSeparator(String fieldSeparator) {
if (fieldSeparator == null) {
fieldSeparator = StringUtils.EMPTY;
}
this.fieldSeparator = fieldSeparator;
}
/**
* Sets whether the field separator should be added at the end
* of each buffer.
*
* @param fieldSeparatorAtEnd the fieldSeparatorAtEnd flag
* @since 2.0
*/
protected void setFieldSeparatorAtEnd(final boolean fieldSeparatorAtEnd) {
this.fieldSeparatorAtEnd = fieldSeparatorAtEnd;
}
/**
* Sets whether the field separator should be added at the start
* of each buffer.
*
* @param fieldSeparatorAtStart the fieldSeparatorAtStart flag
* @since 2.0
*/
protected void setFieldSeparatorAtStart(final boolean fieldSeparatorAtStart) {
this.fieldSeparatorAtStart = fieldSeparatorAtStart;
}
/**
* Sets the text to output when {@code null} found.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param nullText the new text to output when null found
*/
protected void setNullText(String nullText) {
if (nullText == null) {
nullText = StringUtils.EMPTY;
}
this.nullText = nullText;
}
/**
* Sets the end text to output when a {@link Collection},
* {@link Map} or array size is output.
*
* This is output after the size value.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param sizeEndText the new end of size text
*/
protected void setSizeEndText(String sizeEndText) {
if (sizeEndText == null) {
sizeEndText = StringUtils.EMPTY;
}
this.sizeEndText = sizeEndText;
}
/**
* Sets the start text to output when a {@link Collection},
* {@link Map} or array size is output.
*
* This is output before the size value.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param sizeStartText the new start of size text
*/
protected void setSizeStartText(String sizeStartText) {
if (sizeStartText == null) {
sizeStartText = StringUtils.EMPTY;
}
this.sizeStartText = sizeStartText;
}
/**
* Sets the end text to output when an {@link Object} is
* output in summary mode.
*
* This is output after the size value.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param summaryObjectEndText the new end of summary text
*/
protected void setSummaryObjectEndText(String summaryObjectEndText) {
if (summaryObjectEndText == null) {
summaryObjectEndText = StringUtils.EMPTY;
}
this.summaryObjectEndText = summaryObjectEndText;
}
/**
* Sets the start text to output when an {@link Object} is
* output in summary mode.
*
* This is output before the size value.
*
* {@code null} is accepted, but will be converted to
* an empty String.
*
* @param summaryObjectStartText the new start of summary text
*/
protected void setSummaryObjectStartText(String summaryObjectStartText) {
if (summaryObjectStartText == null) {
summaryObjectStartText = StringUtils.EMPTY;
}
this.summaryObjectStartText = summaryObjectStartText;
}
/**
* Sets whether to use the class name.
*
* @param useClassName the new useClassName flag
*/
protected void setUseClassName(final boolean useClassName) {
this.useClassName = useClassName;
}
/**
* Sets whether to use the field names passed in.
*
* @param useFieldNames the new useFieldNames flag
*/
protected void setUseFieldNames(final boolean useFieldNames) {
this.useFieldNames = useFieldNames;
}
/**
* Sets whether to use the identity hash code.
*
* @param useIdentityHashCode the new useIdentityHashCode flag
*/
protected void setUseIdentityHashCode(final boolean useIdentityHashCode) {
this.useIdentityHashCode = useIdentityHashCode;
}
/**
* Sets whether to output short or long class names.
*
* @param useShortClassName the new useShortClassName flag
* @since 2.0
*/
protected void setUseShortClassName(final boolean useShortClassName) {
this.useShortClassName = useShortClassName;
}
}