Nice TWiki > Doc > CodeExamples > TreeVisitorIntermediateExample (r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
Tree and Interior represent a simple binary tree; which is extended with a subclass representing n-ary trees and 3 separate external methods ExtendedTreeVisitorIntermediateExample.

// 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;
}
-- IsaacGouy - 05 Sep 2003

Topic TreeVisitorIntermediateExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.3 | > | r1.2 | > | r1.1 | More }
Revision r1.1 - 05 Sep 2003 - 17:13 GMT - IsaacGouy
Parents: WebHome > CodeExamples
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.

Doc.TreeVisitorIntermediateExample moved from Doc.ExtensibleVisitorIntermediateExample on 05 Sep 2003 - 17:17 by IsaacGouy - put it back