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.SerializableDeprecated.Commons Lang 2 is in maintenance mode. Commons Lang 3 should be used instead.Controls
Stringformatting 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, theStandardToStringStyleclass 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
booleantolongtoObjecttoint[]) 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 ToStringStyleDEFAULT_STYLEDeprecated.The default toString style.static ToStringStyleMULTI_LINE_STYLEDeprecated.The multi line toString style.static ToStringStyleNO_FIELD_NAMES_STYLEDeprecated.The no field names toString style.static ToStringStyleSHORT_PREFIX_STYLEDeprecated.The short prefix toString style.static ToStringStyleSIMPLE_STYLEDeprecated.The simple toString style. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean value)Deprecated.Append to thetoStringabooleanvalue.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringabooleanarray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, byte value)Deprecated.Append to thetoStringabytevalue.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringabytearray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, char value)Deprecated.Append to thetoStringacharvalue.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringachararray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, double value)Deprecated.Append to thetoStringadoublevalue.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringadoublearray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, float value)Deprecated.Append to thetoStringafloatvalue.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringafloatarray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, int value)Deprecated.Append to thetoStringanintvalue.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringanintarray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, long value)Deprecated.Append to thetoStringalongvalue.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringalongarray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, short value)Deprecated.Append to thetoStringashortvalue.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringashortarray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object[] array, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringanObjectarray.voidappend(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value, java.lang.Boolean fullDetail)Deprecated.Append to thetoStringanObjectvalue, printing the fulltoStringof theObjectpassed in.voidappendEnd(java.lang.StringBuffer buffer, java.lang.Object object)Deprecated.Append to thetoStringthe end of data indicator.voidappendStart(java.lang.StringBuffer buffer, java.lang.Object object)Deprecated.Append to thetoStringthe start of data indicator.voidappendSuper(java.lang.StringBuffer buffer, java.lang.String superToString)Deprecated.Append to thetoStringthe superclass toString.voidappendToString(java.lang.StringBuffer buffer, java.lang.String toString)Deprecated.Append to thetoStringanother toString. 
 - 
 
- 
- 
Field Detail
- 
DEFAULT_STYLE
public static final ToStringStyle DEFAULT_STYLE
Deprecated.The default toString style. Using the Using thePersonexample 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 thePersonexample 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 thePersonexample 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 thePersonexample 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 thePersonexample 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
toStringthe superclass toString.NOTE: It assumes that the toString has been created from the same ToStringStyle.
A
nullsuperToStringis ignored.- Parameters:
 buffer- theStringBufferto populatesuperToString- thesuper.toString()- Since:
 - 2.0
 
 
- 
appendToString
public void appendToString(java.lang.StringBuffer buffer, java.lang.String toString)Deprecated.Append to the
toStringanother toString.NOTE: It assumes that the toString has been created from the same ToStringStyle.
A
nulltoStringis ignored.- Parameters:
 buffer- theStringBufferto populatetoString- the additionaltoString- Since:
 - 2.0
 
 
- 
appendStart
public void appendStart(java.lang.StringBuffer buffer, java.lang.Object object)Deprecated.Append to the
toStringthe start of data indicator.- Parameters:
 buffer- theStringBufferto populateobject- theObjectto build atoStringfor
 
- 
appendEnd
public void appendEnd(java.lang.StringBuffer buffer, java.lang.Object object)Deprecated.Append to the
toStringthe end of data indicator.- Parameters:
 buffer- theStringBufferto populateobject- theObjectto build atoStringfor.
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, java.lang.Object value, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringanObjectvalue, printing the fulltoStringof theObjectpassed in.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, long value)Deprecated.Append to the
toStringalongvalue.- Parameters:
 buffer- theStringBufferto 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
toStringanintvalue.- Parameters:
 buffer- theStringBufferto 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
toStringashortvalue.- Parameters:
 buffer- theStringBufferto 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
toStringabytevalue.- Parameters:
 buffer- theStringBufferto 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
toStringacharvalue.- Parameters:
 buffer- theStringBufferto 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
toStringadoublevalue.- Parameters:
 buffer- theStringBufferto 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
toStringafloatvalue.- Parameters:
 buffer- theStringBufferto 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
toStringabooleanvalue.- Parameters:
 buffer- theStringBufferto 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
toStringanObjectarray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to the toStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, long[] array, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringalongarray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to thetoStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, int[] array, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringanintarray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to thetoStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, short[] array, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringashortarray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to thetoStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, byte[] array, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringabytearray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to thetoStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, char[] array, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringachararray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to thetoStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, double[] array, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringadoublearray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to the toStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, float[] array, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringafloatarray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to the toStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
- 
append
public void append(java.lang.StringBuffer buffer, java.lang.String fieldName, boolean[] array, java.lang.Boolean fullDetail)Deprecated.Append to the
toStringabooleanarray.- Parameters:
 buffer- theStringBufferto populatefieldName- the field namearray- the array to add to the toStringfullDetail-truefor detail,falsefor summary info,nullfor style decides
 
 - 
 
 -