/** * method returns the intersection size of two leaf sets * * @param leavesSubTree * @param leavesSubCompareTree * @return intersectionSize */ public static int countCommonLeaves(TreeNode[] leavesSubTree, TreeNode[] leavesSubCompareTree) { int intersectionSize = 0; for (int i = 0; i < leavesSubTree.length; i++) { for (int j = 0; j < leavesSubCompareTree.length; j++) { if (leavesSubTree[i].equalsNode(leavesSubCompareTree[j])) { intersectionSize++; break; } } } return intersectionSize; }
private boolean findLeaf(TreeNode node, int index) { // boolean isIn = false; // if(leaves.contains(node)) return true; // else return false; for (TreeNode leave : leaves) { if (leave.equalsNode(node)) return true; } return false; // try{ // TreeNode l = (TreeNode)leaves.get(index); // elementAt(index); // // if(l.equals(node)){ // isIn = true; // return isIn; // } // }catch (ClassCastException e){ // isIn = false; // index+=1; // if(index<leaves.size()){ // if(findLeaf(node,index)) // return true; // } // } // return isIn; }
/** * Indicates, if this node is a child of the given node. * * @param node: the node, that may be parent of this node * @return true, if this node is a child of the given node, false otherwise */ public boolean isChildOf(TreeNode node) { if (this.getParent().equalsNode(node)) { return true; } else { return false; } }
/** * Computes the number of the given child for this node. * This number is 0 {@literal <=} childNum {@literal <} 'number of children', if the child is a real child of this node. * It is childNum = 'number of children', if the given child is parent of this node. * * @param child: the child, for that its number has to be computed * @return the child number for the given node */ public int getChildNumber(TreeNode child) { if (this.getParent().equalsNode(child)) { return childCount(); } else if (child.isChildOf(this)) { int num = 0; for (TreeNode nodesChild : this.children()) { if (!nodesChild.equalsNode(child)) { num++; } else { break; } } return num; } else { throw new RuntimeException("Given child is no child of this node!"); } }
if (leaf.equalsNode(a)) posA = x; if (leaf.equalsNode(b)) posB = x; if (node.equalsNode(a)) posA = x; if (node.equalsNode(b)) posB = x;