org.exist.xquery.value
Class OrderedValueSequence

java.lang.Object
  extended by org.exist.xquery.value.AbstractSequence
      extended by org.exist.xquery.value.OrderedValueSequence
All Implemented Interfaces:
Sequence

public class OrderedValueSequence
extends AbstractSequence

A sequence that sorts its entries in the order specified by the order specs of an "order by" clause. Used by ForExpr. Contrary to class PreorderedValueSequence, all order expressions are evaluated once for each item in the sequence while items are added.

Author:
wolf

Field Summary
 
Fields inherited from interface org.exist.xquery.value.Sequence
EMPTY_SEQUENCE
 
Constructor Summary
OrderedValueSequence(OrderSpec[] orderSpecs, int size)
           
 
Method Summary
 void add(Item item)
          Add an item to the current sequence.
 void addAll(Sequence other)
          Add all items of the other sequence to this item.
 int getItemCount()
          Returns the number of items contained in the sequence.
 int getItemType()
          Return the primary type to which all items in this sequence belong.
 int getState()
           
 boolean hasChanged(int previousState)
           
 boolean hasOne()
          Returns whether the sequence has just one item or not.
 boolean isCacheable()
           
 boolean isEmpty()
          Returns whether the sequence is empty or not.
 boolean isPersistentSet()
           
 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.
 void removeDuplicates()
          Explicitely remove all duplicate nodes from this sequence.
 void sort()
           
 MemoryNodeSet toMemNodeSet()
          Convert the sequence into an in-memory node set.
 NodeSet toNodeSet()
          Convert the sequence into a NodeSet.
 SequenceIterator unorderedIterator()
          Returns an iterator over all items in the sequence.
 
Methods inherited from class org.exist.xquery.value.AbstractSequence
clearContext, conversionPreference, convertTo, effectiveBooleanValue, getCardinality, getCollectionIterator, getDocumentSet, getStringValue, hasMany, isCached, nodeMoved, setIsCached, setSelfAsContext, toJavaObject, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderedValueSequence

public OrderedValueSequence(OrderSpec[] orderSpecs,
                            int size)
Method Detail

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 AbstractSequence
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 AbstractSequence
Throws:
XPathException

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

isEmpty

public boolean isEmpty()
Description copied from interface: Sequence
Returns whether the sequence is empty or not.

Specified by:
isEmpty in interface Sequence
Specified by:
isEmpty in class AbstractSequence
Returns:
true is the sequence is empty

hasOne

public boolean hasOne()
Description copied from interface: Sequence
Returns whether the sequence has just one item or not.

Specified by:
hasOne in interface Sequence
Specified by:
hasOne in class AbstractSequence
Returns:
true is the sequence has just one item

add

public void add(Item item)
         throws XPathException
Description copied from interface: Sequence
Add an item to the current sequence. An XPathException may be thrown if the item's type is incompatible with this type of sequence (e.g. if the sequence is a node set). The sequence may or may not allow duplicate values.

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

addAll

public void addAll(Sequence other)
            throws XPathException
Description copied from interface: Sequence
Add all items of the other sequence to this item. An XPathException may be thrown if the type of the items in the other sequence is incompatible with the primary type of this sequence.

Specified by:
addAll in interface Sequence
Overrides:
addAll in class AbstractSequence
Throws:
XPathException

sort

public void sort()

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

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
Returns:
the primary type of the items in this sequence.

toNodeSet

public NodeSet toNodeSet()
                  throws XPathException
Description copied from interface: Sequence
Convert the sequence into a NodeSet. If the sequence contains items which are not nodes, an XPathException is thrown.

Throws:
XPathException - if the sequence contains items which are not nodes.

isPersistentSet

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

toMemNodeSet

public MemoryNodeSet toMemNodeSet()
                           throws XPathException
Description copied from interface: Sequence
Convert the sequence into an in-memory node set. If the sequence contains items which are not nodes, an XPathException is thrown. For persistent node sets, this method will return null. Call Sequence.isPersistentSet() to check if the sequence is a persistent node set.

Throws:
XPathException - if the sequence contains items which are not nodes or is a persistent node set

removeDuplicates

public void removeDuplicates()
Description copied from interface: Sequence
Explicitely remove all duplicate nodes from this sequence.


getState

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

hasChanged

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

isCacheable

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


Copyright (C) Wolfgang Meier. All rights reserved.