private final boolean acceptsAttribute(Element element, String name, String value) { return attributeFilter.accepts(element, name, value); }
/** * @return The negation of this predicate. */ public default AttributePredicate not() { return (e, n, v) -> !accepts(e, n, v); }
/** * 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 AttributePredicate and(AttributePredicate other) { Checks.isNotNull(other, "other"); return (e, n, v) -> accepts(e, n, v) && other.accepts(e, n, v); }
/** * 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 AttributePredicate or(AttributePredicate other) { Checks.isNotNull(other, "other"); return (e, n, v) -> accepts(e, n, v) || other.accepts(e, n, v); }
/** * Removes matching attributes. * <p> * Uses a Depth First traversal for recursion.<br> * Removal is applied on parent before its children. * * @param parent The initial node. <em>MUST NOT</em> be null. * @param predicate The predicate of matching attributes. <em>MUST NOT</em> be null. * @param evaluator The evaluator. <em>MUST NOT</em> be null. */ public static void removeMatchingAttributes(Parent parent, AttributePredicate predicate, Evaluator<? super Parent> evaluator) { if (parent instanceof Element) { final Element element = (Element) parent; final Iterator<Attribute> atts = element.getAttributes().iterator(); while (atts.hasNext()) { final Attribute att = atts.next(); if (predicate.accepts(element, att.getName(), att.getValue())) { atts.remove(); } } } for (final Parent child : parent.getChildren(Parent.class)) { if (evaluator.evaluate(child) == Evaluation.CONTINUE) { removeMatchingAttributes(child, predicate, evaluator); } } }
if (predicate.accepts(element, att.getName(), att.getValue())) { if (atts == null) { atts = new ArrayList<>();
/** * Sets value of matching attributes. * <p> * Uses a Depth First traversal for recursion.<br> * Change is applied on parent before its children. * * @param parent The initial node. <em>MUST NOT</em> be null. * @param predicate The predicate of matching attributes. <em>MUST NOT</em> be null. * @param converter The attribute value converter. <em>MUST NOT</em> be null. * @param evaluator The evaluator. <em>MUST NOT</em> be null. */ public static void setValueOfMatchingAttributes(Parent parent, AttributePredicate predicate, AttributeValueConverter converter, Evaluator<? super Parent> evaluator) { if (parent instanceof Element) { final Element element = (Element) parent; for (final Attribute att : element.getAttributes()) { if (predicate.accepts(element, att.getName(), att.getValue())) { final String newValue = converter.convertAttributeValue(element, att.getName(), att.getValue()); att.setValue(newValue); } } } for (final Parent child : parent.getChildren(Parent.class)) { if (evaluator.evaluate(child) == Evaluation.CONTINUE) { setValueOfMatchingAttributes(child, predicate, converter, evaluator); } } }