| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Graph |
|
| 0.0;0 |
| 1 | package argos.util.graph; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | import java.util.List; | |
| 5 | ||
| 6 | 0 | public class Graph { |
| 7 | ||
| 8 | public static List<Node> findCircle(List<?> nodes) { | |
| 9 | 0 | List<Node> path = new ArrayList<Node>(); |
| 10 | 0 | List<Node> verified = new ArrayList<Node>(); |
| 11 | ||
| 12 | 0 | for(int i = 0; i < nodes.size(); i++) { |
| 13 | 0 | path.clear(); |
| 14 | 0 | Node node = (Node) nodes.get(i); |
| 15 | 0 | if(findCircle(node, node, path, verified)) { |
| 16 | 0 | return path; |
| 17 | } | |
| 18 | } | |
| 19 | ||
| 20 | 0 | return null; |
| 21 | } | |
| 22 | ||
| 23 | private static boolean findCircle(Node start, Node current, List<Node> path, List<Node> verified) { | |
| 24 | 0 | if(verified.contains(current)) { |
| 25 | 0 | return false; |
| 26 | } | |
| 27 | 0 | else if(path.contains(current)) { |
| 28 | 0 | return true; |
| 29 | } | |
| 30 | else { | |
| 31 | 0 | path.add(current); |
| 32 | 0 | for(Node node : current.getThisDependsOn()) { |
| 33 | 0 | if(findCircle(start, node, path, verified)) { |
| 34 | 0 | return true; |
| 35 | } | |
| 36 | } | |
| 37 | 0 | verified.add(current); |
| 38 | 0 | path.remove(path.size() - 1); |
| 39 | 0 | return false; |
| 40 | } | |
| 41 | } | |
| 42 | } |