-
- All Implemented Interfaces:
-
java.io.Serializable
public abstract class ToStringStyle implements Serializable
Controls
Stringformatting for ToStringBuilder. 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
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); } }
-
-
Field Summary
Fields Modifier and Type Field Description public final static ToStringStyleDEFAULT_STYLEpublic final static ToStringStyleMULTI_LINE_STYLEpublic final static ToStringStyleNO_FIELD_NAMES_STYLEpublic final static ToStringStyleSHORT_PREFIX_STYLEpublic final static ToStringStyleSIMPLE_STYLE
-
Method Summary
Modifier and Type Method Description voidappendSuper(StringBuffer buffer, String superToString)Append to the toStringthe superclass toString.voidappendToString(StringBuffer buffer, String toString)Append to the toStringanother toString.voidappendStart(StringBuffer buffer, Object object)Append to the toStringthe start of data indicator.voidappendEnd(StringBuffer buffer, Object object)Append to the toStringthe end of data indicator.voidappend(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail)Append to the toStringanObjectvalue, printing the fulltoStringof theObjectpassed in.voidappend(StringBuffer buffer, String fieldName, long value)Append to the toStringalongvalue.voidappend(StringBuffer buffer, String fieldName, int value)Append to the toStringanintvalue.voidappend(StringBuffer buffer, String fieldName, short value)Append to the toStringashortvalue.voidappend(StringBuffer buffer, String fieldName, byte value)Append to the toStringabytevalue.voidappend(StringBuffer buffer, String fieldName, char value)Append to the toStringacharvalue.voidappend(StringBuffer buffer, String fieldName, double value)Append to the toStringadoublevalue.voidappend(StringBuffer buffer, String fieldName, float value)Append to the toStringafloatvalue.voidappend(StringBuffer buffer, String fieldName, boolean value)Append to the toStringabooleanvalue.voidappend(StringBuffer buffer, String fieldName, Array<Object> array, Boolean fullDetail)Append to the toStringanObjectarray.voidappend(StringBuffer buffer, String fieldName, Array<long> array, Boolean fullDetail)Append to the toStringalongarray.voidappend(StringBuffer buffer, String fieldName, Array<int> array, Boolean fullDetail)Append to the toStringanintarray.voidappend(StringBuffer buffer, String fieldName, Array<short> array, Boolean fullDetail)Append to the toStringashortarray.voidappend(StringBuffer buffer, String fieldName, Array<byte> array, Boolean fullDetail)Append to the toStringabytearray.voidappend(StringBuffer buffer, String fieldName, Array<char> array, Boolean fullDetail)Append to the toStringachararray.voidappend(StringBuffer buffer, String fieldName, Array<double> array, Boolean fullDetail)Append to the toStringadoublearray.voidappend(StringBuffer buffer, String fieldName, Array<float> array, Boolean fullDetail)Append to the toStringafloatarray.voidappend(StringBuffer buffer, String fieldName, Array<boolean> array, Boolean fullDetail)Append to the toStringabooleanarray.-
-
Method Detail
-
appendSuper
void appendSuper(StringBuffer buffer, String superToString)
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()
-
appendToString
void appendToString(StringBuffer buffer, String toString)
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
-
appendStart
void appendStart(StringBuffer buffer, Object object)
Append to the
toStringthe start of data indicator.- Parameters:
buffer- theStringBufferto populateobject- theObjectto build atoStringfor
-
appendEnd
void appendEnd(StringBuffer buffer, Object object)
Append to the
toStringthe end of data indicator.- Parameters:
buffer- theStringBufferto populateobject- theObjectto build atoStringfor.
-
append
void append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, long value)
Append to the
toStringalongvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
void append(StringBuffer buffer, String fieldName, int value)
Append to the
toStringanintvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
void append(StringBuffer buffer, String fieldName, short value)
Append to the
toStringashortvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
void append(StringBuffer buffer, String fieldName, byte value)
Append to the
toStringabytevalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
void append(StringBuffer buffer, String fieldName, char value)
Append to the
toStringacharvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
void append(StringBuffer buffer, String fieldName, double value)
Append to the
toStringadoublevalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
void append(StringBuffer buffer, String fieldName, float value)
Append to the
toStringafloatvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
void append(StringBuffer buffer, String fieldName, boolean value)
Append to the
toStringabooleanvalue.- Parameters:
buffer- theStringBufferto populatefieldName- the field namevalue- the value to add to thetoString
-
append
void append(StringBuffer buffer, String fieldName, Array<Object> array, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, Array<long> array, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, Array<int> array, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, Array<short> array, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, Array<byte> array, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, Array<char> array, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, Array<double> array, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, Array<float> array, Boolean fullDetail)
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
void append(StringBuffer buffer, String fieldName, Array<boolean> array, Boolean fullDetail)
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
-
-
-
-