## org.exist.dom
Class AbstractNodeSet

    java.lang.Object
      org.exist.xquery.value.AbstractSequence
          org.exist.dom.AbstractNodeSet

All Implemented Interfaces:
  org.w3c.dom.NodeList, NodeSet, Sequence

Direct Known Subclasses:
  AVLTreeNodeSet, EmptyNodeSet, ExtArrayNodeSet, SortedNodeSet, VirtualNodeSet

public abstract class AbstractNodeSet
extends AbstractSequence
implements NodeSet

Abstract base class for all node set implementations. A node set is a special type of sequence, which contains only nodes. Class NodeSet thus implements the `Sequence` as well as the DOM `NodeList` interfaces. Please note that a node set may or may not contain duplicate nodes. Some implementations (e.g. `ExtArrayNodeSet`) remove duplicates when sorting the set.

Field Summary

Fields inherited from interface org.exist.dom.NodeSet
`ANCESTOR, DESCENDANT, EMPTY_SET, FOLLOWING, PRECEDING`

Fields inherited from interface org.exist.xquery.value.Sequence
`EMPTY_SEQUENCE`

Method Summary
`void` `add(Item item)` Add a sequence item to the node set.
`abstract void` `add(NodeProxy proxy)` Add a new proxy object to the node set.
`void` `add(NodeProxy proxy, int sizeHint)` Add a proxy object to the node set.
`abstract void` `addAll(NodeSet other)` Add all nodes from the given node set.
`void` `addAll(Sequence other)` Add all items from the given sequence to the node set.
`void` `clearContext(int contextId)` For every item in the sequence, clear any context-dependant information that is stored during query processing.
`abstract boolean` `contains(NodeProxy proxy)` Check if this node set contains a node matching the document and node-id of the given NodeProxy object.
`boolean` `containsDoc(DocumentImpl doc)` Check if this node set contains nodes belonging to the given document.
`NodeSet` `deepIntersection(NodeSet other)` Return a new node set, containing all nodes in this node set that are contained or have descendants in the other node set.
`NodeSet` `directSelectAttribute(QName qname, int contextId)` Optimized method to select attributes.
`NodeSet` `except(NodeSet other)` Return a new node set containing all nodes from this node set except those nodes which are also contained in the argument node set.
`abstract NodeProxy` `get(int pos)` Get the node at position pos within this node set.
`abstract NodeProxy` `get(NodeProxy p)` Get a node from this node set matching the document and node id of the given NodeProxy.
`NodeSet` `getAncestors(int contextId, boolean includeSelf)`
`NodeSet` `getContextNodes(int contextId)` Returns all context nodes associated with the nodes in this node set.
`DocumentSet` `getDocumentSet()` Returns the set of documents from which the node items in this sequence have been selected.
`int` `getIndexType()` If all nodes in this set have an index, returns the common supertype used to build the index, e.g.
`int` `getItemType()` Return the primary type to which all items in this sequence belong.
`abstract int` `getLength()` Return the number of nodes contained in this node set.
`NodeSet` `getParents(int contextId)` Return a new node set containing the parent nodes of all nodes in the current set.
`boolean` `getProcessInReverseOrder()`
`int` `getSizeHint(DocumentImpl doc)` Get a hint about how many nodes in this node set belong to the specified document.
`int` `getState()`
`boolean` `hasChanged(int previousState)`
`boolean` `hasMixedContent()`
`boolean` `hasTextIndex()`
`NodeSet` `intersection(NodeSet other)` Return a new node set, which represents the intersection of the current node set with the given node set.
`boolean` `isCached()` Returns true if the sequence is the result of a previous operation and has been cached.
`boolean` `isPersistentSet()`
`abstract org.w3c.dom.Node` `item(int pos)`
`abstract SequenceIterator` `iterate()` Returns an iterator over all items in the sequence.
`abstract NodeSetIterator` `iterator()` Return an iterator on the nodes in this list.
`NodeProxy` `parentWithChild(DocumentImpl doc, NodeId nodeId, boolean directParent, boolean includeSelf)` Check if the node identified by its node id has an ancestor contained in this node set and return the ancestor found.
`NodeProxy` `parentWithChild(NodeProxy proxy, boolean directParent, boolean includeSelf, int level)` Check if the given node has an ancestor contained in this node set and return the ancestor found.
`void` `removeDuplicates()` Explicitely remove all duplicate nodes from this sequence.
`NodeSet` `selectAncestorDescendant(NodeSet al, int mode, boolean includeSelf, int contextId)` Check if any descendant nodes are found within this node set for a given set of potential ancestor nodes.
`NodeSet` `selectAncestors(NodeSet descendants, boolean includeSelf, int contextId)` For a given set of potential ancestor nodes, return all ancestors having descendants in this node set.
`NodeSet` `selectFollowing(NodeSet fl)`
`NodeSet` `selectFollowingSiblings(NodeSet siblings, int contextId)` Select all nodes from the passed node set, which are following siblings of the nodes in this set.
`NodeSet` `selectParentChild(NodeSet al, int mode)` Check if any child nodes are found within this node set for a given set of potential parent nodes.
`NodeSet` `selectParentChild(NodeSet al, int mode, int contextId)` Check if any child nodes are found within this node set for a given set of potential ancestor nodes.
`NodeSet` `selectPreceding(NodeSet pl)`
`NodeSet` `selectPrecedingSiblings(NodeSet siblings, int contextId)` Select all nodes from the passed node set, which are preceding or following siblings of the nodes in this set.
`void` `setIsCached(boolean cached)` Indicates that the sequence is the result of a previous operation and has not been recomputed.
`void` `setProcessInReverseOrder(boolean inReverseOrder)`
`NodeSet` `toNodeSet()` Always returns this.
`java.lang.String` `toString()`
`NodeSet` `union(NodeSet other)` Return a new node set which represents the union of the current node set and the given node set.
`abstract SequenceIterator` `unorderedIterator()` Returns an iterator over all items in the sequence.

Methods inherited from class org.exist.xquery.value.AbstractSequence
`conversionPreference, convertTo, effectiveBooleanValue, getCardinality, getStringValue, hasMany, hasOne, isEmpty, itemAt, setSelfAsContext, toJavaObject`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.exist.dom.NodeSet
`get`

Methods inherited from interface org.exist.xquery.value.Sequence
`conversionPreference, convertTo, effectiveBooleanValue, getCardinality, getStringValue, hasMany, hasOne, isEmpty, itemAt, setSelfAsContext, toJavaObject`

Method Detail

### iterator

    public abstract NodeSetIterator iterator()

  Return an iterator on the nodes in this list. The iterator returns nodes according to the internal ordering of nodes (i.e. level first), not in document- order.

  Specified by:
    `iterator` in interface `NodeSet`

### iterate

    public abstract SequenceIterator iterate()
                                      throws XPathException

  Description copied from interface: `Sequence`
  Returns an iterator over all items in the sequence. The items are returned in document order where applicable.

  Specified by:
    `iterate` in interface `Sequence`
  Specified by:
    `iterate` in class `AbstractSequence`
  Throws:
    `XPathException`

### unorderedIterator

    public abstract SequenceIterator unorderedIterator()

  Description copied from interface: `Sequence`
  Returns an iterator over all items in the sequence. The returned items may - but need not - to be in document order.

  Specified by:
    `unorderedIterator` in interface `Sequence`
  Specified by:
    `unorderedIterator` in class `AbstractSequence`

### getItemType

    public int getItemType()

  Description copied from interface: `Sequence`
  Return the primary type to which all items in this sequence belong. This is `Type.NODE` for node sets, `Type.ITEM` for other sequences with mixed items.

  Specified by:
    `getItemType` in interface `Sequence`
  Specified by:
    `getItemType` in class `AbstractSequence`

### contains

    public abstract boolean contains(NodeProxy proxy)

  Check if this node set contains a node matching the document and node-id of the given NodeProxy object.

  Specified by:
    `contains` in interface `NodeSet`
  Parameters:
    `proxy` -

### containsDoc

    public boolean containsDoc(DocumentImpl doc)

  Check if this node set contains nodes belonging to the given document.

  Specified by:
    `containsDoc` in interface `NodeSet`
  Parameters:
    `doc` -

### add

    public abstract void add(NodeProxy proxy)

  Add a new proxy object to the node set. Please note: node set implementations may allow duplicates.

  Specified by:
    `add` in interface `NodeSet`
  Parameters:
    `proxy` -

### add

    public void add(NodeProxy proxy,
                    int sizeHint)

  Add a proxy object to the node set. The sizeHint parameter gives a hint about the number of items to be expected for the current document.

  Specified by:
    `add` in interface `NodeSet`
  Parameters:
    `proxy` -
    `sizeHint` -

### add

    public void add(Item item)
             throws XPathException

  Add a sequence item to the node set. The item has to be a subtype of node.

  Specified by:
    `add` in interface `Sequence`
  Specified by:
    `add` in class `AbstractSequence`
  Throws:
    `XPathException`

### addAll

    public void addAll(Sequence other)
                throws XPathException

  Add all items from the given sequence to the node set. All items have to be a subtype of node.

  Specified by:
    `addAll` in interface `Sequence`
  Overrides:
    `addAll` in class `AbstractSequence`
  Parameters:
    `other` -
  Throws:
    `XPathException`

### addAll

    public abstract void addAll(NodeSet other)

  Add all nodes from the given node set.

  Specified by:
    `addAll` in interface `NodeSet`
  Parameters:
    `other` -

### getLength

    public abstract int getLength()

  Return the number of nodes contained in this node set.

  Specified by:
    `getLength` in interface `Sequence`
  Specified by:
    `getLength` in class `AbstractSequence`

### setIsCached

    public void setIsCached(boolean cached)

  Description copied from interface: `Sequence`
  Indicates that the sequence is the result of a previous operation and has not been recomputed.

  Specified by:
    `setIsCached` in interface `Sequence`
  Overrides:
    `setIsCached` in class `AbstractSequence`

### isCached

    public boolean isCached()

  Description copied from interface: `Sequence`
  Returns true if the sequence is the result of a previous operation and has been cached.

  Specified by:
    `isCached` in interface `Sequence`
  Overrides:
    `isCached` in class `AbstractSequence`

### removeDuplicates

    public void removeDuplicates()

  Description copied from interface: `Sequence`
  Explicitely remove all duplicate nodes from this sequence.

  Specified by:
    `removeDuplicates` in interface `Sequence`

### item

    public abstract org.w3c.dom.Node item(int pos)

  Specified by:
    `item` in interface `org.w3c.dom.NodeList`

### get

    public abstract NodeProxy get(int pos)

  Get the node at position pos within this node set.

  Specified by:
    `get` in interface `NodeSet`
  Parameters:
    `pos` -

### get

    public abstract NodeProxy get(NodeProxy p)

  Get a node from this node set matching the document and node id of the given NodeProxy.

  Specified by:
    `get` in interface `NodeSet`
  Parameters:
    `p` -

### getDocumentSet

    public DocumentSet getDocumentSet()

  Description copied from interface: `Sequence`
  Returns the set of documents from which the node items in this sequence have been selected. This is for internal use only.

  Specified by:
    `getDocumentSet` in interface `NodeSet`
  Overrides:
    `getDocumentSet` in class `AbstractSequence`

### selectParentChild

    public NodeSet selectParentChild(NodeSet al,
                                     int mode)

  Check if any child nodes are found within this node set for a given set of potential parent nodes. If mode is `NodeSet.DESCENDANT`, the returned node set will contain all child nodes found in this node set for each parent node. If mode is `NodeSet.ANCESTOR`, the returned set will contain those parent nodes, for which children have been found.

  Specified by:
    `selectParentChild` in interface `NodeSet`
  Parameters:
    `al` - a node set containing potential parent nodes
    `mode` - selection mode

### selectParentChild

    public NodeSet selectParentChild(NodeSet al,
                                     int mode,
                                     int contextId)

  Check if any child nodes are found within this node set for a given set of potential ancestor nodes. If mode is `NodeSet.DESCENDANT`, the returned node set will contain all child nodes found in this node set for each parent node. If mode is `NodeSet.ANCESTOR`, the returned set will contain those parent nodes, for which children have been found.

  Specified by:
    `selectParentChild` in interface `NodeSet`
  Parameters:
    `al` - a node set containing potential parent nodes
    `mode` - selection mode
    `contextId` - used to track context nodes when evaluating predicate expressions. If contextId != `Expression.NO_CONTEXT_ID`, the current context will be added to each result of the of the selection.

### selectAncestorDescendant

    public NodeSet selectAncestorDescendant(NodeSet al,
                                            int mode,
                                            boolean includeSelf,
                                            int contextId)

  Check if any descendant nodes are found within this node set for a given set of potential ancestor nodes. If mode is `NodeSet.DESCENDANT`, the returned node set will contain all descendant nodes found in this node set for each ancestor. If mode is `NodeSet.ANCESTOR`, the returned set will contain those ancestor nodes, for which descendants have been found.

  Specified by:
    `selectAncestorDescendant` in interface `NodeSet`
  Parameters:
    `al` - a node set containing potential parent nodes
    `mode` - selection mode
    `includeSelf` - if true, check if the ancestor node itself is contained in the set of descendant nodes (descendant-or-self axis)
    `contextId` - used to track context nodes when evaluating predicate expressions. If contextId != `Expression.NO_CONTEXT_ID`, the current context will be added to each result of the of the selection.

### selectAncestors

    public NodeSet selectAncestors(NodeSet descendants,
                                   boolean includeSelf,
                                   int contextId)

  For a given set of potential ancestor nodes, return all ancestors having descendants in this node set.

  Specified by:
    `selectAncestors` in interface `NodeSet`
  Parameters:
    `descendants` - node set containing potential ancestors
    `includeSelf` - if true, check if the ancestor node itself is contained in this node set (ancestor-or-self axis)
    `contextId` -

### selectFollowing

    public NodeSet selectFollowing(NodeSet fl)
                            throws XPathException

  Specified by:
    `selectFollowing` in interface `NodeSet`
  Throws:
    `XPathException`

### selectPreceding

    public NodeSet selectPreceding(NodeSet pl)
                            throws XPathException

  Specified by:
    `selectPreceding` in interface `NodeSet`
  Throws:
    `XPathException`

### selectPrecedingSiblings

    public NodeSet selectPrecedingSiblings(NodeSet siblings,
                                           int contextId)

  Select all nodes from the passed node set, which are preceding or following siblings of the nodes in this set. If mode is `NodeSet.FOLLOWING`, only nodes following the context node are selected. `NodeSet.PRECEDING` selects preceding nodes.

  Specified by:
    `selectPrecedingSiblings` in interface `NodeSet`
  Parameters:
    `siblings` - a node set containing potential siblings
    `contextId` - used to track context nodes when evaluating predicate expressions. If contextId != `Expression.NO_CONTEXT_ID`, the current context will be added to each result of the of the selection.

### selectFollowingSiblings

    public NodeSet selectFollowingSiblings(NodeSet siblings,
                                           int contextId)

  Description copied from interface: `NodeSet`
  Select all nodes from the passed node set, which are following siblings of the nodes in this set.

  Specified by:
    `selectFollowingSiblings` in interface `NodeSet`
  Parameters:
    `siblings` - a node set containing potential siblings
    `contextId` - used to track context nodes when evaluating predicate expressions. If contextId != `Expression.NO_CONTEXT_ID`, the current context will be added to each result of the of the selection.

### directSelectAttribute

    public NodeSet directSelectAttribute(QName qname,
                                         int contextId)

  Description copied from interface: `NodeSet`
  Optimized method to select attributes. Use this if the context has just one or two nodes. Attributes will be directly looked up in the persistent DOM store.

  Specified by:
    `directSelectAttribute` in interface `NodeSet`
  Parameters:
    `qname` - the QName of the attribute
    `contextId` - used to track context nodes when evaluating predicate expressions. If contextId != `Expression.NO_CONTEXT_ID`, the current context will be added to each result of the of the selection.

### parentWithChild

    public NodeProxy parentWithChild(DocumentImpl doc,
                                     NodeId nodeId,
                                     boolean directParent,
                                     boolean includeSelf)

  Description copied from interface: `NodeSet`
  Check if the node identified by its node id has an ancestor contained in this node set and return the ancestor found. If directParent is true, only immediate ancestors (parents) are considered. Otherwise the method will call itself recursively for all the node's parents. If includeSelf is true, the method returns also true if the node itself is contained in the node set.

  Specified by:
    `parentWithChild` in interface `NodeSet`

### parentWithChild

    public NodeProxy parentWithChild(NodeProxy proxy,
                                     boolean directParent,
                                     boolean includeSelf,
                                     int level)

  Check if the given node has an ancestor contained in this node set and return the ancestor found. If directParent is true, only immediate ancestors (parents) are considered. Otherwise the method will call itself recursively for all the node's parents. If includeSelf is true, the method returns also true if the node itself is contained in the node set.

  Specified by:
    `parentWithChild` in interface `NodeSet`

### getParents

    public NodeSet getParents(int contextId)

  Return a new node set containing the parent nodes of all nodes in the current set.

  Specified by:
    `getParents` in interface `NodeSet`

### getAncestors

    public NodeSet getAncestors(int contextId,
                                boolean includeSelf)

  Specified by:
    `getAncestors` in interface `NodeSet`

### getSizeHint

    public int getSizeHint(DocumentImpl doc)

  Get a hint about how many nodes in this node set belong to the specified document. This is just used for allocating new node sets. The information does not need to be exact. -1 is returned if the size cannot be determined (the default).

  Specified by:
    `getSizeHint` in interface `NodeSet`
  Parameters:
    `doc` -

### intersection

    public NodeSet intersection(NodeSet other)

  Return a new node set, which represents the intersection of the current node set with the given node set.

  Specified by:
    `intersection` in interface `NodeSet`
  Parameters:
    `other` -

### deepIntersection

    public NodeSet deepIntersection(NodeSet other)

  Description copied from interface: `NodeSet`
  Return a new node set, containing all nodes in this node set that are contained or have descendants in the other node set.

  Specified by:
    `deepIntersection` in interface `NodeSet`
  Parameters:
    `other` -

### except

    public NodeSet except(NodeSet other)

  Description copied from interface: `NodeSet`
  Return a new node set containing all nodes from this node set except those nodes which are also contained in the argument node set.

  Specified by:
    `except` in interface `NodeSet`
  Parameters:
    `other` -

### setProcessInReverseOrder

    public void setProcessInReverseOrder(boolean inReverseOrder)

  Specified by:
    `setProcessInReverseOrder` in interface `NodeSet`

### getProcessInReverseOrder

    public boolean getProcessInReverseOrder()

  Specified by:
    `getProcessInReverseOrder` in interface `NodeSet`

### union

    public NodeSet union(NodeSet other)

  Return a new node set which represents the union of the current node set and the given node set.

  Specified by:
    `union` in interface `NodeSet`
  Parameters:
    `other` -

### getContextNodes

    public NodeSet getContextNodes(int contextId)

  Returns all context nodes associated with the nodes in this node set.

  Specified by:
    `getContextNodes` in interface `NodeSet`
  Parameters:
    `contextId` - used to track context nodes when evaluating predicate expressions. If contextId != `Expression.NO_CONTEXT_ID`, the current context will be added to each result of the of the selection.

### toNodeSet

    public NodeSet toNodeSet()
                      throws XPathException

  Always returns this.

  Specified by:
    `toNodeSet` in interface `Sequence`
  Throws:
    `XPathException` - if the sequence contains items which are not nodes.
  See Also:
    `Sequence.toNodeSet()`

### getState

    public int getState()

  Specified by:
    `getState` in interface `NodeSet`

### hasChanged

    public boolean hasChanged(int previousState)

  Specified by:
    `hasChanged` in interface `NodeSet`

### getIndexType

    public int getIndexType()

  If all nodes in this set have an index, returns the common supertype used to build the index, e.g. xs:integer or xs:string. If the nodes have different index types or no node has been indexed, returns `Type.ITEM`.

  Specified by:
    `getIndexType` in interface `NodeSet`
  See Also:
    `GeneralComparison`, `ValueComparison`

### hasTextIndex

    public boolean hasTextIndex()

  Specified by:
    `hasTextIndex` in interface `NodeSet`

### hasMixedContent

    public boolean hasMixedContent()

  Specified by:
    `hasMixedContent` in interface `NodeSet`

### clearContext

    public void clearContext(int contextId)

  Description copied from interface: `Sequence`
  For every item in the sequence, clear any context-dependant information that is stored during query processing. This feature is used for node sets, which may store information about their context node.

  Specified by:
    `clearContext` in interface `Sequence`
  Overrides:
    `clearContext` in class `AbstractSequence`

### isPersistentSet

    public boolean isPersistentSet()

  Specified by:
    `isPersistentSet` in interface `Sequence`
  Overrides:
    `isPersistentSet` in class `AbstractSequence`

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `AbstractSequence`

Copyright (C) Wolfgang Meier. All rights reserved.