Cd_graph { void display() to * (DisplayVisitor); void displayParents() bypassing Neighbors to * (DisplayVisitor); } FlattenVisitor{ {{ HashSet commonParents; // Names of classes to add common parts to HashSet commonChildren; // Common children to add to parent boolean debug = false; boolean flush = true; boolean parent = true; // To tell if parent or child class boolean add = false; FlattenVisitor(boolean d) { commonParents = new HashSet(); commonChildren = new HashSet(); debug = d; } void before(Adjacency host) { if (flush) { commonParents.clear(); commonChildren.clear(); } else { if (commonParents.contains(host.get_source())) { add = true; } } } void after(Adjacency host) { add = false; } void before(Neighbors_wc host) { if (add) { Iterator step = commonChildren.iterator(); while(step.hasNext()) host.get_construct_ns().addElement((Any_vertex)step.next()); } } void before(Neighbors host) { parent = false; } void after(Neighbors host) { parent = true; } void before(Common host) { flush = false; commonChildren.add(host); } void before(Vertex host) { if (!parent) commonParents.add(host); } }} } UniqueVisitor { {{ HashSet collection; HashSet duplicates; boolean debug = false; UniqueVisitor(boolean d) { collection = new HashSet(); duplicates = new HashSet(); debug = d; } void before(Adjacency host) { collection.clear(); duplicates.clear(); } void after(Adjacency host) { if (!duplicates.isEmpty()) { Iterator step = duplicates.iterator(); while (step.hasNext()) { String s = (String)step.next(); String c = host.get_source().get_vertex_name().toString(); System.out.println("Warning: "+s+" is already defined in "+c); } } } void before(Vertex host) { String vname = host.get_vertex_name().toString(); if (debug) System.out.println("Vertex name is: " + vname); if (collection.contains(vname)) { if (debug) System.out.println("Duplicate class entry!: "+vname); duplicates.add(vname); } else { if (debug) System.out.println("Successfully added: "+vname); collection.add(vname); } } }} } UndefinedVisitor { {{ HashSet collection; boolean debug = false; UndefinedVisitor(HashSet h, boolean d) {collection = h; debug = d;} void before(Vertex host) { String vname = host.get_vertex_name().toString(); if (debug) System.out.println("Vertex name is: " + vname); if (collection.contains(vname)) { if (debug) System.out.println("Duplicate class entry!: "+vname); } else { if (debug) System.out.println("Successfully added: "+vname); collection.add(vname); } } }} } Main { {{ static ClassGraph cg = new ClassGraph(true,false); static public void main(String args[]) throws Exception { Cd_graph graph = Cd_graph.parse(System.in); undefinedClasses(graph); uniqueParts(graph); } static public void FlattenGraph(Cd_graph graph) { Strategy s_Classes = new Strategy("from Cd_graph to Vertex"); TraversalGraph tg1 = new TraversalGraph(s_Classes, cg); tg1.traverse(graph, new FlattenVisitor(false)); } static public void uniqueParts(Cd_graph graph) { Strategy s_Classes = new Strategy("from Cd_graph to Vertex"); TraversalGraph tg1 = new TraversalGraph(s_Classes, cg); tg1.traverse(graph, new UniqueVisitor(false)); } static public void undefinedClasses(Cd_graph graph) { HashSet hs1 = new HashSet(); HashSet hs2 = new HashSet(); Strategy s_Parents = new Strategy("from Cd_graph bypassing Neighbors"+ " to Vertex"); Strategy s_Children = new Strategy("from Cd_graph through Neighbors"+ " to Vertex"); TraversalGraph tg1 = new TraversalGraph(s_Parents, cg); TraversalGraph tg2 = new TraversalGraph(s_Children, cg); tg1.traverse(graph, new UndefinedVisitor(hs1,false)); tg2.traverse(graph, new UndefinedVisitor(hs2,false)); Iterator step = hs2.iterator(); while (step.hasNext()) { String s = (String)step.next(); if (!hs1.contains(s)) System.out.println("Warning: class "+s+" not defined!"); } } }} }