com.saxonica.extra
Class IndexedClosure

java.lang.Object
  extended bynet.sf.saxon.value.Value
      extended bynet.sf.saxon.value.Closure
          extended bynet.sf.saxon.value.MemoClosure
              extended bycom.saxonica.extra.IndexedClosure
All Implemented Interfaces:
Expression, java.io.Serializable, ValueRepresentation

public class IndexedClosure
extends MemoClosure

A subclass of MemoClosure that allows the construction of one or more indexes to provide rapid access to the items in the sequence.

There can be multiple indexes (a) because different expressions are used in filter predicates on this value, and (b) because of the problems of matching untyped atomic values. In an expression such as $seq[./A = $B], one index is built for each primitive type that occurs in the sequence $B. In this index, any untyped atomic values in ./A are converted to that primitive type. For an expression such as $seq[./A eq $B], a single index is built, in which untyped atomic values in ./A are converted to strings.

A particular difficulty arises where $B (in the expression $seq[./A eq $B]) is untypedAtomic. In this situation an index is built in which any untypedAtomic values in ./A are indexed as strings. While building the index, we note all the primitive types that occur in ./A, and then we convert the search term $B to each of these types in turn before doing the index lookup. In practice, of course, it is very rare for the index to be heterogeneous.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class net.sf.saxon.value.MemoClosure
MemoClosure.ProgressiveIterator
 
Field Summary
 
Fields inherited from class net.sf.saxon.value.MemoClosure
EMPTY, state
 
Fields inherited from class net.sf.saxon.value.Closure
depth, expression, inputIterator, savedXPathContext
 
Fields inherited from class net.sf.saxon.value.Value
EMPTY_CLASS_ARRAY
 
Fields inherited from interface net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD
 
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
 
Constructor Summary
IndexedClosure()
           
 
Method Summary
 SequenceIterator findItems(Expression use, SequenceIterator values, boolean convertUntypedToOther, AtomicComparer comparer, XPathContext context)
          Retrieve items that match a given index value
 boolean isIndexable()
          Determine wither this Closure is indexable
 Value materialize()
          Return a value containing all the items in the sequence returned by this SequenceIterator
 
Methods inherited from class net.sf.saxon.value.MemoClosure
getLength, isFullyRead, itemAt, iterate, process
 
Methods inherited from class net.sf.saxon.value.Closure
display, getCardinality, getImplementationMethod, getItemType, getSpecialProperties, make, makeIteratorClosure, reduce
 
Methods inherited from class net.sf.saxon.value.Value
asItem, asIterator, asValue, checkPermittedContents, convert, convertJavaObjectToXPath, convertToJava, effectiveBooleanValue, equals, evaluateAsString, evaluateItem, getDependencies, getIterator, getParentExpression, getStringValue, getStringValueCS, hashCode, iterateSubExpressions, makeQNameValue, optimize, promote, simplify, stringToNumber, toString, typeCheck
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IndexedClosure

public IndexedClosure()
Method Detail

isIndexable

public boolean isIndexable()
Determine wither this Closure is indexable

Overrides:
isIndexable in class Closure

findItems

public SequenceIterator findItems(Expression use,
                                  SequenceIterator values,
                                  boolean convertUntypedToOther,
                                  AtomicComparer comparer,
                                  XPathContext context)
                           throws XPathException
Retrieve items that match a given index value

Parameters:
use - the expression whose value is to be matched
values - the set of values to be found
convertUntypedToOther - true if untypedAtomic values are to be converted to the type of the other operand
comparer - AtomicComparer used to compare values for equality (encapsulates a collation if necessary)
context - the dynamic evaluation context
Returns:
an iterator over the items that match the specified values
Throws:
XPathException

materialize

public Value materialize()
                  throws XPathException
Return a value containing all the items in the sequence returned by this SequenceIterator

Overrides:
materialize in class MemoClosure
Returns:
the corresponding value
Throws:
XPathException