/** * @return The negation of this predicate. */ public default TextPredicate not() { return (p, t) -> !accepts(p, t); }
DataUtil.RECURSE); DataUtil.setContentOfMatchingTexts(document, TextPredicate.fromElementPaths(margs.scrambled), TextContentConverter.scramble(true), DataUtil.RECURSE);
/** * 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 TextPredicate and(TextPredicate other) { Checks.isNotNull(other, "other"); return (p, t) -> accepts(p, t) && other.accepts(p, t); }
/** * 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 TextPredicate or(TextPredicate other) { Checks.isNotNull(other, "other"); return (p, t) -> accepts(p, t) || other.accepts(p, t); }
/** * Sets the content of matching texts. * <p> * Uses a Depth First traversal for recursion. * * @param parent The initial node. <em>MUST NOT</em> be null. * @param predicate The predicate of matching texts. <em>MUST NOT</em> be null. * @param converter The content converter. * @param evaluator The evaluator. <em>MUST NOT</em> be null. */ public static void setContentOfMatchingTexts(Parent parent, TextPredicate predicate, TextContentConverter converter, Evaluator<? super Parent> evaluator) { for (final Child child : parent.getChildren()) { if (child instanceof Text) { final Text text = (Text) child; if (predicate.accepts(parent, text)) { final String content = converter.convertTextContent(parent, text.getContent()); text.setContent(content); } } else if (child instanceof Parent && evaluator.evaluate((Parent) child) == Evaluation.CONTINUE) { setContentOfMatchingTexts((Parent) child, predicate, converter, evaluator); } } }