private final boolean acceptsElementPre(Parent parent, Element element) { return elementPreFilter.accepts(parent, element); }
/** * @return The negation of this predicate. */ public default ElementPredicate not() { return (p, e) -> !accepts(p, e); }
private final boolean acceptsElementPost(Parent parent, Element element) { return elementPostFilter.accepts(parent, element); }
/** * Returns a predicate that is the logical {@code and} combination of this one and another one. * * @param other The other predicate. * @return A predicate that is the logical {@code and} combination of this one and {@code other}. * @throws IllegalArgumentException When {@code other} is {@code null}. */ public default ElementPredicate and(ElementPredicate other) { Checks.isNotNull(other, "other"); return (p, e) -> accepts(p, e) && other.accepts(p, e); }
/** * Returns a predicate that is the logical {@code or} combination of this one and another one. * * @param other The other predicate. * @return A predicate that is the logical {@code or} combination of this one and {@code other}. * @throws IllegalArgumentException When {@code other} is {@code null}. */ public default ElementPredicate or(ElementPredicate other) { Checks.isNotNull(other, "other"); return (p, e) -> accepts(p, e) || other.accepts(p, e); }
public static void setContentOfMatchingElements(Parent parent, ElementPredicate predicate, TextContentConverter converter, Evaluator<? super Parent> evaluator) { if (parent instanceof Element) { final Element element = (Element) parent; if (predicate.accepts(element.getParent(), element)) { final int count = element.getChildrenCount(); if (count == 0) { // Add a text child final String content = converter.convertTextContent(element, null); if (content != null) { element.addText(content); } } else if (count == 1 && element.hasOnlyText()) { // Modify text child if possible final Text text = element.getChild(Text.class); final String content = converter.convertTextContent(element, text.getContent()); text.setContent(content); } } } for (final Child child : parent.getChildren()) { if (child instanceof Parent && evaluator.evaluate((Parent) child) == Evaluation.CONTINUE) { setContentOfMatchingElements((Parent) child, predicate, converter, evaluator); } } }