Class LearningEvaluator

  • All Implemented Interfaces:
    SequenceEvaluator

    public class LearningEvaluator
    extends java.lang.Object
    implements SequenceEvaluator
    A LearningEvaluator initially performs lazy incremental evaluation of an expression; but if this proves unproductive, it switches after a while to eager evaluation. Lazy evaluation is considered unproductive if the input sequence is read to completion. A MemoClosure reports back if the input sequence is read to completion, and if the number of sequences that are completely read is equal to the total number of evaluations, lazy evaluation is abandoned.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Sequence evaluate​(XPathContext context)
      Evaluate a construct to produce a value (which might be a lazily evaluated Sequence)
      boolean hasDecidedToEvaluateEagerly()
      Ask whether the LearningEvaluator has decided to use eager evaluation always
      void reportCompletion​(int serialNumber)
      Callback method called when a lazily-evaluated expression has been read to completion
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LearningEvaluator

        public LearningEvaluator​(Expression expr,
                                 SequenceEvaluator lazy)
        Construct a LearningEvaluator
        Parameters:
        expr - the expression to be evaluated
        lazy - a SequenceEvaluator that evaluates the expression. Although this is generally obtained by calling getElaborator().lazily(), it does not necessarily perform lazy evaluation; some expressions such as literals and variable references choose to evaluate themselves eagerly all the time.
    • Method Detail

      • evaluate

        public Sequence evaluate​(XPathContext context)
                          throws XPathException
        Evaluate a construct to produce a value (which might be a lazily evaluated Sequence)
        Specified by:
        evaluate in interface SequenceEvaluator
        Parameters:
        context - the evaluation context
        Returns:
        a Sequence (not necessarily grounded)
        Throws:
        XPathException - if a dynamic error occurs during the evaluation.
      • reportCompletion

        public void reportCompletion​(int serialNumber)
        Callback method called when a lazily-evaluated expression has been read to completion
        Parameters:
        serialNumber - identifies the evaluation
      • hasDecidedToEvaluateEagerly

        public boolean hasDecidedToEvaluateEagerly()
        Ask whether the LearningEvaluator has decided to use eager evaluation always
        Returns:
        true if sufficient evaluations have been performed to determine that lazy evaluation offers no benefits