SwatObject
└─SwatTreeNode
public abstract class SwatTreeNode
extends SwatObject
| Field Summary | |
|---|---|
| protected array | An array of children tree nodes. |
| Method Summary | |
|---|---|
| void | addChild(SwatTreeNode child) Adds a child node to this node. |
| void | addTree(SwatTreeNode tree) Adds a full tree structure to this node. |
| integer | count() Gets the number of nodes in this tree or subtree. |
| mixed | current() Gets the current child node in this node. |
| this | Gets this node's children. |
| integer | getIndex() Gets this node's index. |
| SwatTreeNode | Gets the parent node of this node. |
| array | getPath() Gets the path to this node. |
| boolean | Whether or not this tree node has children. |
| void | key() Gets the key of the current child node in this node. |
| mixed | next() Gets the next child node in this node and moves the internal array pointer forward. |
| mixed | rewind() Sets the internal pointer in the child nodes array back to the beginning. |
| boolean | valid() Whether the current child node in this node is valid. |
protected array $children = array()
An array of children tree nodes
This array is indexed numerically and starts at 0.
public void addChild(SwatTreeNode child)
Adds a child node to this node
The parent of the child node is set to this node.
child - the child node to add to this node.public void addTree(SwatTreeNode tree)
Adds a full tree structure to this node
Identical to addChild() except that it removes the root node from the passed tree.
tree - the tree to add to this node.public integer count()
Gets the number of nodes in this tree or subtree
This method is needed to fulfill the Countable interface.
public mixed current()
Gets the current child node in this node
This method is needed to fulfill the RecursiveIterator interface.
public this getChildren()
Gets this node's children
This method is needed to fulfill the RecursiveIterator interface.
public integer getIndex()
Gets this node's index
public SwatTreeNode getParent()
Gets the parent node of this node
public array getPath()
Gets the path to this node
This method travels up the tree until it reaches a node with a parent of 'null', building a path of ids along the way.
public boolean hasChildren()
Whether or not this tree node has children
This method is needed to fulfill the RecursiveIterator interface.
public void key()
Gets the key of the current child node in this node
This method is needed to fulfill the RecursiveIterator interface.
public mixed next()
Gets the next child node in this node and moves the internal array pointer forward
This method is needed to fulfill the RecursiveIterator interface.
public mixed rewind()
Sets the internal pointer in the child nodes array back to the beginning
This method is needed to fulfill the RecursiveIterator interface.
public boolean valid()
Whether the current child node in this node is valid
This method is needed to fulfill the RecursiveIterator interface.
A simple class for building a tree structure
To create a tree data structure, sub-class this class.