Class Precondition

  • Direct Known Subclasses:
    Precondition.BooleanPrecondition, Precondition.NumericComparisonPrecondition, Precondition.StringHashPrecondition

    public abstract class Precondition
    extends java.lang.Object
    A Precondition is a boolean condition that must be true if a pattern is to match (but in general is not a sufficient condition for the pattern to match). Preconditions may be defined in terms of "characteristics": that is, properties of the item being matched. When an item is matched against a RuleChain to find the best matching rule, subexpressions used by more than one rule may be evaluated as characteristics, so they are not evaluated repeatedly. Preconditions are shared by multiple rules. Evaluating a precondition for one rule may ensure that the patterns for other rules do not need to be evaluated.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Precondition.BooleanPrecondition
      A BooleanPrecondition can in principle test any boolean characteristic of a pattern.
      static class  Precondition.NumericComparisonPrecondition
      A numeric comparison precondition is used for patterns containing a predicate that compares some expression E with a numeric constant.
      static class  Precondition.StringHashPrecondition
      A StringHashPrecondition compares a characteristic in the form of a set of integer hash codes against a constant hash code; the precondition is satisfied if the constant hash code is present in the set.
    • Constructor Summary

      Constructors 
      Constructor Description
      Precondition()  
    • Constructor Detail

      • Precondition

        public Precondition()
    • Method Detail

      • setSlotNumber

        public void setSlotNumber​(int slotNumber)
        Allocate a slot number indicating where in the data maintained by the PreconditionMatcher the value of this precondition should be held
        Parameters:
        slotNumber - the slot number to be used for the value of this precondition
      • isSatisfied

        public final boolean isSatisfied​(PreconditionMatcher matcher)
                                  throws XPathException
        Ask whether the precondition is satisfied, making use of caching
        Parameters:
        matcher - The PreconditionMatcher holds the values of conditions that have already been matched, which is therefore used as a cache of values that do not need to be evaluated repeatedly. In addition it holds the dynamic evaluation context; the context item is the item being matched.
        Returns:
        true if the precondition is satisfied
        Throws:
        XPathException - if evaluation of the precondition fails with a dynamic error
      • testPrecondition

        protected abstract boolean testPrecondition​(PreconditionMatcher matcher)
                                             throws XPathException
        Compute the value of the precondition for a given item. The item in question is the context item in the dynamic context held in the PreconditionMatcher
        Parameters:
        matcher - the PreconditionMatcher: holds the dynamic context for evaluation.
        Returns:
        true if the precondition is satisfied
        Throws:
        XPathException - if evaluation of the precondition fails with a dynamic error