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 ToStringStyleDeprecated.The default toString style.static final ToStringStyleDeprecated.The multi line toString style.static final ToStringStyleDeprecated.The no field names toString style.static final ToStringStyleDeprecated.The short prefix toString style.static final ToStringStyleDeprecated.The simple toString style. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(StringBuffer buffer, String fieldName, boolean value) Deprecated.Append to thetoStringabooleanvalue.voidappend(StringBuffer buffer, String fieldName, boolean[] array, Boolean fullDetail) Deprecated.Append to thetoStringabooleanarray.voidappend(StringBuffer buffer, String fieldName, byte value) Deprecated.Append to thetoStringabytevalue.voidappend(StringBuffer buffer, String fieldName, byte[] array, Boolean fullDetail) Deprecated.Append to thetoStringabytearray.voidappend(StringBuffer buffer, String fieldName, char value) Deprecated.Append to thetoStringacharvalue.voidappend(StringBuffer buffer, String fieldName, char[] array, Boolean fullDetail) Deprecated.Append to thetoStringachararray.voidappend(StringBuffer buffer, String fieldName, double value) Deprecated.Append to thetoStringadoublevalue.voidappend(StringBuffer buffer, String fieldName, double[] array, Boolean fullDetail) Deprecated.Append to thetoStringadoublearray.voidappend(StringBuffer buffer, String fieldName, float value) Deprecated.Append to thetoStringafloatvalue.voidappend(StringBuffer buffer, String fieldName, float[] array, Boolean fullDetail) Deprecated.Append to thetoStringafloatarray.voidappend(StringBuffer buffer, String fieldName, int value) Deprecated.Append to thetoStringanintvalue.voidappend(StringBuffer buffer, String fieldName, int[] array, Boolean fullDetail) Deprecated.Append to thetoStringanintarray.voidappend(StringBuffer buffer, String fieldName, long value) Deprecated.Append to thetoStringalongvalue.voidappend(StringBuffer buffer, String fieldName, long[] array, Boolean fullDetail) Deprecated.Append to thetoStringalongarray.voidappend(StringBuffer buffer, String fieldName, short value) Deprecated.Append to thetoStringashortvalue.voidappend(StringBuffer buffer, String fieldName, short[] array, Boolean fullDetail) Deprecated.Append to thetoStringashortarray.voidappend(StringBuffer buffer, String fieldName, Object[] array, Boolean fullDetail) Deprecated.Append to thetoStringanObjectarray.voidappend(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail) Deprecated.Append to thetoStringanObjectvalue, printing the fulltoStringof theObjectpassed in.voidappendEnd(StringBuffer buffer, Object object) Deprecated.Append to thetoStringthe end of data indicator.voidappendStart(StringBuffer buffer, Object object) Deprecated.Append to thetoStringthe start of data indicator.voidappendSuper(StringBuffer buffer, String superToString) Deprecated.Append to thetoStringthe superclass toString.voidappendToString(StringBuffer buffer, String toString) Deprecated.Append to thetoStringanother toString.
-
Field Details
-
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
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
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
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
Deprecated.The simple toString style. Using the Using thePersonexample fromToStringBuilder, the output would look like this:John Doe,33,false
-
-
Method Details
-
appendSuper
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
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
Deprecated.Append to the
toStringthe start of data indicator.- Parameters:
buffer- theStringBufferto populateobject- theObjectto build atoStringfor
-
appendEnd
Deprecated.Append to the
toStringthe end of data indicator.- Parameters:
buffer- theStringBufferto populateobject- theObjectto build atoStringfor.
-
append
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
Deprecated.Append to the
toStringalongvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
Deprecated.Append to the
toStringanintvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
Deprecated.Append to the
toStringashortvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
Deprecated.Append to the
toStringabytevalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
Deprecated.Append to the
toStringacharvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
Deprecated.Append to the
toStringadoublevalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
Deprecated.Append to the
toStringafloatvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
Deprecated.Append to the
toStringabooleanvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
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
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
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
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
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
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
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
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
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
-