// cycle.beh -- check for inheritance cycles in class dictionary // by bmc and bmollo, the leet computer programmers Cd_graph { {{ HashSet checked_set = new HashSet(); }} boolean cycle_check() to Adjacency { {{ Cd_graph graph; }} init {{ return_val = false; }} before Cd_graph {{ graph = host; }} before Adjacency {{ String cur_class = host.get_source().get_vertex_name().toString(); if(Main.debug){System.out.println("Trying to Add : " + cur_class);} if (graph.checked_set.add(cur_class)) { if(Main.debug){System.out.println("Added : " + cur_class);} HashSet cycle_set = new HashSet(); if(host.self_cycle_check(cycle_set, graph)) { if(Main.debug){System.out.println("setting return_val = true");} return_val = true; } } }} } } Adjacency { {{ Iterator superClasses; }} {{ boolean self_cycle_check(HashSet cycle_set, Cd_graph graph) { if(Main.debug){System.out.println(this.get_source().get_vertex_name() + " self_cycle_check()");} graph.checked_set.add(this.get_source().get_vertex_name().toString()); if(Main.debug){ System.out.println( "cycle_set contents:" ); Iterator cycleIter = cycle_set.iterator(); while(cycleIter.hasNext()) { System.out.println( " " + cycleIter.next() ); } } if(cycle_set.contains(this.get_source().get_vertex_name().toString())) { System.out.println("Inheritance Cycle: from "); return true; } cycle_set.add(this.get_source().get_vertex_name()); superClasses = getSuperClassIterator(); while(superClasses.hasNext()) { if(Main.debug){System.out.println( this.get_source().get_vertex_name().toString() + " iterator loop");} // here there is a nifty recursion trick Adjacency nextSuper = (Adjacency) superClasses.next(); if(nextSuper.self_cycle_check(cycle_set, graph)) { System.out.println(nextSuper.get_source().get_vertex_name() + " to "); return true; } } return false; } }} Iterator getSuperClassIterator() to SuperClass { {{ HashSet SuperClasses = new HashSet(); }} before SuperClass {{ SuperClasses.add(host); }} after Adjacency {{ return_val = SuperClasses.iterator(); }} } }