Class StandardToStringStyle
- All Implemented Interfaces:
Serializable
ToStringBuilder to create a toString.
This class is intended to be used as a singleton. There is no need to instantiate a new style each time. Simply instantiate the class once, customize the values as required, and store the result in a public static final variable for the rest of the program to access.
- Since:
- 1.0
- See Also:
-
Field Summary
Fields inherited from class ToStringStyle
DEFAULT_STYLE, JSON_STYLE, MULTI_LINE_STYLE, NO_CLASS_NAME_STYLE, NO_FIELD_NAMES_STYLE, SHORT_PREFIX_STYLE, SIMPLE_STYLEModifier and TypeFieldDescriptionstatic final ToStringStyleThe default toString style.static final ToStringStyleThe JSON toString style.static final ToStringStyleThe multi line toString style.static final ToStringStyleThe no class name toString style.static final ToStringStyleThe no field names toString style.static final ToStringStyleThe short prefix toString style.static final ToStringStyleThe simple toString style. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the array end text.Gets the array separator text.Gets the array start text.Gets the content end text.Gets the content start text.Gets the field name value separator text.Gets the field separator text.Gets the text to output whennullfound.Gets the end text to output when anObjectis output in summary mode.Gets the start text to output when anObjectis output in summary mode.booleanTests whether to output array content detail.booleanTests whether full detail is used when the caller does not specify a detail level.booleanTests whether the field separator should be added at the end of each buffer.booleanTests whether the field separator should be added at the start of each buffer.booleanTests whether to use the class name.booleanTests whether to use the field names passed in.booleanTests whether to use the identity hash code.booleanTests whether short class names should be output.voidsetArrayContentDetail(boolean arrayContentDetail) Sets whether to output array content detail.voidsetArrayEnd(String arrayEnd) Sets the array end text.voidsetArraySeparator(String arraySeparator) Sets the array separator text.voidsetArrayStart(String arrayStart) Sets the array start text.voidsetContentEnd(String contentEnd) Sets the content end text.voidsetContentStart(String contentStart) Sets the content start text.voidsetDefaultFullDetail(boolean defaultFullDetail) Sets whether to use full detail when the caller doesn't specify.voidsetFieldNameValueSeparator(String fieldNameValueSeparator) Sets the field name value separator text.voidsetFieldSeparator(String fieldSeparator) Sets the field separator text.voidsetFieldSeparatorAtEnd(boolean fieldSeparatorAtEnd) Sets whether the field separator should be added at the end of each buffer.voidsetFieldSeparatorAtStart(boolean fieldSeparatorAtStart) Sets whether the field separator should be added at the start of each buffer.voidsetNullText(String nullText) Sets the text to output whennullfound.voidsetSizeEndText(String sizeEndText) voidsetSizeStartText(String sizeStartText) voidsetSummaryObjectEndText(String summaryObjectEndText) Sets the end text to output when anObjectis output in summary mode.voidsetSummaryObjectStartText(String summaryObjectStartText) Sets the start text to output when anObjectis output in summary mode.voidsetUseClassName(boolean useClassName) Sets whether to use the class name.voidsetUseFieldNames(boolean useFieldNames) Sets whether to use the field names passed in.voidsetUseIdentityHashCode(boolean useIdentityHashCode) Sets whether to use the identity hash code.voidsetUseShortClassName(boolean useShortClassName) Sets whether to output short or long class names.Methods inherited from class 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, appendDetail, 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, getRegistry, getShortClassName, isFullDetail, reflectionAppendArrayDetail, removeLastFieldSeparatorModifier and TypeMethodDescriptionvoidappend(StringBuffer buffer, String fieldName, boolean value) Appends to thetoStringabooleanvalue.voidappend(StringBuffer buffer, String fieldName, boolean[] array, Boolean fullDetail) Appends to thetoStringabooleanarray.voidappend(StringBuffer buffer, String fieldName, byte value) Appends to thetoStringabytevalue.voidappend(StringBuffer buffer, String fieldName, byte[] array, Boolean fullDetail) Appends to thetoStringabytearray.voidappend(StringBuffer buffer, String fieldName, char value) Appends to thetoStringacharvalue.voidappend(StringBuffer buffer, String fieldName, char[] array, Boolean fullDetail) Appends to thetoStringachararray.voidappend(StringBuffer buffer, String fieldName, double value) Appends to thetoStringadoublevalue.voidappend(StringBuffer buffer, String fieldName, double[] array, Boolean fullDetail) Appends to thetoStringadoublearray.voidappend(StringBuffer buffer, String fieldName, float value) Appends to thetoStringafloatvalue.voidappend(StringBuffer buffer, String fieldName, float[] array, Boolean fullDetail) Appends to thetoStringafloatarray.voidappend(StringBuffer buffer, String fieldName, int value) Appends to thetoStringanintvalue.voidappend(StringBuffer buffer, String fieldName, int[] array, Boolean fullDetail) Appends to thetoStringanintarray.voidappend(StringBuffer buffer, String fieldName, long value) Appends to thetoStringalongvalue.voidappend(StringBuffer buffer, String fieldName, long[] array, Boolean fullDetail) Appends to thetoStringalongarray.voidappend(StringBuffer buffer, String fieldName, short value) Appends to thetoStringashortvalue.voidappend(StringBuffer buffer, String fieldName, short[] array, Boolean fullDetail) Appends to thetoStringashortarray.voidappend(StringBuffer buffer, String fieldName, Object[] array, Boolean fullDetail) Appends to thetoStringanObjectarray.voidappend(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail) protected voidappendClassName(StringBuffer buffer, Object object) Appends to thetoStringthe class name.protected voidappendContentEnd(StringBuffer buffer) Appends to thetoStringthe content end.protected voidappendContentStart(StringBuffer buffer) Appends to thetoStringthe content start.protected voidappendCyclicObject(StringBuffer buffer, String fieldName, Object value) Appends to thetoStringanObjectvalue that has been detected to participate in a cycle.protected voidappendDetail(StringBuffer buffer, String fieldName, boolean value) Appends to thetoStringabooleanvalue.protected voidappendDetail(StringBuffer buffer, String fieldName, boolean[] array) Appends to thetoStringthe detail of abooleanarray.protected voidappendDetail(StringBuffer buffer, String fieldName, byte value) Appends to thetoStringabytevalue.protected voidappendDetail(StringBuffer buffer, String fieldName, byte[] array) Appends to thetoStringthe detail of abytearray.protected voidappendDetail(StringBuffer buffer, String fieldName, char value) Appends to thetoStringacharvalue.protected voidappendDetail(StringBuffer buffer, String fieldName, char[] array) Appends to thetoStringthe detail of achararray.protected voidappendDetail(StringBuffer buffer, String fieldName, double value) Appends to thetoStringadoublevalue.protected voidappendDetail(StringBuffer buffer, String fieldName, double[] array) Appends to thetoStringthe detail of adoublearray.protected voidappendDetail(StringBuffer buffer, String fieldName, float value) Appends to thetoStringafloatvalue.protected voidappendDetail(StringBuffer buffer, String fieldName, float[] array) Appends to thetoStringthe detail of afloatarray.protected voidappendDetail(StringBuffer buffer, String fieldName, int value) Appends to thetoStringanintvalue.protected voidappendDetail(StringBuffer buffer, String fieldName, int[] array) Appends to thetoStringthe detail of anintarray.protected voidappendDetail(StringBuffer buffer, String fieldName, int i, Object item) Appends to thetoStringthe detail of anObjectarray item.protected voidappendDetail(StringBuffer buffer, String fieldName, long value) Appends to thetoStringalongvalue.protected voidappendDetail(StringBuffer buffer, String fieldName, long[] array) Appends to thetoStringthe detail of alongarray.protected voidappendDetail(StringBuffer buffer, String fieldName, short value) Appends to thetoStringashortvalue.protected voidappendDetail(StringBuffer buffer, String fieldName, short[] array) Appends to thetoStringthe detail of ashortarray.protected voidappendDetail(StringBuffer buffer, String fieldName, Object value) protected voidappendDetail(StringBuffer buffer, String fieldName, Object[] array) Appends to thetoStringthe detail of anObjectarray.protected voidappendDetail(StringBuffer buffer, String fieldName, Collection<?> coll) Appends to thetoStringaCollection.protected voidappendDetail(StringBuffer buffer, String fieldName, Map<?, ?> map) Appends to thetoStringaMap.voidappendEnd(StringBuffer buffer, Object object) Appends to thetoStringthe end of data indicator.protected voidappendFieldEnd(StringBuffer buffer, String fieldName) Appends to thetoStringthe field end.protected voidappendFieldSeparator(StringBuffer buffer) Appends to thetoStringthe field separator.protected voidappendFieldStart(StringBuffer buffer, String fieldName) Appends to thetoStringthe field start.protected voidappendIdentityHashCode(StringBuffer buffer, Object object) Appends theSystem.identityHashCode(java.lang.Object).protected voidappendInternal(StringBuffer buffer, String fieldName, Object value, boolean detail) Appends to thetoStringanObject, correctly interpreting its type.protected voidappendNullText(StringBuffer buffer, String fieldName) Appends to thetoStringan indicator fornull.voidappendStart(StringBuffer buffer, Object object) Appends to thetoStringthe start of data indicator.protected voidappendSummary(StringBuffer buffer, String fieldName, boolean[] array) Appends to thetoStringa summary of abooleanarray.protected voidappendSummary(StringBuffer buffer, String fieldName, byte[] array) Appends to thetoStringa summary of abytearray.protected voidappendSummary(StringBuffer buffer, String fieldName, char[] array) Appends to thetoStringa summary of achararray.protected voidappendSummary(StringBuffer buffer, String fieldName, double[] array) Appends to thetoStringa summary of adoublearray.protected voidappendSummary(StringBuffer buffer, String fieldName, float[] array) Appends to thetoStringa summary of afloatarray.protected voidappendSummary(StringBuffer buffer, String fieldName, int[] array) Appends to thetoStringa summary of anintarray.protected voidappendSummary(StringBuffer buffer, String fieldName, long[] array) Appends to thetoStringa summary of alongarray.protected voidappendSummary(StringBuffer buffer, String fieldName, short[] array) Appends to thetoStringa summary of ashortarray.protected voidappendSummary(StringBuffer buffer, String fieldName, Object value) protected voidappendSummary(StringBuffer buffer, String fieldName, Object[] array) Appends to thetoStringa summary of anObjectarray.protected voidappendSummarySize(StringBuffer buffer, String fieldName, int size) Appends to thetoStringa size summary.voidappendSuper(StringBuffer buffer, String superToString) Appends to thetoStringthe superclass toString.voidappendToString(StringBuffer buffer, String toString) Appends to thetoStringanother toString.Gets the registry of objects being traversed by thereflectionToStringmethods in the current thread.protected StringgetShortClassName(Class<?> cls) Gets the short class name for a class.protected booleanisFullDetail(Boolean fullDetailRequest) Tests whether this field should be output in full detail.protected voidreflectionAppendArrayDetail(StringBuffer buffer, String fieldName, Object array) Appends to thetoStringthe detail of an array type.protected voidremoveLastFieldSeparator(StringBuffer buffer) Remove the last field separator from the buffer.
-
Constructor Details
-
StandardToStringStyle
public StandardToStringStyle()Constructs a new instance.
-
-
Method Details
-
getArrayEnd
Gets the array end text.- Overrides:
getArrayEndin classToStringStyle- Returns:
- The current array end text
-
getArraySeparator
Gets the array separator text.- Overrides:
getArraySeparatorin classToStringStyle- Returns:
- The current array separator text
-
getArrayStart
Gets the array start text.- Overrides:
getArrayStartin classToStringStyle- Returns:
- The current array start text
-
getContentEnd
Gets the content end text.- Overrides:
getContentEndin classToStringStyle- Returns:
- The current content end text
-
getContentStart
Gets the content start text.- Overrides:
getContentStartin classToStringStyle- Returns:
- The current content start text
-
getFieldNameValueSeparator
Gets the field name value separator text.- Overrides:
getFieldNameValueSeparatorin classToStringStyle- Returns:
- The current field name value separator text
-
getFieldSeparator
Gets the field separator text.- Overrides:
getFieldSeparatorin classToStringStyle- Returns:
- The current field separator text
-
getNullText
Gets the text to output whennullfound.- Overrides:
getNullTextin classToStringStyle- Returns:
- The current text to output when
nullfound
-
getSizeEndText
Gets the end text to output when aCollection,MaporArraysize is output.This is output after the size value.
- Overrides:
getSizeEndTextin classToStringStyle- Returns:
- The current end of size text
-
getSizeStartText
Gets the text to output when aCollection,MaporArraysize is output.This is output before the size value.
- Overrides:
getSizeStartTextin classToStringStyle- Returns:
- The current start of size text
-
getSummaryObjectEndText
Gets the end text to output when anObjectis output in summary mode.This is output after the size value.
- Overrides:
getSummaryObjectEndTextin classToStringStyle- Returns:
- The current end of summary text
-
getSummaryObjectStartText
Gets the start text to output when anObjectis output in summary mode.This is output before the size value.
- Overrides:
getSummaryObjectStartTextin classToStringStyle- Returns:
- The current start of summary text
-
isArrayContentDetail
Tests whether to output array content detail.- Overrides:
isArrayContentDetailin classToStringStyle- Returns:
- The current array content detail setting
-
isDefaultFullDetail
Tests whether full detail is used when the caller does not specify a detail level.- Overrides:
isDefaultFullDetailin classToStringStyle- Returns:
- The current defaultFullDetail flag
-
isFieldSeparatorAtEnd
Tests whether the field separator should be added at the end of each buffer.- Overrides:
isFieldSeparatorAtEndin classToStringStyle- Returns:
- fieldSeparatorAtEnd flag
- Since:
- 2.0
-
isFieldSeparatorAtStart
Tests whether the field separator should be added at the start of each buffer.- Overrides:
isFieldSeparatorAtStartin classToStringStyle- Returns:
- The fieldSeparatorAtStart flag
- Since:
- 2.0
-
isUseClassName
Tests whether to use the class name.- Overrides:
isUseClassNamein classToStringStyle- Returns:
- The current useClassName flag
-
isUseFieldNames
Tests whether to use the field names passed in.- Overrides:
isUseFieldNamesin classToStringStyle- Returns:
- The current useFieldNames flag
-
isUseIdentityHashCode
Tests whether to use the identity hash code.- Overrides:
isUseIdentityHashCodein classToStringStyle- Returns:
- The current useIdentityHashCode flag
-
isUseShortClassName
Tests whether short class names should be output.- Overrides:
isUseShortClassNamein classToStringStyle- Returns:
- The current useShortClassName flag
- Since:
- 2.0
-
setArrayContentDetail
Sets whether to output array content detail.- Overrides:
setArrayContentDetailin classToStringStyle- Parameters:
arrayContentDetail- The new arrayContentDetail flag
-
setArrayEnd
Sets the array end text.nullis accepted, but will be converted to an empty String.- Overrides:
setArrayEndin classToStringStyle- Parameters:
arrayEnd- The new array end text
-
setArraySeparator
Sets the array separator text.nullis accepted, but will be converted to an empty String.- Overrides:
setArraySeparatorin classToStringStyle- Parameters:
arraySeparator- The new array separator text
-
setArrayStart
Sets the array start text.nullis accepted, but will be converted to an empty String.- Overrides:
setArrayStartin classToStringStyle- Parameters:
arrayStart- The new array start text
-
setContentEnd
Sets the content end text.nullis accepted, but will be converted to an empty String.- Overrides:
setContentEndin classToStringStyle- Parameters:
contentEnd- The new content end text
-
setContentStart
Sets the content start text.nullis accepted, but will be converted to an empty String.- Overrides:
setContentStartin classToStringStyle- Parameters:
contentStart- The new content start text
-
setDefaultFullDetail
Sets whether to use full detail when the caller doesn't specify.- Overrides:
setDefaultFullDetailin classToStringStyle- Parameters:
defaultFullDetail- The new defaultFullDetail flag
-
setFieldNameValueSeparator
Sets the field name value separator text.nullis accepted, but will be converted to an empty String.- Overrides:
setFieldNameValueSeparatorin classToStringStyle- Parameters:
fieldNameValueSeparator- The new field name value separator text
-
setFieldSeparator
Sets the field separator text.nullis accepted, but will be converted to an empty String.- Overrides:
setFieldSeparatorin classToStringStyle- Parameters:
fieldSeparator- The new field separator text
-
setFieldSeparatorAtEnd
Sets whether the field separator should be added at the end of each buffer.- Overrides:
setFieldSeparatorAtEndin classToStringStyle- Parameters:
fieldSeparatorAtEnd- The fieldSeparatorAtEnd flag- Since:
- 2.0
-
setFieldSeparatorAtStart
Sets whether the field separator should be added at the start of each buffer.- Overrides:
setFieldSeparatorAtStartin classToStringStyle- Parameters:
fieldSeparatorAtStart- The fieldSeparatorAtStart flag- Since:
- 2.0
-
setNullText
Sets the text to output whennullfound.nullis accepted, but will be converted to an empty String.- Overrides:
setNullTextin classToStringStyle- Parameters:
nullText- The new text to output whennullfound
-
setSizeEndText
Sets the end text to output when aCollection,MaporArraysize is output.This is output after the size value.
nullis accepted, but will be converted to an empty String.- Overrides:
setSizeEndTextin classToStringStyle- Parameters:
sizeEndText- The new end of size text
-
setSizeStartText
Sets the start text to output when aCollection,MaporArraysize is output.This is output before the size value.
nullis accepted, but will be converted to an empty String.- Overrides:
setSizeStartTextin classToStringStyle- Parameters:
sizeStartText- The new start of size text
-
setSummaryObjectEndText
Sets the end text to output when anObjectis output in summary mode.This is output after the size value.
nullis accepted, but will be converted to an empty String.- Overrides:
setSummaryObjectEndTextin classToStringStyle- Parameters:
summaryObjectEndText- The new end of summary text
-
setSummaryObjectStartText
Sets the start text to output when anObjectis output in summary mode.This is output before the size value.
nullis accepted, but will be converted to an empty String.- Overrides:
setSummaryObjectStartTextin classToStringStyle- Parameters:
summaryObjectStartText- The new start of summary text
-
setUseClassName
Sets whether to use the class name.- Overrides:
setUseClassNamein classToStringStyle- Parameters:
useClassName- The new useClassName flag
-
setUseFieldNames
Sets whether to use the field names passed in.- Overrides:
setUseFieldNamesin classToStringStyle- Parameters:
useFieldNames- The new useFieldNames flag
-
setUseIdentityHashCode
Sets whether to use the identity hash code.- Overrides:
setUseIdentityHashCodein classToStringStyle- Parameters:
useIdentityHashCode- The new useIdentityHashCode flag
-
setUseShortClassName
Sets whether to output short or long class names.- Overrides:
setUseShortClassNamein classToStringStyle- Parameters:
useShortClassName- The new useShortClassName flag- Since:
- 2.0
-