Package org.eclipse.zest.layouts.algorithms

# Class TreeLayoutObserver.TreeNode

java.lang.Object
org.eclipse.zest.layouts.algorithms.TreeLayoutObserver.TreeNode

Enclosing class:
  `TreeLayoutObserver`

public static class TreeLayoutObserver.TreeNode extends Object
Represents a node in a tree structure and stores all information related to it. May be subclassed if additional data and behavior is necessary.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final List<TreeLayoutObserver.TreeNode>`
`children`
`protected int`
`depth`
`protected boolean`
`firstChild`
`protected int`
`height`
`protected boolean`
`lastChild`
`protected final NodeLayout`
`node`
`protected int`
`numOfDescendants`
`protected int`
`numOfLeaves`
`protected int`
`order`
`protected final TreeLayoutObserver`
`owner`
`protected TreeLayoutObserver.TreeNode`
`parent`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`TreeNode(NodeLayout node, TreeLayoutObserver owner)`
Creates a tree node related to given layout node

## Method Summary

Modifier and Type
Method
Description
`protected void`
`addChild(TreeLayoutObserver.TreeNode child)`
Adds given node to the list of this node's children and set its parent to this node.
`protected void`
`findNewParent()`
Finds a node that is the best parent for this node.
`List<? extends TreeLayoutObserver.TreeNode>`
`getChildren()`
`int`
`getDepth()`
`int`
`getHeight()`
`NodeLayout`
`getNode()`
`int`
`getNumOfDescendants()`
`int`
`getNumOfLeaves()`
`int`
`getOrder()`
Returns order in which nodes are visited during Deep First Search.
`TreeLayoutObserver`
`getOwner()`
`TreeLayoutObserver.TreeNode`
`getParent()`
`boolean`
`isAncestorOf(TreeLayoutObserver.TreeNode descendant)`
`protected boolean`
`isBetterParent(TreeLayoutObserver.TreeNode potentialParent)`
Checks if a potential parent would be better for this node than its current parent.
`boolean`
`isFirstChild()`
`boolean`
`isLastChild()`
`protected void`
`precomputeTree()`
Performs a DFS on the tree structure and calculates all parameters of its nodes.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### node

protected final NodeLayout node

### owner

protected final TreeLayoutObserver owner

### height

protected int height

### depth

protected int depth

### numOfLeaves

protected int numOfLeaves

### numOfDescendants

protected int numOfDescendants

### order

protected int order

### children

protected final List<TreeLayoutObserver.TreeNode> children

### parent

protected TreeLayoutObserver.TreeNode parent

### firstChild

protected boolean firstChild

### lastChild

protected boolean lastChild

## Constructor Details

### TreeNode

protected TreeNode(NodeLayout node, TreeLayoutObserver owner)
Creates a tree node related to given layout node

Parameters:
  `node` - the layout node
  `owner` - `TreeLayoutObserver` owning created node

## Method Details

### getNode

public NodeLayout getNode()

Returns:
  node layout related to this tree node (null for `Super Root`)

### getOwner

public TreeLayoutObserver getOwner()

Returns:
  `TreeLayoutObserver` owning this tree node

### getHeight

public int getHeight()

Returns:
  height of this node in the tree (the longest distance to a leaf, 0 for a leaf itself)

### getDepth

public int getDepth()

Returns:
  depth of this node in the tree (distance from root, 0 for a root and -1 for `Super Root`

### getNumOfLeaves

public int getNumOfLeaves()

Returns:
  number of all leaves descending from this node (1 for a leaf itself)

### getNumOfDescendants

public int getNumOfDescendants()

Returns:
  total number of descendants of this node (0 for leafs)

### getOrder

public int getOrder()
Returns order in which nodes are visited during Deep First Search. Children are visited in the same order as they were added to their layout context, unless `TreeLayoutObserver.recomputeTree()` was called after the nodes were added. In that case the order is determined by order of nodes returned by `NodeLayout.getSuccessingNodes()`. Leaves are assigned successive numbers starting from 0, other nodes have order equal to the smallest order of their children.

Returns:
  order of this node

### getChildren

public List<? extends TreeLayoutObserver.TreeNode> getChildren()

Returns:
  an unmodifiable list of this node's children

### getParent

public TreeLayoutObserver.TreeNode getParent()

Returns:
  this node's parent

### isFirstChild

public boolean isFirstChild()

Returns:
  true if this node is the first child of its parent (has the smallest order)

### isLastChild

public boolean isLastChild()

Returns:
  true if this node is the last child of its parent (has the highest order)

### addChild

protected void addChild(TreeLayoutObserver.TreeNode child)
Adds given node to the list of this node's children and set its parent to this node.

Parameters:
  `child` - node to add

### precomputeTree

protected void precomputeTree()
Performs a DFS on the tree structure and calculates all parameters of its nodes. Should be called on `Super Root`. Uses recurrence to go through all the nodes.

### findNewParent

protected void findNewParent()
Finds a node that is the best parent for this node. Add this node as a child of the found node.

### isBetterParent

protected boolean isBetterParent(TreeLayoutObserver.TreeNode potentialParent)
Checks if a potential parent would be better for this node than its current parent. A better parent has smaller depth (with exception to `Super Root`, which has depth equal to -1 but is never a better parent than any other node).

Parameters:
  `potentialParent` - potential parent to check
Returns:
  true if potentialParent can be a parent of this node and is better than its current parent

### isAncestorOf

public boolean isAncestorOf(TreeLayoutObserver.TreeNode descendant)

Parameters:
  `descendant` -
Returns:
  true if this node is an ancestor if given descendant node