com.cc.framework.util
Class TreeIterator

java.lang.Object
  extended bycom.cc.framework.util.TreeIterator

public class TreeIterator
extends java.lang.Object

Iterates over the tree. Preorder traversal is used, i.e., node is processed before its children.
Depth of traversal can be limited by setMaxDepth.
Branches can be traversed selectively using skipChildren().


Nested Class Summary
private static class TreeIterator.AbstractLevelIterator
          Base class for all LevelIterator's
static interface TreeIterator.LevelIterator
          Iterator for one level in a tree structure
private static class TreeIterator.RootIterator
          Specialized iterator for the root element of the tree
private static class TreeIterator.SimpleLevelIterator
          Iterator for simple Group Nodes
private static class TreeIterator.VirtualTreeLevelIterator
          Iterator for virtual group nodes.
 
Field Summary
private  TreeIterator.LevelIterator levelIter
           
private  boolean skipChildren
           
private  TreeStateModel state
          The State Model that holds the expansion states
 
Constructor Summary
TreeIterator(TreeNodeDataModel root)
          Creates iterator and sets the root of a tree and tree adapter.
TreeIterator(TreeNodeDataModel root, int maxDepth)
          Creates iterator and sets the root of a tree, tree adapter and depth of the traversal.
TreeIterator(TreeNodeDataModel root, TreeStateModel state)
          Creates iterator and sets the root of a tree and tree adapter.
 
Method Summary
static TreeIterator.LevelIterator createLevelIterator(TreeNodeDataModel root)
          Factory method to create a LevelIterator
 TreeNodeDataModel current()
          Returns the current node.
 int currentIndex()
          Returns index of the of the current node among siblings.
 java.lang.String currentKey()
          Returns key of the of the current node.
 boolean done()
           
 int getDepth()
          Returns the depth of the level being traversed.
 int getMaxDepth()
          Returns the maximum depth of the traversal.
 boolean hasChildren()
          Returns true if current node has children and iterator is allowed to traverse them.
 boolean hasNext()
          Returns true if not all elements of the tree have been traversed.
 boolean isExpanded()
          Returns true if current node is expanded.
 boolean isMaxDepth()
          Returns true if the maximum allowed level is reached.
 void next()
          Returns the next element of a tree.
 void setMaxDepth(int maxDepth)
          Sets the maximum depth of the traversal.
 void skipChildren()
          After this method is called, next() will skip children of the current node and move to the next sibling instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

levelIter

private TreeIterator.LevelIterator levelIter

skipChildren

private boolean skipChildren

state

private TreeStateModel state
The State Model that holds the expansion states

Constructor Detail

TreeIterator

public TreeIterator(TreeNodeDataModel root)
Creates iterator and sets the root of a tree and tree adapter.

Parameters:
root - root of the tree; note that next() moves to the first child, not to the root

TreeIterator

public TreeIterator(TreeNodeDataModel root,
                    TreeStateModel state)
Creates iterator and sets the root of a tree and tree adapter.

Parameters:
root - root of the tree; note that next() moves to the first child, not to the root
state - the tree state that holds the expansion information

TreeIterator

public TreeIterator(TreeNodeDataModel root,
                    int maxDepth)
Creates iterator and sets the root of a tree, tree adapter and depth of the traversal.

Parameters:
root - root of the tree
maxDepth - depth of the traversal;
Method Detail

createLevelIterator

public static TreeIterator.LevelIterator createLevelIterator(TreeNodeDataModel root)
Factory method to create a LevelIterator

Parameters:
root - the root element of the tree
Returns:
LevelIterator

current

public TreeNodeDataModel current()
Returns the current node. After iterator is created, root becomes current. Every next() call moves current to the next node.

Returns:
current node

setMaxDepth

public void setMaxDepth(int maxDepth)
Sets the maximum depth of the traversal.

Parameters:
maxDepth - depth of the traversal;
  • 0 = traverse only the root
  • 1 = traverse root and children
  • 2 = traverse root, children and grand children
  • ...and so forth

getMaxDepth

public int getMaxDepth()
Returns the maximum depth of the traversal.

Returns:
maximum allowed traversal depth set by setMaxDepth().

skipChildren

public void skipChildren()
After this method is called, next() will skip children of the current node and move to the next sibling instead.


isMaxDepth

public boolean isMaxDepth()
Returns true if the maximum allowed level is reached.

Returns:
true if this is the level set by setMaxDepth()

getDepth

public int getDepth()
Returns the depth of the level being traversed.

Returns:
depth of the current node;
  • root has depth = 0
  • children = 1
  • grand children = 2
  • ...and so on

currentIndex

public int currentIndex()
Returns index of the of the current node among siblings. Index starts with 0.

Returns:
index of the current node

currentKey

public java.lang.String currentKey()
Returns key of the of the current node.

Returns:
key of the current node

hasNext

public boolean hasNext()
Returns true if not all elements of the tree have been traversed.

Returns:
true if end of tree is not reached

hasChildren

public boolean hasChildren()
Returns true if current node has children and iterator is allowed to traverse them.

Returns:
true if current node has children

isExpanded

public boolean isExpanded()
Returns true if current node is expanded.

Returns:
true if current node is expanded

next

public void next()
Returns the next element of a tree. Preorder traversal is performed.


done

public boolean done()
Returns:
returns true when the iterator has reached the last element of the iteration. after done() has returned true it is not valid to call current()


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.