GODPAPER | All Packages | All Classes | Index | Frames No Frames |
TreeNode

Package | de.polygonal.ds
Class | public class TreeNode
Inheritance | TreeNode Object
Implements | Collection

A tree node for building a tree data structure. Every tree node has a linked list of child nodes and a pointer to its parent node. Note that a tree data structure is build of TreeNode objects, so there is no class that manages a tree structure.

Public Properties

| Property | Defined By
--- | --- | ---
|  | children : DLinkedList A list of child nodes being referenced. | TreeNode
|  | data : * The data being referened. | TreeNode
|  | depth : int [read-only] Computes the depth of the tree, starting from this node. | TreeNode
|  | numChildren : int [read-only] The total number of children. | TreeNode
|  | numSiblings : int [read-only] The total number of siblings. | TreeNode
|  | parent : TreeNode The parent node being referenced. | TreeNode
|  | size : int [read-only] Counts the total number of tree nodes starting from the current tree node. | TreeNode

Public Methods

| Method | Defined By
--- | --- | ---
|  | TreeNode(obj:* = null, parent:TreeNode = null) Creates a tree node. | TreeNode
|  | clear():void Clears all items. | TreeNode
|  | contains(obj:*):Boolean Determines if the collection contains a given item. | TreeNode
|  | dump():String Prints out all elements (for debug/demo purposes). | TreeNode
|  | getIterator():Iterator Initializes an iterator object pointing to the first item in the collection. | TreeNode
|  | getTreeIterator():TreeIterator Creates a tree iterator pointing at this tree node. | TreeNode
|  | hasChildren():Boolean Checks if the tree node has child nodes. | TreeNode
|  | hasSiblings():Boolean Checks if the tree node has siblings. | TreeNode
|  | isEmpty():Boolean Checks is the tree node is empty (has no children). | TreeNode
|  | isLeaf():Boolean Checks if the tree node is a leaf node. | TreeNode
|  | isRoot():Boolean Checks if the tree node is a root node. | TreeNode
|  | toArray():Array Converts the collection into an array. | TreeNode
|  | toString():String Prints out a string representing the current object. | TreeNode

Property Detail

children | property

`public var children:DLinkedList`

A list of child nodes being referenced.

data | property |

`public var data:*`

The data being referened.

depth | property |

`depth:int` [read-only]

Computes the depth of the tree, starting from this node.

Implementation
`public function get depth():int`

numChildren | property |

`numChildren:int` [read-only]

The total number of children.

Implementation
`public function get numChildren():int`

numSiblings | property |

`numSiblings:int` [read-only]

The total number of siblings.

Implementation
`public function get numSiblings():int`

parent | property |

`public var parent:TreeNode`

The parent node being referenced.

size | property |

`size:int` [read-only]

Counts the total number of tree nodes starting from the current tree node.

Implementation
`public function get size():int`
Constructor Detail

TreeNode | () | Constructor

`public function TreeNode(obj:* = null, parent:TreeNode = null)`

Creates a tree node.

Parameters

| `obj:*` (default = `null`)`` — The data to store inside the node.
| `parent:TreeNode` (default = `null`)`` — The node's parent.

Method Detail

clear | () | method

`public function clear():void`

Clears all items.

contains | () | method |

`public function contains(obj:*):Boolean`

Determines if the collection contains a given item.

Parameters

| `obj:*` — The item to search for.

Returns

| `Boolean` — True if the item exists, otherwise false.

dump | () | method |

`public function dump():String`

Prints out all elements (for debug/demo purposes).

Returns

| `String` — A human-readable representation of the structure.

getIterator | () | method |

`public function getIterator():Iterator`

Initializes an iterator object pointing to the first item in the collection.

Returns

| `Iterator` — An iterator object.

getTreeIterator | () | method |

`public function getTreeIterator():TreeIterator`

Creates a tree iterator pointing at this tree node.

Returns

| `TreeIterator`

hasChildren | () | method |

`public function hasChildren():Boolean`

Checks if the tree node has child nodes.

Returns

| `Boolean`

hasSiblings | () | method |

`public function hasSiblings():Boolean`

Checks if the tree node has siblings.

Returns

| `Boolean`

isEmpty | () | method |

`public function isEmpty():Boolean`

Checks is the tree node is empty (has no children).

Returns

| `Boolean`

isLeaf | () | method |

`public function isLeaf():Boolean`

Checks if the tree node is a leaf node.

Returns

| `Boolean`

isRoot | () | method |

`public function isRoot():Boolean`

Checks if the tree node is a root node.

Returns

| `Boolean`

toArray | () | method |

`public function toArray():Array`

Converts the collection into an array.

Returns

| `Array` — An array.

toString | () | method |

`public function toString():String`

Prints out a string representing the current object.

Returns

| `String` — A string representing the current object.

Thu Jan 16 2014, 01:11 PM +08:00