public static boolean validateOverhangs(ArrayList<RGraph> graphs) { boolean valid = true; for (RGraph graph : graphs) { ArrayList<RNode> queue = new ArrayList<RNode>(); HashSet<RNode> seenNodes = new HashSet<RNode>(); RNode root = graph.getRootNode(); queue.add(root); while (!queue.isEmpty()) { RNode current = queue.get(0); queue.remove(0); seenNodes.add(current); if (!("EX".equals(current.getLOverhang()) && "SP".equals(current.getROverhang()))) { return false; } ArrayList<RNode> neighbors = current.getNeighbors(); for (RNode neighbor : neighbors) { if (!seenNodes.contains(neighbor)) { queue.add(neighbor); } } } } return valid; }
/** Overhang scars helper * */ private ArrayList<String> assignScarsHelper(RNode parent, ArrayList<RNode> children) { ArrayList<String> scars = new ArrayList<String>(); // Loop through each one of the children to assign rule-instructed overhangs... enumerated // numbers currently for (int i = 0; i < children.size(); i++) { RNode child = children.get(i); if (i > 0) { if (child.getLOverhang().isEmpty()) { scars.add("_"); } scars.add("BB"); } // Make recursive call if (child.getStage() > 0) { // Remove the current parent from the list ArrayList<RNode> grandChildren = new ArrayList<RNode>(); grandChildren.addAll(child.getNeighbors()); if (grandChildren.contains(parent)) { grandChildren.remove(parent); } ArrayList<String> childScars = assignScarsHelper(child, grandChildren); scars.addAll(childScars); } else { ArrayList<String> childScars = new ArrayList<String>(); if (child.getComposition().size() > 1) { if (!child.getScars().isEmpty()) { childScars.addAll(child.getScars()); } else { for (int j = 0; j < child.getComposition().size() - 1; j++) { childScars.add("_"); } child.setScars(childScars); } } scars.addAll(childScars); } } // Keep scars for re-used parts with scars if (!scars.isEmpty()) { parent.setScars(scars); return scars; } else { return parent.getScars(); } }