/** * Returns the highest ancestor of this child that is a child. * <p> * This may be this child. * * @return The root child of this child. */ public default Child getRootChild() { Child index = this; while (index.getParent() instanceof Child) { index = (AbstractChild) index.getParent(); } return index; }
/** * Returns the parent of this child, cast to a target class. * * @param <E> The target type. * @param parentClass The target class. * @return The parent of this child as a {@code parentClass} object. */ public default <E extends Parent> E getParent(Class<E> parentClass) { return parentClass.cast(getParent()); }
public static boolean hasAncestorMatching(Node node, Predicate<Node> predicate) { Node index = node; while (index != null) { if (predicate.test(index)) { return true; } if (index instanceof Child) { index = ((Child) index).getParent(); } else { index = null; } } return false; }
/** * Set the index of this child. * * @param to The new index of this child. * @throws IllegalArgumentException When this child has no parent,<br> * or {@code to < 0 or to >= getParent().getChildrenCount()}. */ public default void setIndex(int to) { CollectionsUtil.setIndex(getParent().getChildren(), this, to); }
/** * Remove a child. * <p> * If child is not a child of this parent, then false is returned. * * @param child The child. * @return {@code true} if child was removed, {@code false} otherwise. */ public default boolean removeChild(Child child) { if (child != null && child.getParent() == this) { getModifiableChildren().remove(child); child.setParent(null); return true; } else { return false; } }
@Override public void endElement(String uri, String localName, String qName) throws SAXException { LOGGER.trace("endElement()"); if (top() == Action.KEEP) { final Element current = (Element) currentParent; checkActiveText(true); currentParent = ((Child) currentParent).getParent(); resetActiveText(); if (!acceptsElementPost(current.getParent(), current)) { current.detach(); } } popAction(); }