You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephen Colebourne <st...@hotmail.com> on 2002/09/07 00:53:49 UTC

[lang] ToStringBuilder

I have checked into the lang _sandbox_ a ToStringBuilder, along the lines of
HashCodeBuilder.

 * <code>ToString</code> generation routine.
 * <p>
 * This class enables a good toString to be built for any class. This class
aims
 * to simplify the process by:
 * <ul>
 * <li>allowing field names
 * <li>handling all types consistently
 * <li>handling nulls consistently
 * <li>outputting arrays in the same way as Lists
 * <li>enabling the detail level to be controlled for objects and
collections
 * </ul>
 * <p>
 * To use this class write code as follows:
 * <code>
 * public class Person {
 *   String name;
 *   int age;
 *   boolean isSmoker;
 *
 *   ...
 *
 *   public String toString() {
 *     return new ToStringBuilder(this).
 *       append(name, "name").
 *       append(age, "age").
 *       append(smoker, "smoker").
 *       toString();
 *   }
 * }
 * </code>
 * This will produce a toString of the format:
 * <code>Person@7f54[name=Stephen,age=29,smoker=false]</code>

Comments welcomed. If positive/ no issues I will try to promote it to lang
proper before the release.

Stephen



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>