net.sf.saxon.pattern

## Class PatternWithPredicate

- java.lang.Object
- - net.sf.saxon.pattern.Pattern
  - - net.sf.saxon.pattern.PatternWithPredicate

- All Implemented Interfaces:
    Serializable, SourceLocator, Container, PatternFinder

      public class PatternWithPredicate
      extends Pattern

  Class for handling patterns with simple non-positional boolean predicates
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PatternWithPredicate(Pattern basePattern, Expression predicate)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `allocateSlots(SlotManager slotManager, int nextFree)` Allocate slots to any variables used within the pattern
    `Pattern` | `analyze(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)` Type-check the pattern.
    `void` | `bindCurrent(Binding binding)` Replace any calls on current() by a variable reference bound to the supplied binding
    `double` | `getDefaultPriority()` Determine the default priority to use if this pattern appears as a match pattern for a template with no explicit priority attribute.
    `int` | `getFingerprint()` Determine the name fingerprint of nodes to which this pattern applies.
    `ItemType` | `getItemType()` Get an ItemType that all the items matching this pattern must satisfy
    `int` | `getNodeKind()` Determine the types of nodes to which this pattern applies.
    `boolean` | `isMotionless(boolean allowExtensions)` Test whether a pattern is motionless, that is, whether it can be evaluated against a node without repositioning the input stream.
    `Iterator<Expression>` | `iterateSubExpressions()` Iterate over the subexpressions within this pattern
    `boolean` | `matches(Item item, XPathContext context)` Determine whether this Pattern matches the given Node.
    `void` | `promote(PromotionOffer offer, Expression parent)` Offer promotion for subexpressions within this pattern.

    - ### Methods inherited from class net.sf.saxon.pattern.Pattern

      `getColumnNumber, getContainerGranularity, getDependencies, getExecutable, getHostLanguage, getLineNumber, getLocationProvider, getPublicId, getSystemId, make, matchesBeneathAnchor, replaceCurrent, replaceSubExpression, selectNodes, setExecutable, setLineNumber, setOriginalText, setSystemId, simplify, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### PatternWithPredicate

          public PatternWithPredicate(Pattern basePattern,
                              Expression predicate)

  - ### Method Detail

    - #### bindCurrent

          public void bindCurrent(Binding binding)

      Replace any calls on current() by a variable reference bound to the supplied binding
      Overrides:
        `bindCurrent` in class `Pattern`

    - #### promote

          public void promote(PromotionOffer offer,
                     Expression parent)
                       throws XPathException

      Offer promotion for subexpressions within this pattern. The offer will be accepted if the subexpression is not dependent on the factors (e.g. the context item) identified in the PromotionOffer. By default the offer is not accepted - this is appropriate in the case of simple expressions such as constant values and variable references where promotion would give no performance advantage. This method is always called at compile time.

      Unlike the corresponding method on `Expression`, this method does not return anything: it can make internal changes to the pattern, but cannot return a different pattern. Only certain kinds of promotion are applicable within a pattern: specifically, promotions affecting local variable references within the pattern.

      Overrides:
        `promote` in class `Pattern`
      Parameters:
        `offer` - details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression
        `parent` -
      Throws:
        `XPathException` - if any error is detected

    - #### allocateSlots

          public int allocateSlots(SlotManager slotManager,
                          int nextFree)

      Allocate slots to any variables used within the pattern
      Overrides:
        `allocateSlots` in class `Pattern`
      Parameters:
        `slotManager` - holds details of the allocated slots
        `nextFree` - the next slot that is free to be allocated @return the next slot that is free to be allocated
      Returns:
        the next slot that is free to be allocated

    - #### getNodeKind

          public int getNodeKind()

      Determine the types of nodes to which this pattern applies. Used for optimisation. For patterns that match nodes of several types, return Type.NODE. For patterns that do not match nodes, return -1.
      Overrides:
        `getNodeKind` in class `Pattern`
      Returns:
        the type of node matched by this pattern. e.g. Type.ELEMENT or Type.TEXT

    - #### getFingerprint

          public int getFingerprint()

      Determine the name fingerprint of nodes to which this pattern applies. Used for optimisation.
      Overrides:
        `getFingerprint` in class `Pattern`
      Returns:
        A fingerprint that the nodes must match, or -1 if it can match multiple fingerprints, or it if matches atomic values

    - #### matches

          public boolean matches(Item item,
                        XPathContext context)
                          throws XPathException

      Determine whether this Pattern matches the given Node.
      Specified by:
        `matches` in class `Pattern`
      Parameters:
        `item` - The NodeInfo representing the Element or other node to be tested against the Pattern
        `context` - The dynamic context. Only relevant if the pattern uses variables, or contains calls on functions such as document() or key().
      Returns:
        true if the node matches the Pattern, false otherwise
      Throws:
        `XPathException` - if an error occurs while matching the pattern (the caller will usually treat this the same as a false result)

    - #### getItemType

          public ItemType getItemType()

      Get an ItemType that all the items matching this pattern must satisfy
      Specified by:
        `getItemType` in class `Pattern`
      Returns:
        an ItemType, as specific as possible, which all the matching items satisfy

    - #### iterateSubExpressions

          public Iterator<Expression> iterateSubExpressions()

      Iterate over the subexpressions within this pattern
      Overrides:
        `iterateSubExpressions` in class `Pattern`
      Returns:
        an iterator over the subexpressions. Default implementation returns an empty sequence

    - #### analyze

          public Pattern analyze(ExpressionVisitor visitor,
                        ExpressionVisitor.ContextItemType contextItemType)
                          throws XPathException

      Type-check the pattern.
      Overrides:
        `analyze` in class `Pattern`
      Parameters:
        `visitor` - the expression visitor
        `contextItemType` - the type of the context item at the point where the pattern is defined. Set to null if it is known that the context item is undefined.
      Returns:
        the optimised Pattern
      Throws:
        `XPathException`

    - #### getDefaultPriority

          public double getDefaultPriority()

      Determine the default priority to use if this pattern appears as a match pattern for a template with no explicit priority attribute.
      Overrides:
        `getDefaultPriority` in class `Pattern`
      Returns:
        the default priority for the pattern

    - #### isMotionless

          public boolean isMotionless(boolean allowExtensions)

      Description copied from class: `Pattern`
      Test whether a pattern is motionless, that is, whether it can be evaluated against a node without repositioning the input stream. This is a necessary condition for patterns used as the match pattern of a streamed template rule.
      Overrides:
        `isMotionless` in class `Pattern`
      Parameters:
        `allowExtensions` - if false, the result is determined strictly according to the W3C "guaranteed streamability rules. If true, Saxon extensions are permitted: that is, constructs may be recognized as motionless by Saxon even if they are not recognized as motionless by the W3C rules.
      Returns:
        true if the pattern is motionless, that is, if it can be evaluated against a streamed node without changing the position in the streamed input file

Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.