Controls String
formatting for {@link org.apache.commons.lang3.builder.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 {@link org.apache.commons.lang3.builder.StandardToStringStyle} class can be usedto 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(StringBuilder buffer, String fieldName, Object value) { if (value instanceof Date) { value = new SimpleDateFormat("yyyy-MM-dd").format(value); } buffer.append(value); } }@version $Id: ToStringStyle.java 1091066 2011-04-11 13:30:11Z mbenson $ @since 1.0
|
|