protected void cacheDescendantsHelper(Node n) { for (Node child : n.getChildNodes()) { if (descendants.contains(child)) { continue; } descendants.add(child); cacheDescendantsHelper(child); } }
protected boolean isAncestorHelper(List<Node> children, Node node, Set<Node> seenNodes) { for (Node n : children) { if (seenNodes.contains(n)) { continue; } seenNodes.add(n); if (n.equals(node)) { return true; } if (isAncestorHelper(n.getChildNodes(), node, seenNodes)) { return true; } } return false; }