Class ToStringStyle
- java.lang.Object
-
- org.apache.commons.lang3.builder.ToStringStyle
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
RecursiveToStringStyle
,StandardToStringStyle
public abstract class ToStringStyle extends java.lang.Object implements java.io.Serializable
ControlsString
formatting forToStringBuilder
. The main public interface is always viaToStringBuilder
.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
tolong
toObject
toint[]
) 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
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ToStringStyle
DEFAULT_STYLE
The default toString style.static ToStringStyle
JSON_STYLE
The JSON toString style.static ToStringStyle
MULTI_LINE_STYLE
The multi line toString style.static ToStringStyle
NO_CLASS_NAME_STYLE
The no class name toString style.static ToStringStyle
NO_FIELD_NAMES_STYLE
The no field names toString style.static ToStringStyle
SHORT_PREFIX_STYLE
The short prefix toString style.static ToStringStyle
SIMPLE_STYLE
The simple toString style.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ToStringStyle()
Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean value)
Appends to thetoString
aboolean
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array, java.lang.Boolean fullDetail)
Appends to thetoString
aboolean
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, byte value)
Appends to thetoString
abyte
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array, java.lang.Boolean fullDetail)
Appends to thetoString
abyte
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, char value)
Appends to thetoString
achar
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array, java.lang.Boolean fullDetail)
Appends to thetoString
achar
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, double value)
Appends to thetoString
adouble
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array, java.lang.Boolean fullDetail)
Appends to thetoString
adouble
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, float value)
Appends to thetoString
afloat
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array, java.lang.Boolean fullDetail)
Appends to thetoString
afloat
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, int value)
Appends to thetoString
anint
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array, java.lang.Boolean fullDetail)
Appends to thetoString
anint
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, long value)
Appends to thetoString
along
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array, java.lang.Boolean fullDetail)
Appends to thetoString
along
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, short value)
Appends to thetoString
ashort
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array, java.lang.Boolean fullDetail)
Appends to thetoString
ashort
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array, java.lang.Boolean fullDetail)
Appends to thetoString
anObject
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value, java.lang.Boolean fullDetail)
Appends to thetoString
anObject
value, printing the fulltoString
of theObject
passed in.protected void
appendClassName(java.lang.StringBuffer buffer, java.lang.Object object)
Appends to thetoString
the class name.protected void
appendContentEnd(java.lang.StringBuffer buffer)
Appends to thetoString
the content end.protected void
appendContentStart(java.lang.StringBuffer buffer)
Appends to thetoString
the content start.protected void
appendCyclicObject(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value)
Appends to thetoString
anObject
value that has been detected to participate in a cycle.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean value)
Appends to thetoString
aboolean
value.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array)
Appends to thetoString
the detail of aboolean
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, byte value)
Appends to thetoString
abyte
value.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array)
Appends to thetoString
the detail of abyte
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, char value)
Appends to thetoString
achar
value.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array)
Appends to thetoString
the detail of achar
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, double value)
Appends to thetoString
adouble
value.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array)
Appends to thetoString
the detail of adouble
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, float value)
Appends to thetoString
afloat
value.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array)
Appends to thetoString
the detail of afloat
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, int value)
Appends to thetoString
anint
value.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array)
Appends to thetoString
the detail of anint
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, int i, java.lang.Object item)
Appends to thetoString
the detail of anObject
array item.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, long value)
Appends to thetoString
along
value.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array)
Appends to thetoString
the detail of along
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, short value)
Appends to thetoString
ashort
value.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array)
Appends to thetoString
the detail of ashort
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value)
Appends to thetoString
anObject
value, printing the full detail of theObject
.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array)
Appends to thetoString
the detail of anObject
array.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.util.Collection<?> coll)
Appends to thetoString
aCollection
.protected void
appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.util.Map<?,?> map)
Appends to thetoString
aMap
.void
appendEnd(java.lang.StringBuffer buffer, java.lang.Object object)
Appends to thetoString
the end of data indicator.protected void
appendFieldEnd(java.lang.StringBuffer buffer, java.lang.String fieldName)
Appends to thetoString
the field end.protected void
appendFieldSeparator(java.lang.StringBuffer buffer)
Appends to thetoString
the field separator.protected void
appendFieldStart(java.lang.StringBuffer buffer, java.lang.String fieldName)
Appends to thetoString
the field start.protected void
appendIdentityHashCode(java.lang.StringBuffer buffer, java.lang.Object object)
Appends theSystem.identityHashCode(java.lang.Object)
.protected void
appendInternal(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value, boolean detail)
Appends to thetoString
anObject
, correctly interpreting its type.protected void
appendNullText(java.lang.StringBuffer buffer, java.lang.String fieldName)
Appends to thetoString
an indicator fornull
.void
appendStart(java.lang.StringBuffer buffer, java.lang.Object object)
Appends to thetoString
the start of data indicator.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array)
Appends to thetoString
a summary of aboolean
array.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array)
Appends to thetoString
a summary of abyte
array.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array)
Appends to thetoString
a summary of achar
array.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array)
Appends to thetoString
a summary of adouble
array.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array)
Appends to thetoString
a summary of afloat
array.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array)
Appends to thetoString
a summary of anint
array.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array)
Appends to thetoString
a summary of along
array.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array)
Appends to thetoString
a summary of ashort
array.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value)
Appends to thetoString
anObject
value, printing a summary of theObject
.protected void
appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array)
Appends to thetoString
a summary of anObject
array.protected void
appendSummarySize(java.lang.StringBuffer buffer, java.lang.String fieldName, int size)
Appends to thetoString
a size summary.void
appendSuper(java.lang.StringBuffer buffer, java.lang.String superToString)
Appends to thetoString
the superclass toString.void
appendToString(java.lang.StringBuffer buffer, java.lang.String toString)
Appends to thetoString
another toString.protected java.lang.String
getArrayEnd()
Gets the array end text.protected java.lang.String
getArraySeparator()
Gets the array separator text.protected java.lang.String
getArrayStart()
Gets the array start text.protected java.lang.String
getContentEnd()
Gets the content end text.protected java.lang.String
getContentStart()
Gets the content start text.protected java.lang.String
getFieldNameValueSeparator()
Gets the field name value separator text.protected java.lang.String
getFieldSeparator()
Gets the field separator text.protected java.lang.String
getNullText()
Gets the text to output whennull
found.static java.util.Map<java.lang.Object,java.lang.Object>
getRegistry()
Gets the registry of objects being traversed by thereflectionToString
methods in the current thread.protected java.lang.String
getShortClassName(java.lang.Class<?> cls)
Gets the short class name for a class.protected java.lang.String
getSizeEndText()
Gets the end text to output when aCollection
,Map
or array size is output.protected java.lang.String
getSizeStartText()
Gets the start text to output when aCollection
,Map
or array size is output.protected java.lang.String
getSummaryObjectEndText()
Gets the end text to output when anObject
is output in summary mode.protected java.lang.String
getSummaryObjectStartText()
Gets the start text to output when anObject
is output in summary mode.protected boolean
isArrayContentDetail()
Gets whether to output array content detail.protected boolean
isDefaultFullDetail()
Gets whether to use full detail when the caller doesn't specify.protected boolean
isFieldSeparatorAtEnd()
Gets whether the field separator should be added at the end of each buffer.protected boolean
isFieldSeparatorAtStart()
Gets whether the field separator should be added at the start of each buffer.protected boolean
isFullDetail(java.lang.Boolean fullDetailRequest)
Is this field to be output in full detail.protected boolean
isUseClassName()
Gets whether to use the class name.protected boolean
isUseFieldNames()
Gets whether to use the field names passed in.protected boolean
isUseIdentityHashCode()
Gets whether to use the identity hash code.protected boolean
isUseShortClassName()
Gets whether to output short or long class names.protected void
reflectionAppendArrayDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object array)
Appends to thetoString
the detail of an array type.protected void
removeLastFieldSeparator(java.lang.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(java.lang.String arrayEnd)
Sets the array end text.protected void
setArraySeparator(java.lang.String arraySeparator)
Sets the array separator text.protected void
setArrayStart(java.lang.String arrayStart)
Sets the array start text.protected void
setContentEnd(java.lang.String contentEnd)
Sets the content end text.protected void
setContentStart(java.lang.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(java.lang.String fieldNameValueSeparator)
Sets the field name value separator text.protected void
setFieldSeparator(java.lang.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(java.lang.String nullText)
Sets the text to output whennull
found.protected void
setSizeEndText(java.lang.String sizeEndText)
Sets the end text to output when aCollection
,Map
or array size is output.protected void
setSizeStartText(java.lang.String sizeStartText)
Sets the start text to output when aCollection
,Map
or array size is output.protected void
setSummaryObjectEndText(java.lang.String summaryObjectEndText)
Sets the end text to output when anObject
is output in summary mode.protected void
setSummaryObjectStartText(java.lang.String summaryObjectStartText)
Sets the start text to output when anObject
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.
-
-
-
Field Detail
-
DEFAULT_STYLE
public static final ToStringStyle DEFAULT_STYLE
The default toString style. Using thePerson
example fromToStringBuilder
, the output would look like this:Person@182f0db[name=John Doe,age=33,smoker=false]
-
MULTI_LINE_STYLE
public static final ToStringStyle MULTI_LINE_STYLE
The multi line toString style. Using thePerson
example fromToStringBuilder
, the output would look like this:Person@182f0db[ name=John Doe age=33 smoker=false ]
-
NO_FIELD_NAMES_STYLE
public static final ToStringStyle NO_FIELD_NAMES_STYLE
The no field names toString style. Using thePerson
example fromToStringBuilder
, the output would look like this:Person@182f0db[John Doe,33,false]
-
SHORT_PREFIX_STYLE
public static final ToStringStyle SHORT_PREFIX_STYLE
The short prefix toString style. Using thePerson
example fromToStringBuilder
, the output would look like this:Person[name=John Doe,age=33,smoker=false]
- Since:
- 2.1
-
SIMPLE_STYLE
public static final ToStringStyle SIMPLE_STYLE
The simple toString style. Using thePerson
example fromToStringBuilder
, the output would look like this:John Doe,33,false
-
NO_CLASS_NAME_STYLE
public static final ToStringStyle NO_CLASS_NAME_STYLE
The no class name toString style. Using thePerson
example fromToStringBuilder
, the output would look like this:[name=John Doe,age=33,smoker=false]
- Since:
- 3.4
-
JSON_STYLE
public static final ToStringStyle JSON_STYLE
The JSON toString style. Using thePerson
example fromToStringBuilder
, 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 anUnsupportedOperationException
if no field name is passed in while appending. Furthermore This ToStringStyle will only generate valid JSON if referenced objects also produce JSON when callingtoString()
on them.- Since:
- 3.4
- See Also:
- json.org
-
-
Method Detail
-
getRegistry
public static java.util.Map<java.lang.Object,java.lang.Object> getRegistry()
Gets the registry of objects being traversed by thereflectionToString
methods in the current thread.- Returns:
- Set the registry of objects being traversed
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean value)
Appends to thetoString
aboolean
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array, java.lang.Boolean fullDetail)
Appends to thetoString
aboolean
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to the toStringfullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, byte value)
Appends to thetoString
abyte
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array, java.lang.Boolean fullDetail)
Appends to thetoString
abyte
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to thetoString
fullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, char value)
Appends to thetoString
achar
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array, java.lang.Boolean fullDetail)
Appends to thetoString
achar
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to thetoString
fullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, double value)
Appends to thetoString
adouble
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array, java.lang.Boolean fullDetail)
Appends to thetoString
adouble
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to the toStringfullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, float value)
Appends to thetoString
afloat
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array, java.lang.Boolean fullDetail)
Appends to thetoString
afloat
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to the toStringfullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, int value)
Appends to thetoString
anint
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array, java.lang.Boolean fullDetail)
Appends to thetoString
anint
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to thetoString
fullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, long value)
Appends to the
toString
along
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array, java.lang.Boolean fullDetail)
Appends to thetoString
along
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to thetoString
fullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value, java.lang.Boolean fullDetail)
Appends to thetoString
anObject
value, printing the fulltoString
of theObject
passed in.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
fullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array, java.lang.Boolean fullDetail)
Appends to thetoString
anObject
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to the toStringfullDetail
-true
for detail,false
for summary info,null
for style decides
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, short value)
Appends to thetoString
ashort
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array, java.lang.Boolean fullDetail)
Appends to thetoString
ashort
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namearray
- the array to add to thetoString
fullDetail
-true
for detail,false
for summary info,null
for style decides
-
appendClassName
protected void appendClassName(java.lang.StringBuffer buffer, java.lang.Object object)
Appends to thetoString
the class name.- Parameters:
buffer
- theStringBuffer
to populateobject
- theObject
whose name to output
-
appendContentEnd
protected void appendContentEnd(java.lang.StringBuffer buffer)
Appends to thetoString
the content end.- Parameters:
buffer
- theStringBuffer
to populate
-
appendContentStart
protected void appendContentStart(java.lang.StringBuffer buffer)
Appends to thetoString
the content start.- Parameters:
buffer
- theStringBuffer
to populate
-
appendCyclicObject
protected void appendCyclicObject(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value)
Appends to thetoString
anObject
value that has been detected to participate in a cycle. This implementation will print the standard string value of the value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
, notnull
- Since:
- 2.2
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean value)
Appends to thetoString
aboolean
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array)
Appends to thetoString
the detail of aboolean
array.- Parameters:
buffer
- theStringBuffer
to 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 value)
Appends to thetoString
abyte
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array)
Appends to thetoString
the detail of abyte
array.- Parameters:
buffer
- theStringBuffer
to 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 value)
Appends to thetoString
achar
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array)
Appends to thetoString
the detail of achar
array.- Parameters:
buffer
- theStringBuffer
to 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, java.util.Collection<?> coll)
Appends to thetoString
aCollection
.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedcoll
- theCollection
to add to thetoString
, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, double value)
Appends to thetoString
adouble
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array)
Appends to thetoString
the detail of adouble
array.- Parameters:
buffer
- theStringBuffer
to 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 value)
Appends to thetoString
afloat
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array)
Appends to thetoString
the detail of afloat
array.- Parameters:
buffer
- theStringBuffer
to 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 value)
Appends to thetoString
anint
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, int i, java.lang.Object item)
Appends to thetoString
the detail of anObject
array item.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedi
- the array item index to additem
- the array item to add- Since:
- 3.11
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array)
Appends to thetoString
the detail of anint
array.- Parameters:
buffer
- theStringBuffer
to 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 value)
Appends to thetoString
along
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array)
Appends to thetoString
the detail of along
array.- Parameters:
buffer
- theStringBuffer
to 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, java.util.Map<?,?> map)
Appends to thetoString
aMap
.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedmap
- theMap
to add to thetoString
, notnull
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value)
Appends to thetoString
anObject
value, printing the full detail of theObject
.- Parameters:
buffer
- theStringBuffer
to 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)
Appends to thetoString
the detail of anObject
array.- Parameters:
buffer
- theStringBuffer
to 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 value)
Appends to thetoString
ashort
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
-
appendDetail
protected void appendDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array)
Appends to thetoString
the detail of ashort
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendEnd
public void appendEnd(java.lang.StringBuffer buffer, java.lang.Object object)
Appends to thetoString
the end of data indicator.- Parameters:
buffer
- theStringBuffer
to populateobject
- theObject
to build atoString
for.
-
appendFieldEnd
protected void appendFieldEnd(java.lang.StringBuffer buffer, java.lang.String fieldName)
Appends to thetoString
the field end.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appended
-
appendFieldSeparator
protected void appendFieldSeparator(java.lang.StringBuffer buffer)
Appends to thetoString
the field separator.- Parameters:
buffer
- theStringBuffer
to populate
-
appendFieldStart
protected void appendFieldStart(java.lang.StringBuffer buffer, java.lang.String fieldName)
Appends to thetoString
the field start.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name
-
appendIdentityHashCode
protected void appendIdentityHashCode(java.lang.StringBuffer buffer, java.lang.Object object)
Appends theSystem.identityHashCode(java.lang.Object)
.- Parameters:
buffer
- theStringBuffer
to populateobject
- theObject
whose id to output
-
appendInternal
protected void appendInternal(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value, boolean detail)
Appends to thetoString
anObject
, correctly interpreting its type.This method performs the main lookup by Class type to correctly route arrays,
Collection
s,Map
s andObjects
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
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
, notnull
detail
- output detail or not
-
appendNullText
protected void appendNullText(java.lang.StringBuffer buffer, java.lang.String fieldName)
Appends to thetoString
an indicator fornull
.The default indicator is
"<null>"
.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appended
-
appendStart
public void appendStart(java.lang.StringBuffer buffer, java.lang.Object object)
Appends to thetoString
the start of data indicator.- Parameters:
buffer
- theStringBuffer
to populateobject
- theObject
to build atoString
for
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array)
Appends to thetoString
a summary of aboolean
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array)
Appends to thetoString
a summary of abyte
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array)
Appends to thetoString
a summary of achar
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array)
Appends to thetoString
a summary of adouble
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array)
Appends to thetoString
a summary of afloat
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array)
Appends to thetoString
a summary of anint
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array)
Appends to thetoString
a summary of along
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value)
Appends to thetoString
anObject
value, printing a summary of theObject
.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array)
Appends to thetoString
a summary of anObject
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummary
protected void appendSummary(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array)
Appends to thetoString
a summary of ashort
array.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
-
appendSummarySize
protected void appendSummarySize(java.lang.StringBuffer buffer, java.lang.String fieldName, int size)
Appends to thetoString
a size summary.The size summary is used to summarize the contents of
Collection
s,Map
s and arrays.The output consists of a prefix, the passed in size and a suffix.
The default format is
"<size=n>"
.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedsize
- the size to append
-
appendSuper
public void appendSuper(java.lang.StringBuffer buffer, java.lang.String superToString)
Appends to thetoString
the superclass toString.NOTE: It assumes that the toString has been created from the same ToStringStyle.
A
null
superToString
is ignored.- Parameters:
buffer
- theStringBuffer
to populatesuperToString
- thesuper.toString()
- Since:
- 2.0
-
appendToString
public void appendToString(java.lang.StringBuffer buffer, java.lang.String toString)
Appends to thetoString
another toString.NOTE: It assumes that the toString has been created from the same ToStringStyle.
A
null
toString
is ignored.- Parameters:
buffer
- theStringBuffer
to populatetoString
- the additionaltoString
- Since:
- 2.0
-
getArrayEnd
protected java.lang.String getArrayEnd()
Gets the array end text.- Returns:
- the current array end text
-
getArraySeparator
protected java.lang.String getArraySeparator()
Gets the array separator text.- Returns:
- the current array separator text
-
getArrayStart
protected java.lang.String getArrayStart()
Gets the array start text.- Returns:
- the current array start text
-
getContentEnd
protected java.lang.String getContentEnd()
Gets the content end text.- Returns:
- the current content end text
-
getContentStart
protected java.lang.String getContentStart()
Gets the content start text.- Returns:
- the current content start text
-
getFieldNameValueSeparator
protected java.lang.String getFieldNameValueSeparator()
Gets the field name value separator text.- Returns:
- the current field name value separator text
-
getFieldSeparator
protected java.lang.String getFieldSeparator()
Gets the field separator text.- Returns:
- the current field separator text
-
getNullText
protected java.lang.String getNullText()
Gets the text to output whennull
found.- Returns:
- the current text to output when null found
-
getShortClassName
protected java.lang.String getShortClassName(java.lang.Class<?> cls)
Gets the short class name for a class.The short class name is the class name excluding the package name.
- Parameters:
cls
- theClass
to get the short name of- Returns:
- the short name
-
getSizeEndText
protected java.lang.String getSizeEndText()
Gets the end text to output when aCollection
,Map
or array size is output.This is output after the size value.
- Returns:
- the current end of size text
-
getSizeStartText
protected java.lang.String getSizeStartText()
Gets the start text to output when aCollection
,Map
or array size is output.This is output before the size value.
- Returns:
- the current start of size text
-
getSummaryObjectEndText
protected java.lang.String getSummaryObjectEndText()
Gets the end text to output when anObject
is output in summary mode.This is output after the size value.
- Returns:
- the current end of summary text
-
getSummaryObjectStartText
protected java.lang.String getSummaryObjectStartText()
Gets the start text to output when anObject
is output in summary mode.This is output before the size value.
- Returns:
- the current start of summary text
-
isArrayContentDetail
protected boolean isArrayContentDetail()
Gets whether to output array content detail.- Returns:
- the current array content detail setting
-
isDefaultFullDetail
protected boolean isDefaultFullDetail()
Gets whether to use full detail when the caller doesn't specify.- Returns:
- the current defaultFullDetail flag
-
isFieldSeparatorAtEnd
protected boolean isFieldSeparatorAtEnd()
Gets whether the field separator should be added at the end of each buffer.- Returns:
- fieldSeparatorAtEnd flag
- Since:
- 2.0
-
isFieldSeparatorAtStart
protected boolean isFieldSeparatorAtStart()
Gets whether the field separator should be added at the start of each buffer.- Returns:
- the fieldSeparatorAtStart flag
- Since:
- 2.0
-
isFullDetail
protected boolean isFullDetail(java.lang.Boolean fullDetailRequest)
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 (
true
), but a subclass might ignore that and always returnfalse
. The calling code may pass innull
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
-
isUseClassName
protected boolean isUseClassName()
Gets whether to use the class name.- Returns:
- the current useClassName flag
-
isUseFieldNames
protected boolean isUseFieldNames()
Gets whether to use the field names passed in.- Returns:
- the current useFieldNames flag
-
isUseIdentityHashCode
protected boolean isUseIdentityHashCode()
Gets whether to use the identity hash code.- Returns:
- the current useIdentityHashCode flag
-
isUseShortClassName
protected boolean isUseShortClassName()
Gets whether to output short or long class names.- Returns:
- the current useShortClassName flag
- Since:
- 2.0
-
reflectionAppendArrayDetail
protected void reflectionAppendArrayDetail(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object array)
Appends to thetoString
the detail of an array type.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field name, typically not used as already appendedarray
- the array to add to thetoString
, notnull
- Since:
- 2.0
-
removeLastFieldSeparator
protected void removeLastFieldSeparator(java.lang.StringBuffer buffer)
Remove the last field separator from the buffer.- Parameters:
buffer
- theStringBuffer
to populate- Since:
- 2.0
-
setArrayContentDetail
protected void setArrayContentDetail(boolean arrayContentDetail)
Sets whether to output array content detail.- Parameters:
arrayContentDetail
- the new arrayContentDetail flag
-
setArrayEnd
protected void setArrayEnd(java.lang.String arrayEnd)
Sets the array end text.null
is accepted, but will be converted to an empty String.- Parameters:
arrayEnd
- the new array end text
-
setArraySeparator
protected void setArraySeparator(java.lang.String arraySeparator)
Sets the array separator text.null
is accepted, but will be converted to an empty String.- Parameters:
arraySeparator
- the new array separator text
-
setArrayStart
protected void setArrayStart(java.lang.String arrayStart)
Sets the array start text.null
is accepted, but will be converted to an empty String.- Parameters:
arrayStart
- the new array start text
-
setContentEnd
protected void setContentEnd(java.lang.String contentEnd)
Sets the content end text.null
is accepted, but will be converted to an empty String.- Parameters:
contentEnd
- the new content end text
-
setContentStart
protected void setContentStart(java.lang.String contentStart)
Sets the content start text.null
is accepted, but will be converted to an empty String.- Parameters:
contentStart
- the new content start text
-
setDefaultFullDetail
protected void setDefaultFullDetail(boolean defaultFullDetail)
Sets whether to use full detail when the caller doesn't specify.- Parameters:
defaultFullDetail
- the new defaultFullDetail flag
-
setFieldNameValueSeparator
protected void setFieldNameValueSeparator(java.lang.String fieldNameValueSeparator)
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
-
setFieldSeparator
protected void setFieldSeparator(java.lang.String fieldSeparator)
Sets the field separator text.null
is accepted, but will be converted to an empty String.- Parameters:
fieldSeparator
- the new field separator text
-
setFieldSeparatorAtEnd
protected void setFieldSeparatorAtEnd(boolean fieldSeparatorAtEnd)
Sets whether the field separator should be added at the end of each buffer.- Parameters:
fieldSeparatorAtEnd
- the fieldSeparatorAtEnd flag- Since:
- 2.0
-
setFieldSeparatorAtStart
protected void setFieldSeparatorAtStart(boolean fieldSeparatorAtStart)
Sets whether the field separator should be added at the start of each buffer.- Parameters:
fieldSeparatorAtStart
- the fieldSeparatorAtStart flag- Since:
- 2.0
-
setNullText
protected void setNullText(java.lang.String nullText)
Sets the text to output whennull
found.null
is accepted, but will be converted to an empty String.- Parameters:
nullText
- the new text to output when null found
-
setSizeEndText
protected void setSizeEndText(java.lang.String sizeEndText)
Sets the end text to output when aCollection
,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
-
setSizeStartText
protected void setSizeStartText(java.lang.String sizeStartText)
Sets the start text to output when aCollection
,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
-
setSummaryObjectEndText
protected void setSummaryObjectEndText(java.lang.String summaryObjectEndText)
Sets the end text to output when anObject
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
-
setSummaryObjectStartText
protected void setSummaryObjectStartText(java.lang.String summaryObjectStartText)
Sets the start text to output when anObject
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
-
setUseClassName
protected void setUseClassName(boolean useClassName)
Sets whether to use the class name.- Parameters:
useClassName
- the new useClassName flag
-
setUseFieldNames
protected void setUseFieldNames(boolean useFieldNames)
Sets whether to use the field names passed in.- Parameters:
useFieldNames
- the new useFieldNames flag
-
setUseIdentityHashCode
protected void setUseIdentityHashCode(boolean useIdentityHashCode)
Sets whether to use the identity hash code.- Parameters:
useIdentityHashCode
- the new useIdentityHashCode flag
-
setUseShortClassName
protected void setUseShortClassName(boolean useShortClassName)
Sets whether to output short or long class names.- Parameters:
useShortClassName
- the new useShortClassName flag- Since:
- 2.0
-
-