org.basex.query.iter
Class NodeSeqBuilder

java.lang.Object
  extended by org.basex.query.iter.Iter
      extended by org.basex.query.iter.NodeIter
          extended by org.basex.query.iter.AxisIter
              extended by org.basex.query.iter.NodeSeqBuilder
All Implemented Interfaces:
java.lang.Iterable<ANode>

public final class NodeSeqBuilder
extends AxisIter

This class can be used to build new node sequences. At the same time, it serves as an iterator.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
 ANode[] nodes
          Node container.
 
Constructor Summary
NodeSeqBuilder()
          Constructor.
NodeSeqBuilder(ANode[] it, int s)
          Lightweight constructor, assigning the specified array of sorted nodes.
 
Method Summary
 void add(ANode n)
          Adds a node.
 int binarySearch(DBNode n, int start, int length)
          Performs a binary search on the given range of this sequence iterator, assuming that all nodes are DBNodes from the same Data instance (i.e., dbnodes() returns true).
 NodeSeqBuilder check()
          Checks all nodes for potential duplicates and their orderedness.
 NodeSeqBuilder copy()
          Creates a copy of this sequence builder.
 boolean dbnodes()
          Checks if binary search can be applied to this iterator, i.e.
 void delete(int p)
          Deletes a value at the specified position.
 ANode get(int i)
          Returns the specified node.
 ANode get(long i)
          Returns the specified item, or an arbitrary item if the index is invalid.
 int indexOf(ANode n, boolean db)
          Checks if the iterator contains a database node with the specified pre value.
 ANode next()
          Returns the next item or null if no other items are found.
 boolean reset()
          Resets the iterator and returns true if operation was successful.
 long size()
          Returns the iterator size.
 void size(int s)
          Sets a new item size.
 NodeSeqBuilder sort()
          Sorts the nodes, if necessary.
 java.lang.String toString()
           
 Value value()
          Returns a sequence with all iterator values.
 
Methods inherited from class org.basex.query.iter.AxisIter
iterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nodes

public ANode[] nodes
Node container.

Constructor Detail

NodeSeqBuilder

public NodeSeqBuilder()
Constructor.


NodeSeqBuilder

public NodeSeqBuilder(ANode[] it,
                      int s)
Lightweight constructor, assigning the specified array of sorted nodes.

Parameters:
it - node array
s - size
Method Detail

check

public NodeSeqBuilder check()
Checks all nodes for potential duplicates and their orderedness.

Returns:
self reference

get

public ANode get(int i)
Returns the specified node.

Parameters:
i - node offset
Returns:
node

delete

public void delete(int p)
Deletes a value at the specified position.

Parameters:
p - deletion position

add

public void add(ANode n)
Adds a node.

Parameters:
n - node to be added

reset

public boolean reset()
Description copied from class: Iter
Resets the iterator and returns true if operation was successful. false is returned if the iterator cannot be reset.

Overrides:
reset in class Iter
Returns:
true if operator could be reset

next

public ANode next()
Description copied from class: Iter
Returns the next item or null if no other items are found.

Specified by:
next in class AxisIter
Returns:
resulting item or null

get

public ANode get(long i)
Description copied from class: Iter
Returns the specified item, or an arbitrary item if the index is invalid. This method needs to be implemented - and should only be called - if Iter.size() returns the correct number of results. A calling method should call Iter.reset() after the last items has been retrieved.

Overrides:
get in class Iter
Parameters:
i - value offset
Returns:
specified item

size

public long size()
Description copied from class: Iter
Returns the iterator size. Note: -1 is returned if the result size is unknown. If this method is implemented by an iterator, Iter.get(long) needs to be implemented as well.

Overrides:
size in class Iter
Returns:
number of entries

size

public void size(int s)
Sets a new item size.

Parameters:
s - size

value

public Value value()
Description copied from class: Iter
Returns a sequence with all iterator values. Must only be called if Iter.next() has not been called before.

Overrides:
value in class Iter
Returns:
sequence

dbnodes

public boolean dbnodes()
Checks if binary search can be applied to this iterator, i.e. if all nodes are DBNode references and refer to the same database.

Returns:
result of check

indexOf

public int indexOf(ANode n,
                   boolean db)
Checks if the iterator contains a database node with the specified pre value.

Parameters:
n - node to be found
db - indicates if all nodes are sorted DBNode references
Returns:
position, or -1

binarySearch

public int binarySearch(DBNode n,
                        int start,
                        int length)
Performs a binary search on the given range of this sequence iterator, assuming that all nodes are DBNodes from the same Data instance (i.e., dbnodes() returns true).

Parameters:
n - node to find
start - start of the search interval
length - length of the search interval
Returns:
position of the item or -insertPosition - 1 if not found

sort

public NodeSeqBuilder sort()
Sorts the nodes, if necessary.

Returns:
self reference

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

copy

public NodeSeqBuilder copy()
Creates a copy of this sequence builder.

Returns:
copy