/***********************************************************************************/ // Required for AbstractSet public boolean add(Node obj) // obj must be a Node { Node node = obj; boolean found = nodeToData.keySet().contains(obj); if (!found) { NodeData nd = new NodeData(); nodeToData.put(node, nd); } return !found; }
public NodeData() { clear(); }
void visitAll(NodeVisitor nv) { boolean done = false; // Repeat the traversal until every node has been visited. Since it takes one pass to determine whether or not // each node has already been visited, this loop always runs at least once. do { done = true; // Copy entries to array to avoid concurrent modification problem with iterator if the visitor is updating // the graph. @SuppressWarnings("unchecked") Map.Entry<Node, NodeData>[] entries = nodeToData.entrySet().toArray(new Map.Entry[0]); // Visit each node in the graph that has not already been visited. // If any node is visited in this pass, we must run at least one more pass. for (int ctr = 0; ctr < entries.length; ctr++) { Map.Entry<Node, NodeData> current = entries[ctr]; Node node = current.getKey(); NodeData nd = current.getValue(); if (!nd.isVisited()) { nd.visited(); done = false; nv.visit(this, node, nd); } } } while (!done); }
private Set<Node> collectRootSet() { final Set<Node> result = new HashSet<Node>(); Iterator<Map.Entry<Node, NodeData>> iter = nodeToData.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Node, NodeData> entry = iter.next(); Node node = entry.getKey(); NodeData nd = entry.getValue(); if (nd.isRoot()) result.add(node); } return result; }
public void visit(Graph graph, Node node, NodeData nd) { Iterator<Node> iter = node.getChildren().iterator(); // Iterator<Node> while (iter.hasNext()) { Node child = iter.next(); // Make sure the child is in the graph so it can be visited later if necessary. graph.add(child); // Mark the child as a non-root, since a child is never a root. NodeData cnd = graph.getNodeData(child); cnd.notRoot(); } } });
void visitAll(NodeVisitor nv) { boolean done = false; // Repeat the traversal until every node has been visited. Since it takes one pass to determine whether or not // each node has already been visited, this loop always runs at least once. do { done = true; // Copy entries to array to avoid concurrent modification problem with iterator if the visitor is updating // the graph. @SuppressWarnings("unchecked") Map.Entry<Node, NodeData>[] entries = nodeToData.entrySet().toArray(new Map.Entry[0]); // Visit each node in the graph that has not already been visited. // If any node is visited in this pass, we must run at least one more pass. for (int ctr = 0; ctr < entries.length; ctr++) { Map.Entry<Node, NodeData> current = entries[ctr]; Node node = current.getKey(); NodeData nd = current.getValue(); if (!nd.isVisited()) { nd.visited(); done = false; nv.visit(this, node, nd); } } } while (!done); }
private Set<Node> collectRootSet() { final Set<Node> result = new HashSet<Node>(); Iterator<Map.Entry<Node, NodeData>> iter = nodeToData.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Node, NodeData> entry = iter.next(); Node node = entry.getKey(); NodeData nd = entry.getValue(); if (nd.isRoot()) result.add(node); } return result; }
public void visit(Graph graph, Node node, NodeData nd) { Iterator<Node> iter = node.getChildren().iterator(); // Iterator<Node> while (iter.hasNext()) { Node child = iter.next(); // Make sure the child is in the graph so it can be visited later if necessary. graph.add(child); // Mark the child as a non-root, since a child is never a root. NodeData cnd = graph.getNodeData(child); cnd.notRoot(); } } });
public NodeData() { clear(); }
/***********************************************************************************/ // Required for AbstractSet public boolean add(Node obj) // obj must be a Node { Node node = obj; boolean found = nodeToData.keySet().contains(obj); if (!found) { NodeData nd = new NodeData(); nodeToData.put(node, nd); } return !found; }
private void clearNodeData() { // Clear every node Iterator<Map.Entry<Node, NodeData>> iter = nodeToData.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Node, NodeData> entry = iter.next(); NodeData nd = entry.getValue(); nd.clear(); } }
private void clearNodeData() { // Clear every node Iterator<Map.Entry<Node, NodeData>> iter = nodeToData.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Node, NodeData> entry = iter.next(); NodeData nd = entry.getValue(); nd.clear(); } }