/** * Computes the count of element siblings after the given element in the DOM tree. * @param e The element to be examined * @param sameType when set to <code>true</code> only the element with the same type are considered. * Otherwise, all elements are considered. * @return the number of following siblings */ protected int countSiblingsAfter(Element e, boolean sameType) { int cnt = 0; Node next = e; do { next = next.getNextSibling(); if (next != null && next.getNodeType() == Node.ELEMENT_NODE) { if (!sameType || isSameElementType(e, (Element) next)) cnt++; } } while (next != null); return cnt; }
/** * Computes the count of element siblings before the given element in the DOM tree. * @param e The element to be examined * @param sameType when set to <code>true</code> only the element with the same type are considered. * Otherwise, all elements are considered. * @return the number of preceding siblings */ protected int countSiblingsBefore(Element e, boolean sameType) { int cnt = 0; Node prev = e; do { prev = prev.getPreviousSibling(); if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE) { if (!sameType || isSameElementType(e, (Element) prev)) cnt++; } } while (prev != null); return cnt; }
/** * Computes the count of element siblings before the given element in the DOM tree. * @param e The element to be examined * @param sameType when set to <code>true</code> only the element with the same type are considered. * Otherwise, all elements are considered. * @return the number of preceding siblings */ protected int countSiblingsBefore(Element e, boolean sameType) { int cnt = 0; Node prev = e; do { prev = prev.getPreviousSibling(); if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE) { if (!sameType || isSameElementType(e, (Element) prev)) cnt++; } } while (prev != null); return cnt; }
prev = prev.getPreviousSibling(); if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE && isSameElementType(e, (Element) prev)) firstt = false; } while (prev != null && firstt); next = next.getNextSibling(); if (next != null && next.getNodeType() == Node.ELEMENT_NODE && isSameElementType(e, (Element) next)) lastt = false; } while(next != null && lastt);
prev = prev.getPreviousSibling(); if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE && isSameElementType(e, (Element) prev)) firstt = false; } while (prev != null && firstt); next = next.getNextSibling(); if (next != null && next.getNodeType() == Node.ELEMENT_NODE && isSameElementType(e, (Element) next)) lastt = false; } while(next != null && lastt);
/** * Computes the count of element siblings after the given element in the DOM tree. * @param e The element to be examined * @param sameType when set to <code>true</code> only the element with the same type are considered. * Otherwise, all elements are considered. * @return the number of following siblings */ protected int countSiblingsAfter(Element e, boolean sameType) { int cnt = 0; Node next = e; do { next = next.getNextSibling(); if (next != null && next.getNodeType() == Node.ELEMENT_NODE) { if (!sameType || isSameElementType(e, (Element) next)) cnt++; } } while (next != null); return cnt; }