Class SingleItemFilter

All Implemented Interfaces:
Serializable, SourceLocator, LocationProvider, SaxonLocator, InstructionInfo, Locator
Direct Known Subclasses:
FirstItemExpression, LastItemExpression

public abstract class SingleItemFilter extends UnaryExpression
A SingleItemFilter is an expression that selects zero or one items from a supplied sequence
See Also:
  • Constructor Details

    • SingleItemFilter

      public SingleItemFilter()
  • Method Details

    • optimize

      public Expression optimize(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType) throws XPathException
      Perform optimisation of an expression and its subexpressions.

      This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.

      Overrides:
      optimize in class UnaryExpression
      Parameters:
      visitor - an expresion visitor
      contextItemType - the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set to Type.ITEM_TYPE
      Returns:
      the original expression, rewritten if appropriate to optimize execution
      Throws:
      XPathException - if an error is discovered during this phase (typically a type error)
    • promote

      public Expression promote(PromotionOffer offer, Expression parent) throws XPathException
      Promote this expression if possible
      Overrides:
      promote in class UnaryExpression
      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 - the containing expression in the expression tree
      Returns:
      if the offer is not accepted, return this expression unchanged. Otherwise return the result of rewriting the expression to promote this subexpression
      Throws:
      XPathException - if any error is detected
    • computeCardinality

      public int computeCardinality()
      Get the static cardinality: this implementation is appropriate for [1] and [last()] which will always return something if the input is non-empty
      Overrides:
      computeCardinality in class UnaryExpression
      Returns:
      the computed cardinality, as one of the values StaticProperty.ALLOWS_ZERO_OR_ONE, StaticProperty.EXACTLY_ONE, StaticProperty.ALLOWS_ONE_OR_MORE, StaticProperty.ALLOWS_ZERO_OR_MORE