// determine if nodes are homogeneous, meaning their descendant structure is 'identical' for repeat purposes // identical means all children match, and the children's children match, and so on // repeatable children are ignored; as they do not have to exist in the same quantity for nodes to be homogeneous // however, the child repeatable nodes MUST be verified amongst themselves for homogeneity later // this function ignores the names of the two nodes public static Boolean isHomogeneous(TreeElement a, TreeElement b) { if (a.isLeaf() && b.isLeaf()) { return(true); } else if (a.isChildable() && b.isChildable()) { // verify that every (non-repeatable) node in a exists in b and vice // versa for (int k = 0; k < 2; k++) { TreeElement n1 = (k == 0 ? a : b); TreeElement n2 = (k == 0 ? b : a); for (int i = 0; i < n1.getNumChildren(); i++) { TreeElement child1 = n1.getChildAt(i); if (child1.repeatable) { continue; } TreeElement child2 = n2.getChild(child1.getName(), 0); if (child2 == null) { return(false); } if (child2.repeatable) { throw new SystemException("shouldn't happen"); } } } // compare children for (int i = 0; i < a.getNumChildren(); i++) { TreeElement childA = a.getChildAt(i); if (childA.repeatable) { continue; } TreeElement childB = b.getChild(childA.getName(), 0); if (!isHomogeneous(childA, childB)) { return(false); } } return(true); } else { return(false); } }