qflib 0.98.1

de.qfs.lib.tree
Class AbstractTraversal

java.lang.Object
  |
  +--de.qfs.lib.tree.AbstractTraversal
All Implemented Interfaces:
Traversal
Direct Known Subclasses:
IndexTraversal

public abstract class AbstractTraversal
extends java.lang.Object
implements Traversal

Abstract base class for implementations of the Traversal interface.

Since:
0.98.1
Version:
$Revision: 1.2 $
Author:
Gregor Schmid

Inner Class Summary
protected static class AbstractTraversal.Level
          Structure that holds information about one level of the tree.
 
Constructor Summary
protected AbstractTraversal(TreeAdapter adapter, java.lang.Object root)
          Create a new AbstractTraversal.
 
Method Summary
 TreeAdapter getAdapter()
          Get the adapter for the tree being traversed.
 int getIndex()
          Get the index of the current node in its parent.
 java.lang.Object getNode()
          Get the current node of the traversal.
 java.lang.Object getParent()
          Get the parent node of the current node.
 java.lang.Object[] getPath()
          Get the path of the current node, up to the root of the traversal.
 java.lang.Object getPreviousSibling()
          Get the previous sibling of the current node.
 java.lang.Object getUserObject()
          Get a user object assoiated with the traversal, set with setUserObject.
 void setUserObject(java.lang.Object object)
          Set a user object for the traversal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.qfs.lib.tree.Traversal
finish
 

Constructor Detail

AbstractTraversal

protected AbstractTraversal(TreeAdapter adapter,
                            java.lang.Object root)
Create a new AbstractTraversal.
Method Detail

getAdapter

public TreeAdapter getAdapter()
Get the adapter for the tree being traversed.
Specified by:
getAdapter in interface Traversal
Returns:
The adapter for the tree being traversed.

getNode

public java.lang.Object getNode()
Get the current node of the traversal.
Specified by:
getNode in interface Traversal
Returns:
The current node.

getIndex

public int getIndex()
Get the index of the current node in its parent. For trees that are not index-based , this is more efficient than TreeAdapter.getIndexOfChildNode.
Specified by:
getIndex in interface Traversal
Returns:
The index of the current node in its parent node.

getParent

public java.lang.Object getParent()
Get the parent node of the current node. The parent of the root of the traversal will always be null, even if it is not the true root of the tree.
Specified by:
getParent in interface Traversal
Returns:
The parent node of the current node.

getPath

public java.lang.Object[] getPath()
Get the path of the current node, up to the root of the traversal. If the traversal doesn't start at the root of the tree, this path is different from the path obtained with TreeUtil.getPath.
Specified by:
getPath in interface Traversal
Returns:
The path of the current node, up to the root of the traversal. The first object in the array is the root, the last is the current node.

getPreviousSibling

public java.lang.Object getPreviousSibling()
Get the previous sibling of the current node. If the tree is not link based, this method is faster than TreeAdapter.getPreviousSibling.
Specified by:
getPreviousSibling in interface Traversal
Returns:
The previous sibling of the current node or null if it is the first child of its parent or the root of the traversal.

getUserObject

public java.lang.Object getUserObject()
Get a user object assoiated with the traversal, set with setUserObject.
Specified by:
getUserObject in interface Traversal
Returns:
The user object assoiated with the traversal.

setUserObject

public void setUserObject(java.lang.Object object)
Set a user object for the traversal. Simplifies keeping some state during the traversal with multiple threads.
Specified by:
setUserObject in interface Traversal
Parameters:
object - The object to associate with the traversal.

qflib 0.98.1