org.exist.dom
Class ExtArrayNodeSet

java.lang.Object
  extended by org.exist.xquery.value.AbstractSequence
      extended by org.exist.dom.AbstractNodeSet
          extended by org.exist.dom.ExtArrayNodeSet
All Implemented Interfaces:
DocumentSet, NodeSet, Sequence, NodeList

public class ExtArrayNodeSet
extends AbstractNodeSet
implements DocumentSet

A fast node set implementation, based on arrays to store nodes and documents. The class uses an array to store all nodes belonging to one document. Another sorted array is used to keep track of the document ids. For each document, we maintain an inner class, Part, which stores the array of nodes. Nodes are just appended to the nodes array. No order is guaranteed and calls to get/contains may fail although a node is present in the array (get/contains do a binary search and thus assume that the set is sorted). Also, duplicates are allowed. If you have to ensure that calls to get/contains return valid results at any time and no duplicates occur, use class AVLTreeNodeSet. Use this class, if you can either ensure that items are added in order, or no calls to contains/get are required during the creation phase. Only after a call to one of the iterator methods, the set will get sorted and duplicates removed.

Since:
0.9.3
Author:
Wolfgang

Field Summary
 
Fields inherited from interface org.exist.dom.DocumentSet
EMPTY_DOCUMENT_SET
 
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
 
Constructor Summary
ExtArrayNodeSet()
          Creates a new ExtArrayNodeSet instance.
ExtArrayNodeSet(int initialArraySize)
          Creates a new ExtArrayNodeSet instance.
ExtArrayNodeSet(int initialDocsCount, int initialArraySize)
          Creates a new ExtArrayNodeSet instance.
 
Method Summary
 void add(NodeProxy proxy)
          The method add
 void add(NodeProxy proxy, int sizeHint)
          Add a new node to the set.
 void addAll(NodeSet other)
          Add all nodes from the given node set.
 boolean contains(DocumentSet other)
           
 boolean contains(int docId)
           
 boolean contains(NodeProxy proxy)
          Check if this node set contains a node matching the document and node-id of the given NodeProxy object.
 String debugParts()
          The method debugParts
 NodeSet docsToNodeSet()
           
 boolean equalDocs(DocumentSet other)
           
 NodeSet filterDocuments(ExtArrayNodeSet otherSet)
          The method filterDocuments
 NodeProxy get(DocumentImpl doc, NodeId nodeId)
           
 NodeProxy get(int pos)
          Get the node at position pos within this node set.
 NodeProxy get(NodeProxy p)
          Get a node from this node set matching the document and node id of the given NodeProxy.
 Iterator getCollectionIterator()
          The method getCollectionIterator
 NodeSet getDescendantsInSet(NodeSet al, boolean childOnly, boolean includeSelf, int mode, int contextId, boolean copyMatches)
          The method getDescendantsInSet
 DocumentImpl getDoc(int docId)
           
 DocumentImpl getDocumentAt(int pos)
           
 int getDocumentCount()
           
 Iterator getDocumentIterator()
           
 DocumentSet getDocumentSet()
          The method getDocumentSet
 int getIndexType()
          If all nodes in this set have an index, returns the common supertype used to build the index, e.g.
 int getItemCount()
          Returns the number of items contained in the sequence.
 int getItemType()
          The method getItemType
 int getLength()
          Return the number of nodes contained in this node set.
 XmldbURI[] getNames()
           
 int getSizeHint(DocumentImpl doc)
          The method getSizeHint
 int getState()
           
 boolean hasChanged(int previousState)
           
 NodeProxy hasDescendantsInSet(DocumentImpl doc, NodeId ancestorId, boolean includeSelf, int contextId)
          The method hasDescendantsInSet
 boolean hasOne()
          The method hasOne
 DocumentSet intersection(DocumentSet other)
           
 boolean isCacheable()
           
 boolean isEmpty()
          The method isEmpty
 Node item(int pos)
           
 Item itemAt(int pos)
          Returns the item located at the specified position within this sequence.
 SequenceIterator iterate()
          Returns an iterator over all items in the sequence.
 ByDocumentIterator iterateByDocument()
           
 NodeSetIterator iterator()
          Return an iterator on the nodes in this list.
 void lock(DBBroker broker, boolean exclusive, boolean checkExisting)
           
 void mergeDuplicates()
          Remove all duplicate nodes, but merge their contexts.
 NodeProxy parentWithChild(DocumentImpl doc, NodeId nodeId, boolean directParent, boolean includeSelf)
          The method parentWithChild
 void reset()
          The method reset
 NodeSet selectAncestorDescendant(NodeSet al, int mode, boolean includeSelf, int contextId, boolean copyMatches)
          Check if any descendant nodes are found within this node set for a given set of potential ancestor nodes.
 NodeSet selectAncestors(NodeSet al, boolean includeSelf, int contextId)
          For a given set of potential ancestor nodes, return all ancestors having descendants in this node set.
 NodeSet selectFollowingSiblings(NodeSet siblings, int contextId)
          The method selectFollowingSiblings
 NodeSet selectParentChild(NodeSet al, int mode, int contextId)
          The method selectParentChild
 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 setDocumentSet(DocumentSet docs)
          The method setDocumentSet
 void setSelfAsContext(int contextId)
           
 void setSorted(DocumentImpl document, boolean sorted)
          The method setSorted
 void sort()
          The method sort
 void sort(boolean mergeContexts)
          The method sort
 void sortInDocumentOrder()
          The method sortInDocumentOrder
 String toString()
          The method toString
 void unlock(boolean exclusive)
           
 SequenceIterator unorderedIterator()
          Returns an iterator over all items in the sequence.
 
Methods inherited from class org.exist.dom.AbstractNodeSet
add, addAll, clearContext, deepIntersection, directSelectAttribute, except, filterDocuments, getAncestors, getContextNodes, getParents, getProcessInReverseOrder, hasMixedContent, hasTextIndex, intersection, isCached, isPersistentSet, nodeMoved, parentWithChild, removeDuplicates, selectFollowing, selectFollowing, selectParentChild, selectPreceding, selectPreceding, setIsCached, setProcessInReverseOrder, toMemNodeSet, toNodeSet, union
 
Methods inherited from class org.exist.xquery.value.AbstractSequence
conversionPreference, convertTo, effectiveBooleanValue, getCardinality, getStringValue, hasMany, toJavaObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.exist.xquery.value.Sequence
conversionPreference, convertTo, effectiveBooleanValue, getCardinality, getStringValue, hasMany, toJavaObject
 

Constructor Detail

ExtArrayNodeSet

public ExtArrayNodeSet()
Creates a new ExtArrayNodeSet instance.


ExtArrayNodeSet

public ExtArrayNodeSet(int initialDocsCount,
                       int initialArraySize)
Creates a new ExtArrayNodeSet instance.

Parameters:
initialDocsCount - an int value
initialArraySize - an int value

ExtArrayNodeSet

public ExtArrayNodeSet(int initialArraySize)
Creates a new ExtArrayNodeSet instance.

Parameters:
initialArraySize - an int value
Method Detail

reset

public void reset()
The method reset


isEmpty

public boolean isEmpty()
The method isEmpty

Specified by:
isEmpty in interface Sequence
Specified by:
isEmpty in class AbstractSequence
Returns:
a boolean value

hasOne

public boolean hasOne()
The method hasOne

Specified by:
hasOne in interface Sequence
Specified by:
hasOne in class AbstractSequence
Returns:
a boolean value

add

public void add(NodeProxy proxy)
The method add

Specified by:
add in interface NodeSet
Specified by:
add in class AbstractNodeSet
Parameters:
proxy - a NodeProxy value

add

public void add(NodeProxy proxy,
                int sizeHint)
Add a new node to the set. If a new array of nodes has to be allocated for the document, use the sizeHint parameter to determine the size of the newly allocated array. This will overwrite the default array size. If the size hint is correct, no further reallocations will be required.

Specified by:
add in interface NodeSet
Overrides:
add in class AbstractNodeSet

getItemType

public int getItemType()
The method getItemType

Specified by:
getItemType in interface Sequence
Overrides:
getItemType in class AbstractNodeSet
Returns:
an int value

getSizeHint

public int getSizeHint(DocumentImpl doc)
The method getSizeHint

Specified by:
getSizeHint in interface NodeSet
Overrides:
getSizeHint in class AbstractNodeSet
Parameters:
doc - a DocumentImpl value
Returns:
an int value

iterator

public NodeSetIterator iterator()
Description copied from class: AbstractNodeSet
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
Specified by:
iterator in class AbstractNodeSet

iterate

public 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 AbstractNodeSet
Throws:
XPathException - TODO

unorderedIterator

public SequenceIterator unorderedIterator()
                                   throws XPathException
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 AbstractNodeSet
Throws:
XPathException

iterateByDocument

public ByDocumentIterator iterateByDocument()

contains

public boolean contains(NodeProxy proxy)
Description copied from class: AbstractNodeSet
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
Specified by:
contains in class AbstractNodeSet

addAll

public void addAll(NodeSet other)
Description copied from class: AbstractNodeSet
Add all nodes from the given node set.

Specified by:
addAll in interface NodeSet
Specified by:
addAll in class AbstractNodeSet

getLength

public int getLength()
Description copied from class: AbstractNodeSet
Return the number of nodes contained in this node set.

Specified by:
getLength in interface NodeList
Specified by:
getLength in class AbstractNodeSet

getItemCount

public int getItemCount()
Description copied from interface: Sequence
Returns the number of items contained in the sequence. Call this method only when necessary, since it can be resource consuming.

Specified by:
getItemCount in interface Sequence
Specified by:
getItemCount in class AbstractSequence
Returns:
The number of items in the sequence

item

public Node item(int pos)
Specified by:
item in interface NodeList
Specified by:
item in class AbstractNodeSet

get

public NodeProxy get(int pos)
Description copied from class: AbstractNodeSet
Get the node at position pos within this node set.

Specified by:
get in interface NodeSet
Specified by:
get in class AbstractNodeSet

get

public NodeProxy get(NodeProxy p)
Description copied from class: AbstractNodeSet
Get a node from this node set matching the document and node id of the given NodeProxy.

Specified by:
get in interface NodeSet
Specified by:
get in class AbstractNodeSet

get

public NodeProxy get(DocumentImpl doc,
                     NodeId nodeId)
Specified by:
get in interface NodeSet

itemAt

public Item itemAt(int pos)
Description copied from interface: Sequence
Returns the item located at the specified position within this sequence. Items are counted beginning at 0.

Specified by:
itemAt in interface Sequence
Specified by:
itemAt in class AbstractSequence

getDescendantsInSet

public NodeSet getDescendantsInSet(NodeSet al,
                                   boolean childOnly,
                                   boolean includeSelf,
                                   int mode,
                                   int contextId,
                                   boolean copyMatches)
The method getDescendantsInSet

Parameters:
al - a NodeSet value
childOnly - a boolean value
includeSelf - a boolean value
mode - an int value
contextId - an int value
Returns:
a NodeSet value

hasDescendantsInSet

public NodeProxy hasDescendantsInSet(DocumentImpl doc,
                                     NodeId ancestorId,
                                     boolean includeSelf,
                                     int contextId)
The method hasDescendantsInSet

Parameters:
doc - a DocumentImpl value
ancestorId - a NodeId value
includeSelf - a boolean value
contextId - an int value
Returns:
a NodeProxy value

selectParentChild

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

Specified by:
selectParentChild in interface NodeSet
Overrides:
selectParentChild in class AbstractNodeSet
Parameters:
al - a NodeSet value
mode - an int value
contextId - an int value
Returns:
a NodeSet value

filterDocuments

public NodeSet filterDocuments(ExtArrayNodeSet otherSet)
The method filterDocuments

Parameters:
otherSet - an ExtArrayNodeSet value
Returns:
a NodeSet value

setSorted

public void setSorted(DocumentImpl document,
                      boolean sorted)
The method setSorted

Parameters:
document - a DocumentImpl value
sorted - a boolean value

mergeDuplicates

public void mergeDuplicates()
Remove all duplicate nodes, but merge their contexts.


sort

public void sort()
The method sort


sort

public void sort(boolean mergeContexts)
The method sort

Parameters:
mergeContexts - a boolean value

sortInDocumentOrder

public final void sortInDocumentOrder()
The method sortInDocumentOrder


setSelfAsContext

public void setSelfAsContext(int contextId)
                      throws XPathException
Specified by:
setSelfAsContext in interface Sequence
Overrides:
setSelfAsContext in class AbstractSequence
Throws:
XPathException

selectAncestorDescendant

public NodeSet selectAncestorDescendant(NodeSet al,
                                        int mode,
                                        boolean includeSelf,
                                        int contextId,
                                        boolean copyMatches)
Description copied from class: AbstractNodeSet
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
Overrides:
selectAncestorDescendant in class AbstractNodeSet
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 selection.

selectPrecedingSiblings

public NodeSet selectPrecedingSiblings(NodeSet siblings,
                                       int contextId)
Description copied from class: AbstractNodeSet
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
Overrides:
selectPrecedingSiblings in class AbstractNodeSet
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)
The method selectFollowingSiblings

Specified by:
selectFollowingSiblings in interface NodeSet
Overrides:
selectFollowingSiblings in class AbstractNodeSet
Parameters:
siblings - a NodeSet value
contextId - an int value
Returns:
a NodeSet value

selectAncestors

public NodeSet selectAncestors(NodeSet al,
                               boolean includeSelf,
                               int contextId)
Description copied from class: AbstractNodeSet
For a given set of potential ancestor nodes, return all ancestors having descendants in this node set.

Specified by:
selectAncestors in interface NodeSet
Overrides:
selectAncestors in class AbstractNodeSet
Parameters:
al - 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 - 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)
The method parentWithChild

Specified by:
parentWithChild in interface NodeSet
Overrides:
parentWithChild in class AbstractNodeSet
Parameters:
doc - a DocumentImpl value
nodeId - a NodeId value
directParent - a boolean value
includeSelf - a boolean value
Returns:
a NodeProxy value

debugParts

public String debugParts()
The method debugParts

Returns:
a String value

getIndexType

public int getIndexType()
Description copied from class: AbstractNodeSet
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
Overrides:
getIndexType in class AbstractNodeSet
See Also:
GeneralComparison, ValueComparison

getDocumentSet

public DocumentSet getDocumentSet()
The method getDocumentSet

Specified by:
getDocumentSet in interface NodeSet
Specified by:
getDocumentSet in interface Sequence
Overrides:
getDocumentSet in class AbstractNodeSet
Returns:
a DocumentSet value

setDocumentSet

public void setDocumentSet(DocumentSet docs)
The method setDocumentSet

Parameters:
docs - a DocumentSet value

equalDocs

public boolean equalDocs(DocumentSet other)
Specified by:
equalDocs in interface DocumentSet

getCollectionIterator

public Iterator getCollectionIterator()
The method getCollectionIterator

Specified by:
getCollectionIterator in interface DocumentSet
Specified by:
getCollectionIterator in interface NodeSet
Specified by:
getCollectionIterator in interface Sequence
Overrides:
getCollectionIterator in class AbstractNodeSet
Returns:
an Iterator value

getDocumentIterator

public Iterator getDocumentIterator()
Specified by:
getDocumentIterator in interface DocumentSet

getDocumentCount

public int getDocumentCount()
Specified by:
getDocumentCount in interface DocumentSet

getDocumentAt

public DocumentImpl getDocumentAt(int pos)
Specified by:
getDocumentAt in interface DocumentSet

getDoc

public DocumentImpl getDoc(int docId)
Specified by:
getDoc in interface DocumentSet

getNames

public XmldbURI[] getNames()
Specified by:
getNames in interface DocumentSet

intersection

public DocumentSet intersection(DocumentSet other)
Specified by:
intersection in interface DocumentSet

contains

public boolean contains(DocumentSet other)
Specified by:
contains in interface DocumentSet

contains

public boolean contains(int docId)
Specified by:
contains in interface DocumentSet

docsToNodeSet

public NodeSet docsToNodeSet()
Specified by:
docsToNodeSet in interface DocumentSet

lock

public void lock(DBBroker broker,
                 boolean exclusive,
                 boolean checkExisting)
          throws LockException
Specified by:
lock in interface DocumentSet
Throws:
LockException

unlock

public void unlock(boolean exclusive)
Specified by:
unlock in interface DocumentSet

hasChanged

public boolean hasChanged(int previousState)
Specified by:
hasChanged in interface NodeSet
Specified by:
hasChanged in interface Sequence
Overrides:
hasChanged in class AbstractNodeSet

getState

public int getState()
Specified by:
getState in interface NodeSet
Specified by:
getState in interface Sequence
Overrides:
getState in class AbstractNodeSet

isCacheable

public boolean isCacheable()
Specified by:
isCacheable in interface Sequence
Overrides:
isCacheable in class AbstractSequence

toString

public String toString()
The method toString

Overrides:
toString in class AbstractNodeSet
Returns:
a String value


Copyright (C) Wolfgang Meier. All rights reserved.