Package org.jsoup.select

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.MatchText, Evaluator.Tag, Evaluator.TagEndsWith, Evaluator.TagStartsWith

public abstract class Evaluator extends Object
An Evaluator tests if an element meets the selector's requirements. Obtain an evaluator for a given CSS selector with QueryParser.parse(java.lang.String). 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().

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

  • Constructor Details

    • Evaluator

      protected Evaluator()
  • Method Details

    • asPredicate

      public Predicate<Element> asPredicate(Element root)
      Provides a Predicate for this Evaluator, matching the test Element.
      Parameters:
      root - the root Element, for match evaluation
      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)
      Test if the element meets the evaluator's requirements.
      Parameters:
      root - Root of the matching subtree
      element - tested element
      Returns:
      Returns true if the requirements are met or false otherwise
    • 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