Class ToString

java.lang.Object
fc.util.ToString

public class ToString extends Object
Makes creating toString methods easier. (For example, provides ability to introspect and write field values). Idea inspired by a similar apache/jakarta utility.

Methods of the form append(String, type) imply the name specified by the string (typically a field name) is shown with value specified by type.

Example usage:
foo and bar are fields of this object.

public String toString() {
  return new ToString(this).
    append("foo","some-value").
    append("bar",123).
    render();
  }
Another example:
Automatically prints this entire object using reflection.
public String toString() {
  return new ToString(this).reflect().
  render();
  }
Note: Don't forget the render() call at the end.

The class only needs to be instantiated once so here's a more efficient approach:

{ //instance initializer
ToString tostr = new ToString(this);
}
public String toString() {
  return tostr.reflect().
  render();
  }