// compilation unit Tree.nice
package openclassdispatch;
public class Tree<T> {
private !T value;
// internal implementation of prettyPrinting to
// measure regular dispatch speed
// Unlike MultiJava, in Nice there's no difference
// to methods defined externally - like prettyPrint
public String internalPrettyPrint(String prefix);
internalPrettyPrint(prefix) =
prefix + this.getValue().toString + "\n";
public String internalPrettyPrint();
internalPrettyPrint() = this.internalPrettyPrint("");
public !T getValue() = value;
}
// compilation unit Interior.nice
package openclassdispatch;
public class Interior<T> extends Tree {
private Tree<T> left;
private Tree<T> right;
// internal implementation of prettyPrinting to
// measure regular dispatch speed
// Unlike MultiJava, in Nice there's no difference
// to methods defined externally - like prettyPrint
internalPrettyPrint(prefix) {
let result = new StringBuffer( prefix + this.getValue() + "\n" );
let newPrefix = prefix + "| ";
result.append( this.getLeft().internalPrettyPrint( newPrefix ) );
result.append( this.getRight().internalPrettyPrint( newPrefix ) );
return result.toString;
}
public Tree<T> getLeft() = left;
public Tree<T> getRight() = right;
}
// 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;
}
}
-- IsaacGouy - 05 Sep 2003
| Topic TreeVisitorClassesIntermediateExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.1 | More } |
|
Revision r1.1 - 05 Sep 2003 - 18:43 GMT - IsaacGouy Parents: WebHome > CodeExamples > TreeVisitorIntermediateExample |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |