com.saxonica.expr

## Class IndexedLookupExpression

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - com.saxonica.expr.IndexedLookupExpression

- All Implemented Interfaces:
    Serializable, SourceLocator, LocationProvider, SaxonLocator, InstructionInfo, Locator

      public final class IndexedLookupExpression
      extends Expression

  An IndexedLookupExpression contains a base expression and a lookup expression. The base expression will always be a local variable reference. The expression returns true if the base expression (after atomization) contains the value of the lookup expression. That is, the expression is equivalent to exists(base[lookup]), except that lookup is evaluated with the same context as base.
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.expr.Expression

      `EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, EVENT_FEED_METHOD, INHERITED_CONTEXT, INSPECTION_CONTEXT, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, NAVIGATION_CONTEXT, NODE_VALUE_CONTEXT, PROCESS_METHOD, PUSH_SELECTION, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, W3C_CONSUMING, W3C_FREE_RANGING, W3C_GROUP_CONSUMING, W3C_MOTIONLESS, WATCH_METHOD`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IndexedLookupExpression(VariableReference base, Expression lookup, AtomicComparer comparer)` Constructor

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `computeCardinality()` Get the static cardinality of this expression
    `int` | `computeDependencies()` Determine which aspects of the context the expression depends on.
    `int` | `computeSpecialProperties()` Get the static properties of this expression (other than its type).
    `Expression` | `copy()` Copy an expression.
    `boolean` | `effectiveBooleanValue(XPathContext context)` Get the effective boolean value of the expression.
    `boolean` | `equals(Object other)` Is this expression the same as another expression?
    `Item` | `evaluateItem(XPathContext context)` Evaluate an expression as a single item.
    `void` | `explain(ExpressionPresenter destination)` Diagnostic print of expression structure.
    `AtomicComparer` | `getAtomicComparer()` Get the atomic comparer used
    `VariableReference` | `getBaseExpression()` Get the underlying expression
    `ExpressionCompiler` | `getExpressionCompiler()` Return the compiler of the IndexedLookup expression
    `ItemType` | `getItemType(TypeHierarchy th)` Get the data type of the items returned
    `Expression` | `getLookup()` Get the lookup expression
    `Expression` | `getUseExpression()` Get the expression that computes the key
    `int` | `hashCode()` get HashCode for comparing two expressions
    `Iterator<Expression>` | `iterateSubExpressions()` Get the immediate subexpressions of this expression
    `Expression` | `optimize(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)` Perform optimisation of an expression and its subexpressions.
    `Expression` | `promote(PromotionOffer offer, Expression parent)` Promote this expression if possible
    `boolean` | `replaceSubExpression(Expression original, Expression replacement)` Replace one subexpression by a replacement subexpression
    `Expression` | `simplify(ExpressionVisitor visitor)` Simplify an expression
    `Expression` | `typeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)` Type-check the expression

    - ### Methods inherited from class net.sf.saxon.expr.Expression

      `addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeStaticProperties, doPromotion, dynamicError, evaluateAsString, evaluatePendingUpdates, explain, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getEvaluationMethod, getExecutable, getExpressionName, getHostLanguage, getImplementationMethod, getIntegerBounds, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getStreamability, getStreamingAdjunct, getSystemId, getSystemId, hasVariableBinding, implementsStaticTypeCheck, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, iterateEvents, iterateSubExpressionInfo, markTailFunctionCalls, process, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, toPattern, toStreamingPattern, toString, typeError`

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

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

- - ### Constructor Detail

    - #### IndexedLookupExpression

          public IndexedLookupExpression(VariableReference base,
                                 Expression lookup,
                                 AtomicComparer comparer)

      Constructor
      Parameters:
        `base` - A sequence expression denoting the sequence to be searched
        `lookup` - An expression defining value to be sought

  - ### Method Detail

    - #### getItemType

          public ItemType getItemType(TypeHierarchy th)

      Get the data type of the items returned
      Specified by:
        `getItemType` in class `Expression`
      Parameters:
        `th` - the type hierarchy cache
      Returns:
        an integer representing the data type

    - #### getBaseExpression

          public VariableReference getBaseExpression()

      Get the underlying expression
      Returns:
        the expression being filtered

    - #### getLookup

          public Expression getLookup()

      Get the lookup expression
      Returns:
        the expression acting as the filter predicate

    - #### getUseExpression

          public Expression getUseExpression()

      Get the expression that computes the key
      Returns:
        the expression that computes the key

    - #### getAtomicComparer

          public AtomicComparer getAtomicComparer()

      Get the atomic comparer used
      Returns:
        the atomic comparer

    - #### simplify

          public Expression simplify(ExpressionVisitor visitor)
                              throws XPathException

      Simplify an expression
      Overrides:
        `simplify` in class `Expression`
      Parameters:
        `visitor` - an expression visitor
      Returns:
        the simplified expression
      Throws:
        `XPathException` - if an error is discovered during expression rewriting

    - #### typeCheck

          public Expression typeCheck(ExpressionVisitor visitor,
                             ExpressionVisitor.ContextItemType contextItemType)

      Type-check the expression
      Overrides:
        `typeCheck` in class `Expression`
      Parameters:
        `visitor` - an expression 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 expression after type-checking (potentially modified to add run-time checks and/or conversions)

    - #### optimize

          public Expression optimize(ExpressionVisitor visitor,
                            ExpressionVisitor.ContextItemType contextItemType)

      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 `Expression`
      Parameters:
        `visitor` - an expression 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

    - #### copy

          public Expression copy()

      Copy an expression. This makes a deep copy.
      Specified by:
        `copy` in class `Expression`
      Returns:
        the copy of the original expression

    - #### promote

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

      Promote this expression if possible
      Overrides:
        `promote` in class `Expression`
      Parameters:
        `offer` - details of the promotion that is possible
        `parent` -
      Returns:
        the promoted expression (or the original expression, unchanged)
      Throws:
        `XPathException` - if any error is detected

    - #### iterateSubExpressions

          public Iterator<Expression> iterateSubExpressions()

      Get the immediate subexpressions of this expression
      Overrides:
        `iterateSubExpressions` in class `Expression`
      Returns:
        the subexpressions, as an array

    - #### replaceSubExpression

          public boolean replaceSubExpression(Expression original,
                                     Expression replacement)

      Replace one subexpression by a replacement subexpression
      Overrides:
        `replaceSubExpression` in class `Expression`
      Parameters:
        `original` - the original subexpression
        `replacement` - the replacement subexpression
      Returns:
        true if the original subexpression is found

    - #### computeCardinality

          public int computeCardinality()

      Get the static cardinality of this expression
      Specified by:
        `computeCardinality` in class `Expression`
      Returns:
        the cardinality. The method attempts to determine the case where the filter predicate is guaranteed to select at most one item from the sequence being filtered

    - #### computeSpecialProperties

          public int computeSpecialProperties()

      Get the static properties of this expression (other than its type). The result is bit-significant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.
      Overrides:
        `computeSpecialProperties` in class `Expression`
      Returns:
        the static properties of the expression, as a bit-significant value

    - #### equals

          public boolean equals(Object other)

      Is this expression the same as another expression?
      Overrides:
        `equals` in class `Object`
      Parameters:
        `other` - the expression to be compared with this one
      Returns:
        true if the two expressions are statically equivalent

    - #### hashCode

          public int hashCode()

      get HashCode for comparing two expressions
      Overrides:
        `hashCode` in class `Object`
      Returns:
        the hash code

    - #### effectiveBooleanValue

          public boolean effectiveBooleanValue(XPathContext context)
                                        throws XPathException

      Description copied from class: `Expression`
      Get the effective boolean value of the expression. This returns false if the value is the empty sequence, a zero-length string, a number equal to zero, or the boolean false. Otherwise it returns true.
      Overrides:
        `effectiveBooleanValue` in class `Expression`
      Parameters:
        `context` - The context in which the expression is to be evaluated
      Returns:
        the effective boolean value
      Throws:
        `XPathException` - if any dynamic error occurs evaluating the expression

    - #### evaluateItem

          public Item evaluateItem(XPathContext context)
                            throws XPathException

      Description copied from class: `Expression`
      Evaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.
      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

    - #### computeDependencies

          public int computeDependencies()

      Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as XPathContext.VARIABLES and XPathContext.CURRENT_NODE
      Overrides:
        `computeDependencies` in class `Expression`
      Returns:
        the dependencies

    - #### getExpressionCompiler

          public ExpressionCompiler getExpressionCompiler()

      Return the compiler of the IndexedLookup expression
      Overrides:
        `getExpressionCompiler` in class `Expression`
      Returns:
        the relevant ExpressionCompiler

    - #### explain

          public void explain(ExpressionPresenter destination)

      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Specified by:
        `explain` in class `Expression`
      Parameters:
        `destination` - the expression presenter used to display the structure

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