silverorange Code


Swat.SwatTreeNode
/Swat/SwatTreeNode.php at line 16

Class SwatTreeNode

SwatObject
└─SwatTreeNode

public abstract class SwatTreeNode
extends SwatObject

A simple class for building a tree structure

To create a tree data structure, sub-class this class.

Copyright:
2005-2006 silverorange
License:
http://www.gnu.org/copyleft/lesser.html LGPL License 2.1

Field Summary
protected array

$children

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

getChildren()

Gets this node's children.

integer

getIndex()

Gets this node's index.

SwatTreeNode

getParent()

Gets the parent node of this node.

array

getPath()

Gets the path to this node.

boolean

hasChildren()

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.

Field Detail

/Swat/SwatTreeNode.php at line 28

children

protected array $children = array()

An array of children tree nodes

This array is indexed numerically and starts at 0.


Method Detail

/Swat/SwatTreeNode.php at line 60

addChild

public void addChild(SwatTreeNode child)

Adds a child node to this node

The parent of the child node is set to this node.

Parameters:
child - the child node to add to this node.

/Swat/SwatTreeNode.php at line 78

addTree

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.

Parameters:
tree - the tree to add to this node.

/Swat/SwatTreeNode.php at line 263

count

public integer count()

Gets the number of nodes in this tree or subtree

This method is needed to fulfill the Countable interface.

Returns:
the number of nodes in this tree or subtree.

/Swat/SwatTreeNode.php at line 181

current

public mixed current()

Gets the current child node in this node

This method is needed to fulfill the RecursiveIterator interface.

Returns:
the current child node in this node as a {@link SwatTreeNode} object. If the current child node is invalid, false is returned.

/Swat/SwatTreeNode.php at line 135

getChildren

public this getChildren()

Gets this node's children

This method is needed to fulfill the RecursiveIterator interface.

Returns:
node's children.

/Swat/SwatTreeNode.php at line 164

getIndex

public integer getIndex()

Gets this node's index

Returns:
this node's index.

/Swat/SwatTreeNode.php at line 120

getParent

public SwatTreeNode getParent()

Gets the parent node of this node

Returns:
the parent node of this node.

/Swat/SwatTreeNode.php at line 96

getPath

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.

Returns:
an array of indexes that is the path to the given node from the root of the current tree.

/Swat/SwatTreeNode.php at line 151

hasChildren

public boolean hasChildren()

Whether or not this tree node has children

This method is needed to fulfill the RecursiveIterator interface.

Returns:
true if this node has children or false if this node does not have children.

/Swat/SwatTreeNode.php at line 196

key

public void key()

Gets the key of the current child node in this node

This method is needed to fulfill the RecursiveIterator interface.

Reutrn:
integer the key (index) of the current child node in this node.

/Swat/SwatTreeNode.php at line 214

next

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.

Returns:
the next child node in this node as a {@link SwatTreeNode} object. If the next child node is invalid, false is returned.

/Swat/SwatTreeNode.php at line 232

rewind

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.

Returns:
the first child node in this node as a {@link SwatTreeNode} object. If there are no child nodes, false is returned.

/Swat/SwatTreeNode.php at line 248

valid

public boolean valid()

Whether the current child node in this node is valid

This method is needed to fulfill the RecursiveIterator interface.

Returns:
true if the current child node is valid and false if it is not.

silverorange Code