// // Inheritance Cycle Check // /* * Algorithim for the Inheritance Cycle Check * * 1. Create a collection of visited classes * 2. Add self to collection * If self is already in collection then fail * 3. Go to super(s) * 4. Repeat 2-4 as necessary */ Adjacency { boolean check_cycle(Set visited, Cd_graph cdg) {{ //System.out.println(this.get_source_name()); if (visited.contains(this.get_source_name())) { System.out.print("Cycle exists with classes: "); return true; } //Add self to collection. Self check is above visited.add(this.get_source_name()); Iterator sIter = this.super_iter(); while (sIter.hasNext()) { //Add supers and repeat SuperClass s = (SuperClass) sIter.next(); //System.out.println("test"); Adjacency adj = cdg.get_class(s.get_super_name().toString()); //System.out.println("recurse "+adj.get_source_name()); if(adj.check_cycle(visited,cdg)) { System.out.print(this.get_source_name()+ " "); cdg.cyclic.add(this.get_source_name() ); return true; } } //No violation of the TBR return false; }} } Cd_graph { {{ public Set cyclic = new HashSet(); }} boolean check_cycles() to Adjacency { {{ Cd_graph cdg; }} init {{ return_val = false; }} before Adjacency {{ if(!cdg.cyclic.contains(host.get_source_name())){ Set s = new HashSet(); if (host.check_cycle(s,cdg)){ return_val = true; System.out.println(); } } }} before Cd_graph{{ cdg = host; }} } }