*/
private static int computeTwinIndex(Element parent, Element child) throws JDOMException {
int index = -1;
if (parent == null) {
throw new JDOMException("can't use null parent");
}
List<Element> identicalTwins = getNamedChildren(parent, child.getQualifiedName());
if (identicalTwins.size() > 1) {
for (int j = 0; index < 0 && j < identicalTwins.size(); ++j) {
if (identicalTwins.get(j) == child) {
// Add 1 to convert to 1-origin index used by
// Xpath.
index = j + 1;
}
}
if (index < 0) {
// ??? Something is wrong. We didn't find child
// among its parent's children.
throw new JDOMException("error in tree: node is not listed among its parent's children");
}
}
return index;
}