core: import edu.neu.ccs.demeter.dj.*; import edu.neu.ccs.demeter.*; add: class Container { protected List contents; public List get_contents() {{ return contents; }} public void set_contents(List new_contents) {{ contents = new_contents; }} public constructor Container() {{ super(); }} public constructor Container(List contents) {{ super(); set_contents(contents); }} public static Container parse(java.io.Reader in) throws ParseException {{ return new Parser(in)._Container(); }} public static Container parse(java.io.InputStream in) throws ParseException {{ return new Parser(in)._Container(); }} public static Container parse(String s) {{ try { return parse(new java.io.StringReader(s)); } catch (ParseException e) { throw new RuntimeException(e.toString()); } }} {{ float statistics(TraversalGraph whereToGo) throws Exception { CountingVisitorDJ cV = new CountingVisitorDJ(); //1 SummingVisitorDJ sV = new SummingVisitorDJ(); //1 AverageVisitorDJ aV = new AverageVisitorDJ(); //1 ResultVisitorDJ rV = new ResultVisitorDJ(); // establish communication between visitors aV.set_cV(cV); aV.set_sV(sV); rV.set_aV(aV); // replace the following // Visitor[] visitors = new Visitor[4]; // visitors[0]=(Visitor) rV; // visitors[1]=(Visitor) sV; // visitors[2]=(Visitor) cV; // visitors[3]=(Visitor) aV; // System.out.println("visitors prepared"); // Float res = (Float) whereToGo.traverse(this, visitors); Float res = (Float) whereToGo.traverse(this, new Visitor[] { rV, sV, cV, aV }); return res.floatValue(); } }} {{ void universal_trv0_bef(UniversalVisitor _v_) { ((UniversalVisitor) _v_).before(this); } }} {{ void universal_trv0_aft(UniversalVisitor _v_) { ((UniversalVisitor) _v_).after(this); } }} {{ void universal_trv0(UniversalVisitor _v_) { universal_trv0_bef(_v_); ((UniversalVisitor) _v_).before_contents(this, contents); contents.universal_trv0(_v_); ((UniversalVisitor) _v_).after_contents(this, contents); universal_trv0_aft(_v_); } }} }