/** * @return {@code true} if this parent has children elements. */ public default boolean hasElements() { return !Iterables.isEmpty(getElements()); }
/** * Merges all consecutive comments recursively. * * @param recurse If {@code true}, then this is applied recursively. */ public default void mergeComments(boolean recurse) { mergeComments(); if (recurse) { for (final Element child : getElements()) { child.mergeComments(true); } } }
/** * Merges all consecutive texts recursively. * * @param recurse If {@code true}, then this is applied recursively. */ public default void mergeTexts(boolean recurse) { mergeTexts(); if (recurse) { for (final Element child : getElements()) { child.mergeTexts(true); } } }
/** * Changes all texts recursively. * * @param modifier A function that take content and returns new content. * @param recurse If {@code true}, then this is applied recursively. */ public default void changeTexts(Function<String, String> modifier, boolean recurse) { changeTexts(modifier); if (recurse) { for (final Element child : getElements()) { child.changeTexts(modifier, true); } } }
/** * Sorts children recursively. * * @param comparator The comparator. * @param recurse If {@code true}, then this is applied recursively. */ public default void sortChildren(Comparator<? super Child> comparator, boolean recurse) { sortChildren(comparator); if (recurse) { for (final Element child : getElements()) { child.sortChildren(comparator, true); } } }
/** * Changes all comments recursively. * * @param modifier A function that take content and returns new content. * @param recurse If {@code true}, then this is applied recursively. */ public default void changeComments(Function<String, String> modifier, boolean recurse) { changeComments(modifier); if (recurse) { for (final Element child : getElements()) { child.changeComments(modifier, true); } } } }
/** * Changes or set text under element that have a given name, recursively. * * @param name The element name. * @param modifier A function that take content and returns new content. * @param recurse If {@code true}, then this is applied recursively. */ public default void changeNamedTexts(String name, Function<String, String> modifier, boolean recurse) { changeNamedTexts(name, modifier); if (recurse) { for (final Element child : getElements()) { child.changeNamedTexts(name, modifier, true); } } }
/** * 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); } }