org.jplate.foundation
Interface FormattableIfc
- All Known Subinterfaces:
- AttributeIfc<N,V>, BranchNodeIfc<BC,LC>, KvpIfc, KvpParseContextIfc<P>, LeafNodeIfc<BC,LC>, NodeIfc<BC,LC>, SourceIfc<S>
- All Known Implementing Classes:
- AbstractNode, DefaultAttribute, DefaultBranchNode, DefaultKvp, DefaultKvpParseContext, DefaultLeafNode, DefaultSource
public interface FormattableIfc
Classes should implement this interface to gain "prettier"
toString()
functionality by way of allowing arbitrary prependable
text. For instance this can be used to stagger (indent) data members.
Consider the following classes:
public class Bar implements FormattableIfc
{
public int _value1;
public int _value2;
public String toString ()
{
return toString ( "" );
}
public String toString ( final String prepend )
{
return
prepend + "_value1 = [" + _value1 + "]\n" +
prepend + "_value2 = [" + _value2 + "]\n";
}
}
public class Foo implements FormattableIfc
{
public final Bar _bar1 = new Bar ();
public final Bar _bar2 = new Bar ();
public int _age;
public String toString ()
{
return toString ( "" );
}
public String toString ( final String prepend )
{
return
prepend + "_bar1 =\n" + _bar1.toString ( prepend + " " ) +
prepend + "_bar2 =\n" + _bar2.toString ( prepend + " " ) +
prepend + "_age = [" + _age + "]";
}
}
If one executes the above code using the following:
final Foo foo = new Foo ();
foo._bar1._value1 = 1;
foo._bar1._value2 = 2;
foo._bar2._value1 = 3;
foo._bar2._value2 = 4;
foo._age = 37;
System.out.println ( "foo =\n" + foo.toString ( "----" ) );
Will yield:
foo =
----_bar1 =
---- _value1 = [1]
---- _value2 = [2]
----_bar2 =
---- _value1 = [3]
---- _value2 = [4]
----_age = [37]
Modifications:
$Author: sfloess $
$Date: 2008-12-02 12:32:45 -0500 (Tue, 02 Dec 2008) $
$Revision: 479 $
$HeadURL: https://jplate.svn.sourceforge.net/svnroot/jplate/trunk/src/dev/java/org/jplate/foundation/FormattableIfc.java $
Method Summary |
java.lang.String |
toString(java.lang.String prepend)
Returns a string representation of self prepending prepend to
each line. |
toString
java.lang.String toString(java.lang.String prepend)
- Returns a string representation of self prepending
prepend
to
each line.
- Parameters:
prepend
- The text to prepend to each line as defined in the return
value.
- Returns:
- A string representation of self who has
prepend
prepended to each line.