Package 

Class ToStringStyle

  • All Implemented Interfaces:
    java.io.Serializable

    
    public abstract class ToStringStyle
     implements Serializable
                        

    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 booleanto 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);
      }
    }
    
    • Method Detail

      • appendSuper

         void appendSuper(StringBuffer buffer, String superToString)

        Append to the toString the superclass toString.

        NOTE: It assumes that the toString has been created from the same ToStringStyle.

        A nullsuperToString is ignored.

        Parameters:
        buffer - the StringBuffer to populate
        superToString - the super.toString()
      • appendToString

         void appendToString(StringBuffer buffer, String toString)

        Append to the toString another toString.

        NOTE: It assumes that the toString has been created from the same ToStringStyle.

        A nulltoString is ignored.

        Parameters:
        buffer - the StringBuffer to populate
        toString - the additional toString
      • appendStart

         void appendStart(StringBuffer buffer, Object object)

        Append to the toString the start of data indicator.

        Parameters:
        buffer - the StringBuffer to populate
        object - the Object to build a toString for
      • appendEnd

         void appendEnd(StringBuffer buffer, Object object)

        Append to the toString the end of data indicator.

        Parameters:
        buffer - the StringBuffer to populate
        object - the Object to build atoString for.
      • append

         void append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail)

        Append to the toString an Objectvalue, printing the full toString of theObject passed in.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, long value)

        Append to the toString a longvalue.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
      • append

         void append(StringBuffer buffer, String fieldName, int value)

        Append to the toString an intvalue.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
      • append

         void append(StringBuffer buffer, String fieldName, short value)

        Append to the toString a shortvalue.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
      • append

         void append(StringBuffer buffer, String fieldName, byte value)

        Append to the toString a bytevalue.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
      • append

         void append(StringBuffer buffer, String fieldName, char value)

        Append to the toString a charvalue.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
      • append

         void append(StringBuffer buffer, String fieldName, double value)

        Append to the toString a doublevalue.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
      • append

         void append(StringBuffer buffer, String fieldName, float value)

        Append to the toString a floatvalue.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
      • append

         void append(StringBuffer buffer, String fieldName, boolean value)

        Append to the toString a booleanvalue.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
      • append

         void append(StringBuffer buffer, String fieldName, Array<Object> array, Boolean fullDetail)

        Append to the toString an Objectarray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, Array<long> array, Boolean fullDetail)

        Append to the toString a longarray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, Array<int> array, Boolean fullDetail)

        Append to the toString an intarray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, Array<short> array, Boolean fullDetail)

        Append to the toString a shortarray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, Array<byte> array, Boolean fullDetail)

        Append to the toString a bytearray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, Array<char> array, Boolean fullDetail)

        Append to the toString a chararray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, Array<double> array, Boolean fullDetail)

        Append to the toString a doublearray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, Array<float> array, Boolean fullDetail)

        Append to the toString a floatarray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides
      • append

         void append(StringBuffer buffer, String fieldName, Array<boolean> array, Boolean fullDetail)

        Append to the toString a booleanarray.

        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, falsefor summary info, null for style decides