Class FirstItemExpression

All Implemented Interfaces:
ExportAgent, Locatable, IdentityComparable, Traceable

public final class FirstItemExpression extends SingleItemFilter
A FirstItemExpression returns the first item in the sequence returned by a given base expression
  • Method Details

    • makeFirstItemExpression

      public static Expression makeFirstItemExpression(Expression base)
      Static factory method
      Parameters:
      base - A sequence expression denoting sequence whose first item is to be returned
      Returns:
      the FirstItemExpression, or an equivalent
    • computeCardinality

      protected 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 SingleItemFilter
      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. May also return StaticProperty.ALLOWS_ZERO if the result is known to be an empty sequence, or StaticProperty.ALLOWS_MANY if if is known to return a sequence of length two or more.
    • copy

      public Expression copy(RebindingMap rebindings)
      Copy an expression. This makes a deep copy.
      Specified by:
      copy in class Expression
      Parameters:
      rebindings - variables that must be re-bound
      Returns:
      the copy of the original expression
    • toPattern

      public Pattern toPattern(Configuration config) throws XPathException
      Convert this expression to an equivalent XSLT pattern
      Overrides:
      toPattern in class Expression
      Parameters:
      config - the Saxon configuration
      Returns:
      the equivalent pattern
      Throws:
      XPathException - if conversion is not possible
    • getImplementationMethod

      public int getImplementationMethod()
      An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.
      Specified by:
      getImplementationMethod in class Expression
      Returns:
      the implementation method, for example Expression.ITERATE_METHOD or Expression.EVALUATE_METHOD or Expression.PROCESS_METHOD
    • evaluateItem

      public Item evaluateItem(XPathContext context) throws XPathException
      Evaluate the expression
      Overrides:
      evaluateItem in class Expression
      Parameters:
      context - The context in which the expression is to be evaluated
      Returns:
      the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
      Throws:
      XPathException - if any dynamic error occurs evaluating the expression
    • getExpressionName

      public String getExpressionName()
      Description copied from class: Expression
      Get a name identifying the kind of expression, in terms meaningful to a user.
      Overrides:
      getExpressionName in class Expression
      Returns:
      a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in export() output displaying the expression.
    • toShortString

      public String toShortString()
      Description copied from class: Expression
      Produce a short string identifying the expression for use in error messages
      Overrides:
      toShortString in class UnaryExpression
      Returns:
      a short string, sufficient to identify the expression
    • getStreamerName

      public String getStreamerName()
      Get the (partial) name of a class that supports streaming of this kind of expression
      Overrides:
      getStreamerName in class Expression
      Returns:
      the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class
    • getElaborator

      public Elaborator getElaborator()
      Make an elaborator for this expression
      Overrides:
      getElaborator in class Expression
      Returns:
      a suitable elaborator