%META:TOPICINFO{author="IsaacGouy" date="1062782438" format="1.0" version="1.1"}%
%META:TOPICPARENT{name="TreeVisitorIntermediateExample"}%
// compilation unit MultiInterior.nice
package openclassdispatch;
public class MultiInterior<T> extends Tree {
private Tree<T>[] children ;
public Tree<T>[] getChildren() = children;
prettyPrint(prefix) {
let result = new StringBuffer( prefix + this.value() + "\n" );
let newPrefix = prefix + "| ";
for (each : children)
result.append( each.prettyPrint( newPrefix ) );
return result.toString;
}
dispatchTest() {
for (each : children) each.dispatchTest;
}
size(){
var count = 1;
for (each : this.children) count += each.size;
return count;
}
}
// compilation unit dispatchTest.nice
package openclassdispatch;
<T> void dispatchTest(Tree<T> t);
dispatchTest(this@Tree) { }
dispatchTest(this@Interior) {
this.getLeft().dispatchTest();
this.getRight().dispatchTest();
}
// compilation unit size.nice
package openclassdispatch;
<T> int size(Tree<T> t);
size(t@Tree) = 1;
size(t@Interior) = 1 + t.getLeft().size() + t.getRight().size();
/ compilation unit prettyPrint.nice
package openclassdispatch;
public <T> String prettyPrint(Tree<T> t);
prettyPrint(t@Tree) = t.prettyPrint( "" );
public <T> String prettyPrint(Tree<T> t, String prefix);
prettyPrint(t@Tree, prefix) = prefix + t.value() + "\n";
prettyPrint(t@Interior, prefix) {
let result = new StringBuffer( prefix + t.value() + "\n" );
let newPrefix = prefix + "| ";
result.append( t.left().prettyPrint( newPrefix ) );
result.append( t.right().prettyPrint( newPrefix ) );
return result.toString();
}
-- IsaacGouy - 05 Sep 2003 |