Class ToStringStyle
- java.lang.Object
-
- org.apache.commons.lang.builder.ToStringStyle
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
StandardToStringStyle
@Deprecated(since="2021-04-30") public abstract class ToStringStyle extends java.lang.Object implements java.io.Serializable
Deprecated.Commons Lang 2 is in maintenance mode. Commons Lang 3 should be used instead.Controls
String
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, theStandardToStringStyle
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
Deprecated.The default toString style.static ToStringStyle
MULTI_LINE_STYLE
Deprecated.The multi line toString style.static ToStringStyle
NO_FIELD_NAMES_STYLE
Deprecated.The no field names toString style.static ToStringStyle
SHORT_PREFIX_STYLE
Deprecated.The short prefix toString style.static ToStringStyle
SIMPLE_STYLE
Deprecated.The simple toString style.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean value)
Deprecated.Append to thetoString
aboolean
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
aboolean
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, byte value)
Deprecated.Append to thetoString
abyte
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
abyte
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, char value)
Deprecated.Append to thetoString
achar
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
achar
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, double value)
Deprecated.Append to thetoString
adouble
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
adouble
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, float value)
Deprecated.Append to thetoString
afloat
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
afloat
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, int value)
Deprecated.Append to thetoString
anint
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
anint
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, long value)
Deprecated.Append to thetoString
along
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
along
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, short value)
Deprecated.Append to thetoString
ashort
value.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
ashort
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
anObject
array.void
append(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value, java.lang.Boolean fullDetail)
Deprecated.Append to thetoString
anObject
value, printing the fulltoString
of theObject
passed in.void
appendEnd(java.lang.StringBuffer buffer, java.lang.Object object)
Deprecated.Append to thetoString
the end of data indicator.void
appendStart(java.lang.StringBuffer buffer, java.lang.Object object)
Deprecated.Append to thetoString
the start of data indicator.void
appendSuper(java.lang.StringBuffer buffer, java.lang.String superToString)
Deprecated.Append to thetoString
the superclass toString.void
appendToString(java.lang.StringBuffer buffer, java.lang.String toString)
Deprecated.Append to thetoString
another toString.
-
-
-
Field Detail
-
DEFAULT_STYLE
public static final ToStringStyle 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
public static final ToStringStyle 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
public static final ToStringStyle 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
public static final ToStringStyle 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
public static final ToStringStyle SIMPLE_STYLE
Deprecated.The simple toString style. Using the Using thePerson
example fromToStringBuilder
, the output would look like this:John Doe,33,false
-
-
Method Detail
-
appendSuper
public void appendSuper(java.lang.StringBuffer buffer, java.lang.String superToString)
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
public void appendToString(java.lang.StringBuffer buffer, java.lang.String toString)
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
public void appendStart(java.lang.StringBuffer buffer, java.lang.Object object)
Deprecated.Append to the
toString
the start of data indicator.- Parameters:
buffer
- theStringBuffer
to populateobject
- theObject
to build atoString
for
-
appendEnd
public void appendEnd(java.lang.StringBuffer buffer, java.lang.Object object)
Deprecated.Append to the
toString
the end of data indicator.- Parameters:
buffer
- theStringBuffer
to populateobject
- theObject
to build atoString
for.
-
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, long value)
Deprecated.Append 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, int value)
Deprecated.Append to the
toString
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, short value)
Deprecated.Append to the
toString
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, byte value)
Deprecated.Append to the
toString
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, char value)
Deprecated.Append to the
toString
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, double value)
Deprecated.Append to the
toString
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, float value)
Deprecated.Append to the
toString
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, boolean value)
Deprecated.Append to the
toString
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, java.lang.Object[] array, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array, java.lang.Boolean fullDetail)
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
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array, java.lang.Boolean fullDetail)
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
-
-