// return the level distance to the current node public int getDistance(Node node) { Node myParent = node.getParent(); int level = 1; while (myParent != null && myParent != this) { level++; myParent = myParent.getParent(); } return level; }
/** * Is passed node a child of current node * * @param aNode */ public boolean isNodeChild(Node aNode) { boolean retval; if (aNode == null) { retval = false; } else { if (getChildCount() == 0) { retval = false; } else { retval = (aNode.getParent() == this); } } return retval; }
/** Is parsed in node a sibling */ public boolean isNodeSibling(Node anotherNode) { boolean retval; if (anotherNode == null) { retval = false; } else if (anotherNode == this) { retval = true; } else { Node myParent = getParent(); retval = (myParent != null && myParent == anotherNode.getParent()); if (retval && !((Node) getParent()).isNodeChild(anotherNode)) { throw new Error("sibling has different parent"); } } return retval; }