Class ToStringStyle
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
StandardToStringStyle
Controls String
formatting for ToStringBuilder
.
The main public interface is always via ToStringBuilder
.
These classes are intended to be used as Singletons
.
There is no need to instantiate a new style each time. A program
will generally use one of the predefined constants on this class.
Alternatively, the StandardToStringStyle
class can be used
to set the individual settings. Thus most styles can be achieved
without subclassing.
If required, a subclass can override as many or as few of the
methods as it requires. Each object type (from boolean
to long
to Object
to int[]
) has
its own methods to output it. Most have two versions, detail and summary.
For example, the detail version of the array based methods will output the whole array, whereas the summary method will just output the array length.
If you want to format the output of certain objects, such as dates, you must create a subclass and override a method.
public class MyStyle extends ToStringStyle { protected void appendDetail(StringBuffer buffer, String fieldName, Object value) { if (value instanceof Date) { value = new SimpleDateFormat("yyyy-MM-dd").format(value); } buffer.append(value); } }
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ToStringStyle
Deprecated.The default toString style.static final ToStringStyle
Deprecated.The multi line toString style.static final ToStringStyle
Deprecated.The no field names toString style.static final ToStringStyle
Deprecated.The short prefix toString style.static final ToStringStyle
Deprecated.The simple toString style. -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(StringBuffer buffer, String fieldName, boolean value) Deprecated.Append to thetoString
aboolean
value.void
append
(StringBuffer buffer, String fieldName, boolean[] array, Boolean fullDetail) Deprecated.Append to thetoString
aboolean
array.void
append
(StringBuffer buffer, String fieldName, byte value) Deprecated.Append to thetoString
abyte
value.void
append
(StringBuffer buffer, String fieldName, byte[] array, Boolean fullDetail) Deprecated.Append to thetoString
abyte
array.void
append
(StringBuffer buffer, String fieldName, char value) Deprecated.Append to thetoString
achar
value.void
append
(StringBuffer buffer, String fieldName, char[] array, Boolean fullDetail) Deprecated.Append to thetoString
achar
array.void
append
(StringBuffer buffer, String fieldName, double value) Deprecated.Append to thetoString
adouble
value.void
append
(StringBuffer buffer, String fieldName, double[] array, Boolean fullDetail) Deprecated.Append to thetoString
adouble
array.void
append
(StringBuffer buffer, String fieldName, float value) Deprecated.Append to thetoString
afloat
value.void
append
(StringBuffer buffer, String fieldName, float[] array, Boolean fullDetail) Deprecated.Append to thetoString
afloat
array.void
append
(StringBuffer buffer, String fieldName, int value) Deprecated.Append to thetoString
anint
value.void
append
(StringBuffer buffer, String fieldName, int[] array, Boolean fullDetail) Deprecated.Append to thetoString
anint
array.void
append
(StringBuffer buffer, String fieldName, long value) Deprecated.Append to thetoString
along
value.void
append
(StringBuffer buffer, String fieldName, long[] array, Boolean fullDetail) Deprecated.Append to thetoString
along
array.void
append
(StringBuffer buffer, String fieldName, short value) Deprecated.Append to thetoString
ashort
value.void
append
(StringBuffer buffer, String fieldName, short[] array, Boolean fullDetail) Deprecated.Append to thetoString
ashort
array.void
append
(StringBuffer buffer, String fieldName, Object[] array, Boolean fullDetail) Deprecated.Append to thetoString
anObject
array.void
append
(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail) Deprecated.Append to thetoString
anObject
value, printing the fulltoString
of theObject
passed in.void
appendEnd
(StringBuffer buffer, Object object) Deprecated.Append to thetoString
the end of data indicator.void
appendStart
(StringBuffer buffer, Object object) Deprecated.Append to thetoString
the start of data indicator.void
appendSuper
(StringBuffer buffer, String superToString) Deprecated.Append to thetoString
the superclass toString.void
appendToString
(StringBuffer buffer, String toString) Deprecated.Append to thetoString
another toString.
-
Field Details
-
DEFAULT_STYLE
Deprecated.The default toString style. Using the Using thePerson
example fromToStringBuilder
, the output would look like this:Person@182f0db[name=John Doe,age=33,smoker=false]
-
MULTI_LINE_STYLE
Deprecated.The multi line toString style. Using the Using thePerson
example fromToStringBuilder
, the output would look like this:Person@182f0db[ name=John Doe age=33 smoker=false ]
-
NO_FIELD_NAMES_STYLE
Deprecated.The no field names toString style. Using the Using thePerson
example fromToStringBuilder
, the output would look like this:Person@182f0db[John Doe,33,false]
-
SHORT_PREFIX_STYLE
Deprecated.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
Deprecated.The simple toString style. Using the Using thePerson
example fromToStringBuilder
, the output would look like this:John Doe,33,false
-
-
Method Details
-
appendSuper
Deprecated.Append to the
toString
the superclass toString.NOTE: It assumes that the toString has been created from the same ToStringStyle.
A
null
superToString
is ignored.- Parameters:
buffer
- theStringBuffer
to populatesuperToString
- thesuper.toString()
- Since:
- 2.0
-
appendToString
Deprecated.Append to the
toString
another toString.NOTE: It assumes that the toString has been created from the same ToStringStyle.
A
null
toString
is ignored.- Parameters:
buffer
- theStringBuffer
to populatetoString
- the additionaltoString
- Since:
- 2.0
-
appendStart
Deprecated.Append to the
toString
the start of data indicator.- Parameters:
buffer
- theStringBuffer
to populateobject
- theObject
to build atoString
for
-
appendEnd
Deprecated.Append to the
toString
the end of data indicator.- Parameters:
buffer
- theStringBuffer
to populateobject
- theObject
to build atoString
for.
-
append
Deprecated.Append to the
toString
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
Deprecated.Append to the
toString
along
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
Deprecated.Append to the
toString
anint
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
Deprecated.Append to the
toString
ashort
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
Deprecated.Append to the
toString
abyte
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
Deprecated.Append to the
toString
achar
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
Deprecated.Append to the
toString
adouble
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
Deprecated.Append to the
toString
afloat
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
Deprecated.Append to the
toString
aboolean
value.- Parameters:
buffer
- theStringBuffer
to populatefieldName
- the field namevalue
- the value to add to thetoString
-
append
Deprecated.Append to the
toString
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
Deprecated.Append to the
toString
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
Deprecated.Append to the
toString
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
Deprecated.Append to the
toString
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
-
append
Deprecated.Append to the
toString
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
Deprecated.Append to the
toString
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
Deprecated.Append to the
toString
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
Deprecated.Append to the
toString
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
Deprecated.Append to the
toString
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
-