Package org.apache.commons.lang3.builder
Class MultilineRecursiveToStringStyle
- java.lang.Object
-
- org.apache.commons.lang3.builder.ToStringStyle
-
- org.apache.commons.lang3.builder.RecursiveToStringStyle
-
- org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle
-
- All Implemented Interfaces:
java.io.Serializable
public class MultilineRecursiveToStringStyle extends RecursiveToStringStyle
Works withToStringBuilderto create a "deep"toString. But instead a single line like theRecursiveToStringStylethis creates a multiline String similar to theToStringStyle.MULTI_LINE_STYLE.To use this class write code as follows:
public class Job { String title; ... } public class Person { String name; int age; boolean smoker; Job job; ... public String toString() { return new ReflectionToStringBuilder(this, new MultilineRecursiveToStringStyle()).toString(); } }This will produce a toString of the format:
Person@7f54[ <br> name=Stephen, <br> age=29, <br> smokealse, <br> job=Job@43cd2[ <br> title=Manager <br> ] <br> ]- Since:
- 3.4
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static intINDENTIndenting of inner lines.private static longserialVersionUIDRequired for serialization support.private intspacesCurrent indenting.-
Fields inherited from class org.apache.commons.lang3.builder.ToStringStyle
DEFAULT_STYLE, JSON_STYLE, MULTI_LINE_STYLE, NO_CLASS_NAME_STYLE, NO_FIELD_NAMES_STYLE, SHORT_PREFIX_STYLE, SIMPLE_STYLE
-
-
Constructor Summary
Constructors Constructor Description MultilineRecursiveToStringStyle()Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array)Appends to thetoStringthe detail of abooleanarray.protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array)Appends to thetoStringthe detail of abytearray.protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array)Appends to thetoStringthe detail of achararray.protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array)Appends to thetoStringthe detail of adoublearray.protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array)Appends to thetoStringthe detail of afloatarray.protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array)Appends to thetoStringthe detail of anintarray.protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array)Appends to thetoStringthe detail of alongarray.protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array)Appends to thetoStringthe detail of ashortarray.voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value)Appends to thetoStringanObjectvalue, printing the full detail of theObject.protected voidappendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array)Appends to thetoStringthe detail of anObjectarray.protected voidreflectionAppendArrayDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object array)Appends to thetoStringthe detail of an array type.private voidresetIndent()Resets the fields responsible for the line breaks and indenting.private java.lang.Stringspacer(int spaces)Creates a StringBuilder responsible for the indenting.-
Methods inherited from class org.apache.commons.lang3.builder.RecursiveToStringStyle
accept, appendDetail
-
Methods inherited from class org.apache.commons.lang3.builder.ToStringStyle
append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, appendClassName, appendContentEnd, appendContentStart, appendCyclicObject, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendEnd, appendFieldEnd, appendFieldSeparator, appendFieldStart, appendIdentityHashCode, appendInternal, appendNullText, appendStart, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummarySize, appendSuper, appendToString, getArrayEnd, getArraySeparator, getArrayStart, getContentEnd, getContentStart, getFieldNameValueSeparator, getFieldSeparator, getNullText, getRegistry, getShortClassName, getSizeEndText, getSizeStartText, getSummaryObjectEndText, getSummaryObjectStartText, isArrayContentDetail, isDefaultFullDetail, isFieldSeparatorAtEnd, isFieldSeparatorAtStart, isFullDetail, isRegistered, isUseClassName, isUseFieldNames, isUseIdentityHashCode, isUseShortClassName, register, removeLastFieldSeparator, setArrayContentDetail, setArrayEnd, setArraySeparator, setArrayStart, setContentEnd, setContentStart, setDefaultFullDetail, setFieldNameValueSeparator, setFieldSeparator, setFieldSeparatorAtEnd, setFieldSeparatorAtStart, setNullText, setSizeEndText, setSizeStartText, setSummaryObjectEndText, setSummaryObjectStartText, setUseClassName, setUseFieldNames, setUseIdentityHashCode, setUseShortClassName, unregister
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Required for serialization support.- See Also:
Serializable, Constant Field Values
-
INDENT
private static final int INDENT
Indenting of inner lines.- See Also:
- Constant Field Values
-
spaces
private int spaces
Current indenting.
-
-
Method Detail
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of abooleanarray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of abytearray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of achararray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of adoublearray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of afloatarray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of anintarray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of alongarray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
appendDetail
public void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value)Description copied from class:ToStringStyleAppends to thetoStringanObjectvalue, printing the full detail of theObject.- Overrides:
appendDetailin classRecursiveToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedvalue- the value to add to thetoString, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of anObjectarray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of ashortarray.- Overrides:
appendDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
reflectionAppendArrayDetail
protected void reflectionAppendArrayDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object array)Description copied from class:ToStringStyleAppends to thetoStringthe detail of an array type.- Overrides:
reflectionAppendArrayDetailin classToStringStyle- Parameters:
buffer- theStringBufferto populatefieldName- the field name, typically not used as already appendedarray- the array to add to thetoString, notnull
-
resetIndent
private void resetIndent()
Resets the fields responsible for the line breaks and indenting. Must be invoked after changing thespacesvalue.
-
spacer
private java.lang.String spacer(int spaces)
Creates a StringBuilder responsible for the indenting.- Parameters:
spaces- how far to indent- Returns:
- a StringBuilder with {spaces} leading space characters.
-
-