Appendable.javaAPI DocExample2432Mon Apr 03 15:48:14 BST 2000tuning.stringconvert


public interface Appendable
Classes which implement this interface can be appended directly to a StringBuffer without first having to create a string representation.

This allows the elimination of intermediate strings when creating a string representation of the object for display purposes. This is not the same as Serializable - this is for human readable display purposes. It is the same as the call to toString(), but appended to StringBuffers without the intermediate String being created.

Any class which implements this should probably also override its toString() method to something like

public String toString()
StringBuffer s = new StringBuffer();
return s.toString();

And may also want to use the AppenderHelper class for any internal objects

in the appendTo method. This will cut down on extraneous string production. The rationale is that string production is seriously overdone, and the reduction of unnecessary string creation is more likely to improve performance than the overheads in the above call (especially as the AppenderHelper class is much faster than StringBuffer in appending most data types).

Fields Summary
Constructors Summary
Methods Summary
public voidappendTo(java.lang.StringBuffer s, int depth)
Appends a representation of this onto the string buffer s.

The depth parameter specifies the depth of the representation. A value of zero means that the string representation should be that given by the Object.toString() method, i.e. the class name, an "@" character, followed by the hash code of this object (the AppenderHelper.appendDepth0To() method does this efficiently).

A value of 1 corresponds to the object being represented in its standard way, but any embedded objects that are represented are displayed as depth zero objects (for example a collection could be square brackets surrounding comma separated level zero representations of all its elements).

s the string buffer to append this to.
depth the depth of the respresentation.