Class Evaluator

java.lang.Object
org.jsoup.select.Evaluator
Direct Known Subclasses:
CombiningEvaluator, Evaluator.AllElements, Evaluator.Attribute, Evaluator.AttributeKeyPair, Evaluator.AttributeStarting, Evaluator.AttributeWithValueMatching, Evaluator.Class, Evaluator.ContainsData, Evaluator.ContainsOwnText, Evaluator.ContainsText, Evaluator.ContainsWholeOwnText, Evaluator.ContainsWholeText, Evaluator.CssNthEvaluator, Evaluator.Id, Evaluator.IndexEvaluator, Evaluator.IsEmpty, Evaluator.IsFirstChild, Evaluator.IsLastChild, Evaluator.IsOnlyChild, Evaluator.IsOnlyOfType, Evaluator.IsRoot, Evaluator.Matches, Evaluator.MatchesOwn, Evaluator.MatchesWholeOwnText, Evaluator.MatchesWholeText, Evaluator.Tag, Evaluator.TagEndsWith, Evaluator.TagStartsWith

public abstract class Evaluator extends Object
An Evaluator tests if an element (or a node) meets the selector's requirements. Obtain an evaluator for a given CSS selector with Selector.evaluatorOf(String css). If you are executing the same selector on many elements (or documents), it can be more efficient to compile and reuse an Evaluator than to reparse the selector on each invocation of select().

Each evaluator captures the behavior selected by jsoup.queryMode when constructed. Standalone evaluators use legacy behavior in check mode; they do not report compatibility differences.

If you construct and combine evaluators yourself, each child keeps the matching rules selected when it was created. The outer evaluator determines whether searches include the starting element and which element supplies the query context.

Evaluators are thread-safe and may be used concurrently across multiple documents.

See Also:
  • Constructor Details

  • Method Details

    • asPredicate

      Provides a Predicate for this Evaluator, matching the test Element.
      Parameters:
      root - the element the query starts from; see matches(Element, Element)
      Returns:
      a predicate that accepts an Element to test for matches with this Evaluator
      Since:
      1.17.1
    • matches

      public abstract boolean matches(Element root, Element element)
      Tests whether the element matches this evaluator.
      Parameters:
      root - the query context, used by :scope; for a Document, :scope matches its document element
      element - the element to test
      Returns:
      whether the element matches
    • reset

      protected void reset()
      Reset any internal state in this Evaluator before executing a new Collector evaluation.
    • cost

      protected int cost()
      A relative evaluator cost function. During evaluation, Evaluators are sorted by ascending cost as an optimization.
      Returns:
      the relative cost of this Evaluator