private final String convertAttributeValue(Element element, String name, String value) { return attributeValueConverter.convertAttributeValue(element, name, value); }
/** * Returns a converter that first applies {@code other} then this converter. * * @param other The other converter. * @return A converter that first applies {@code other} then this converter. * @throws IllegalArgumentException When {@code other} is {@code null}. */ public default AttributeValueConverter compose(AttributeValueConverter other) { Checks.isNotNull(other, "other"); return (Element element, String name, String value) -> convertAttributeValue(element, name, other.convertAttributeValue(element, name, value)); }
/** * Returns a converter that first applies this converter and then {@code other}. * * @param other The other converter. * @return A converter that first applies this converter and then {@code other}. * @throws IllegalArgumentException When {@code other} is {@code null}. */ public default AttributeValueConverter andThen(AttributeValueConverter other) { Checks.isNotNull(other, "other"); return (Element element, String name, String value) -> other.convertAttributeValue(element, name, convertAttributeValue(element, name, value)); }
/** * 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); } } }