/** * Removes all texts locally. */ public default void removeTexts() { removeChildren(IS_TEXT); }
/** * Removes all ignorable texts locally. */ public default void removeIgnorableTexts() { removeChildren(IS_IGNORABLE_TEXT); }
/** * Removes all comments recursively. * * @param recurse If {@code true}, then this is applied recursively. */ public default void removeComments(boolean recurse) { removeChildren(IS_COMMENT, true, recurse); }
/** * Removes all ignorable texts recursively. * * @param recurse If {@code true}, then this is applied recursively. */ public default void removeIgnorableTexts(boolean recurse) { removeChildren(IS_IGNORABLE_TEXT, true, recurse); }
/** * Removes all comments locally. */ public default void removeComments() { removeChildren(IS_COMMENT); }
/** * Removes all texts recursively. * * @param recurse If {@code true}, then this is applied recursively. */ public default void removeTexts(boolean recurse) { removeChildren(IS_TEXT, true, recurse); }
/** * Removes all children elements that have a given name, recursively. * * @param name The name of elements to remove. * @param recurse If {@code true}, then this is applied recursively. */ public default void removeElementsNamed(String name, boolean recurse) { removeChildren(Element.named(name), true, recurse); }
/** * Removes all children elements that have a given name. * * @param name The name of elements to remove. */ public default void removeElementsNamed(String name) { removeChildren(Element.named(name)); }
/** * Removes all children that match a predicate, recursively. * * @param predicate The predicate. * @param pre If {@code true}, removal is applied before recursion, after otherwise. * @param recurse If {@code true}, then this is applied recursively. */ public default void removeChildren(Predicate<? super Child> predicate, boolean pre, boolean recurse) { if (pre) { removeChildren(predicate); } if (recurse) { for (final Element child : getElements()) { child.removeChildren(predicate, pre, true); } } if (!pre) { removeChildren(predicate); } }
/** * Removes matching children. * <p> * Uses a Depth First traversal for recursion.<br> * Removal is applied on children before parent. * * @param parent The initial node. <em>MUST NOT</em> be null. * @param predicate The predicate of children nodes to remove. <em>MUST NOT</em> be null. * @param evaluator The evaluator. <em>MUST NOT</em> be null. */ public static void removeMatchingChildren(Parent parent, Predicate<? super Child> predicate, Evaluator<? super Parent> evaluator) { // First, recursive processing for (final Parent child : parent.getChildren(Parent.class)) { if (evaluator.evaluate(child) == Evaluation.CONTINUE) { removeMatchingChildren(child, predicate, evaluator); } } // Then local removal process parent.removeChildren(predicate); }