org.mmbase.bridge.util
Class TreeList.TreeItr

Package class diagram package TreeList.TreeItr
java.lang.Object
  extended by org.mmbase.bridge.util.TreeList.TreeItr
All Implemented Interfaces:
Iterator<Node>, ListIterator<Node>, NodeIterator, TreeIterator
Enclosing class:
TreeList

protected class TreeList.TreeItr
extends Object
implements TreeIterator

The TreeIterator contains the core-functionality of TreeList.


Constructor Summary
TreeList.TreeItr(int i)
           
 
Method Summary
 void add(Node o)
           
 int currentDepth()
          Depth of the last node fetched with next() or nextNode()
protected  Node getNextLeafNode()
          Simply returns the 'smallest' of all available nodes (compared to the 'previous node') This is actually an alternavite implementation for getNextNode, but it also works when 'leaf' constraints are applied.
protected  Node getNextNode()
          Implementation idea graphicly.
 Node getParent()
          Returns the 'parent' node of the most recently returned Node.
protected  Node getRealNode(int index)
          Returns the 'real' node, thus the just used 'next' node of index.
 NodeList getSiblings()
          Returns all nodes with the same parent as the most recently return Node (include that node itself).
 boolean hasNext()
           
 boolean hasPrevious()
           
 Node next()
           
 int nextIndex()
           
 Node nextNode()
          Returns the next element in the iterator as a Node
protected  boolean prepare(int index)
          Makes sure that query with given index has an iterator, a 'next' node and a 'previous' node.
 Node previous()
           
 int previousIndex()
           
 Node previousNode()
          Returns the previous element in the iterator as a Node
 void remove()
           
 void set(Node o)
           
protected  void useNext(int index)
          Uses the new 'next' node of the iterator with the given index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeList.TreeItr

TreeList.TreeItr(int i)
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<Node>
Specified by:
hasNext in interface ListIterator<Node>

prepare

protected final boolean prepare(int index)
Makes sure that query with given index has an iterator, a 'next' node and a 'previous' node.

Returns:
true it such query existed, false, otherwise

useNext

protected final void useNext(int index)
Uses the new 'next' node of the iterator with the given index. This means that it becomes the previous node and that a new 'next' node will be determined


getRealNode

protected final Node getRealNode(int index)
Returns the 'real' node, thus the just used 'next' node of index.


nextNode

public Node nextNode()
Description copied from interface: NodeIterator
Returns the next element in the iterator as a Node

Specified by:
nextNode in interface NodeIterator
Returns:
next Node

getParent

public Node getParent()
Description copied from interface: TreeIterator
Returns the 'parent' node of the most recently returned Node. Or null if there is no such node.

Specified by:
getParent in interface TreeIterator

getSiblings

public NodeList getSiblings()
Description copied from interface: TreeIterator
Returns all nodes with the same parent as the most recently return Node (include that node itself).

Specified by:
getSiblings in interface TreeIterator

currentDepth

public int currentDepth()
Depth of the last node fetched with next() or nextNode()

Specified by:
currentDepth in interface TreeIterator
Returns:
Depth of the last node fetched

next

public final Node next()
Specified by:
next in interface Iterator<Node>
Specified by:
next in interface ListIterator<Node>

getNextNode

protected final Node getNextNode()
Implementation idea graphicly.
                        iterators


              current-2  current-1  current       current+1                         [///]: used node
               [///]       [///]     [///]         [///]                            [|||]: last used node (lastNode)
                                                                                    [   ]: unused node
         ...   [///]       [///]     [|||] _       [///]    previousNodes           [ * ]: considered next node (nextListNextNode)
                                            \
               [   ]       [   ]     [   ]   `---> [ * ]    nextNodes

               if (! [|||] contained by [ * ]) current--
         
Every time next is called, the last used node is compared with the next node of the next iterator (the arrow in the above scheme). If the last used node is 'contained' by this next node, then this next node of the next iterator will be 'next()' otherwise current is decreased by one and next is called recursively. This means that the next node is always one longer than the current one, equally long, or shorter. If 'leaf constraints' are in use, then the implementation jumps to getNextLeafNode, which simply returns the 'smallest node' of all iterators.


getNextLeafNode

protected final Node getNextLeafNode()
Simply returns the 'smallest' of all available nodes (compared to the 'previous node') This is actually an alternavite implementation for getNextNode, but it also works when 'leaf' constraints are applied.

Since:
MMBase-1.8

hasPrevious

public boolean hasPrevious()
Specified by:
hasPrevious in interface ListIterator<Node>

previousNode

public Node previousNode()
Description copied from interface: NodeIterator
Returns the previous element in the iterator as a Node

Specified by:
previousNode in interface NodeIterator
Returns:
previous Node

previous

public Node previous()
Specified by:
previous in interface ListIterator<Node>

nextIndex

public int nextIndex()
Specified by:
nextIndex in interface ListIterator<Node>

previousIndex

public int previousIndex()
Specified by:
previousIndex in interface ListIterator<Node>

remove

public void remove()
Specified by:
remove in interface Iterator<Node>
Specified by:
remove in interface ListIterator<Node>

set

public void set(Node o)
Specified by:
set in interface ListIterator<Node>

add

public void add(Node o)
Specified by:
add in interface ListIterator<Node>


MMBase2 Bridge 2.0-SNAPSHOT - 2013-05-29T22:05