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); }
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); }