Nice TWiki > Doc > CodeExamples > BuilderPatternMultiMethodExample > NiceGeneratorMultiMethodExample (r1.4) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
/* Please try the NoviceExamples before the MultiMethodExamples
To compile:
   nicec --sourcepath=.. -a builderpattern.jar builderpattern
To run:
   java -jar builderpattern.jar
*/

package builderpattern;


outFile(NiceStyle){
   File d = new File(".", "driver" + VISITEES);
   d.mkdir();
   return "driver" + VISITEES + "/" + 
      "driver" + VISITEES + ".nice";
}


//==== dumpHeader


dumpHeader(NiceStyle){} 


//==== dumpInnerClasses


dumpVisitee0(NiceStyle, i) = 
   out.println("public class A"+i+" implements A { }\n");



dumpVisiteeI(NiceStyle, i) {
   out.print("public class A" + i + " ");    
   out.println("extends A" + (i-1)+ " implements A { }\n");
}


dumpVisitorClasses(NiceStyle){
   for (int k=0;k<VISITORS;k++) {       
      out.println("class SumNice"+k+" {\n   long sum = 0;");
      out.println("   public void visit(A a){}");
      for (int i=0;i<VISITEES;i++)
         out.println("   public void visit(A" + i + " a) { sum += " + i + ";}");
      out.println("} // end of SumNice"+k+"\n");
   } 
}


//==== dumpLoop


dumpMainHeader(NiceStyle) = 
   out.println("\n\n  public void main(String[] args) {");


//==== dumpFun


createVisitees(NiceStyle) { 
   out.println("   A[] a = new A[" + VISITEES+"].fill(int k => new A0());\n");
   for (int i=0;i<VISITEES;i++)
      out.println("   a["+i+ "] = new A"+i+"();");
   out.println("");
}


stopTimer(NiceStyle) =
   out.println("   long end = System.currentTimeMillis();\n" +
               "   return int(end - start);");


dumpFun(NiceStyle){
   out.println("int " + NiceStyle + "() {");
   createVisitees(NiceStyle);
   for (int k=0;k<VISITORS;k++)
      out.println("   SumNice"+k+" nicesum"+k+" = new SumNice"+k+"();");
   out.println("");
   startTimer(NiceStyle);
   out.println("   for (int i=0;i<"+ITERS+";i++)\n"+
               "      for (int j=0;j<"+VISITEES+";j++) {");
   for (int k=0;k<VISITORS;k++)
      out.println("         nicesum"+k+".visit(a[j]);");
   out.println("      }\n");   
   stopTimer(NiceStyle);   
   out.println("}");
}

//==== dumpFooter

dumpFooter(NiceStyle){}

-- IsaacGouy - 30 Jan 2004

Topic NiceGeneratorMultiMethodExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.6 | > | r1.5 | > | r1.4 | More }
Revision r1.4 - 23 Jan 2005 - 13:51 GMT - TWikiGuest
Parents: WebHome > CodeExamples > BuilderPatternMultiMethodExample
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.