Top Description Fields Constructors Methods
org.abego.treelayout.util

public Class DefaultTreeForTreeLayout<TreeNode>

extends AbstractTreeForTreeLayout<TreeNode>
Class Inheritance
Type Parameters
<TreeNode>
Type of elements used as nodes in the tree
Static Imports
org.abego.treelayout.internal.util.Contract.checkArg

Provides a generic implementation for the org.abego.treelayout.TreeForTreeLayout interface, applicable to any type of tree node.

It allows you to create a tree "from scratch", without creating any new class.

To create a tree you must provide the root of the tree (see DefaultTreeForTreeLayout(Object). Then you can incrementally construct the tree by adding children to the root or other nodes of the tree (see addChild(Object, Object) and addChildren(Object, Object...)).

Author
Udo Borkowski ([email protected])

Field Summary

Modifier and TypeField and Description
private Map<TreeNode, List<TreeNode>>
private List<TreeNode>
private Map<TreeNode, TreeNode>

Constructor Summary

AccessConstructor and Description
public
DefaultTreeForTreeLayout(TreeNode
the node to be used as the root.
root
)

Creates a new instance with a given node as the root

Method Summary

Modifier and TypeMethod and Description
public void
addChild(TreeNode
[hasNode(parentNode)]
parentNode
,
TreeNode
[!hasNode(node)]
node
)

public void
addChildren(TreeNode parentNode, TreeNode... nodes)

public List<TreeNode>
getChildrenList(TreeNode
 
node
)

Implements abstract org.abego.treelayout.util.AbstractTreeForTreeLayout.getChildrenList.

Return the children of a node as a List.
private List<TreeNode>
public TreeNode
getParent(TreeNode
 
node
)

Implements abstract org.abego.treelayout.util.AbstractTreeForTreeLayout.getParent.

Returns the parent of a node, if it has one.
public boolean

Returns:

true iff the node is in the tree
hasNode
(TreeNode
 
node
)

Inherited from org.abego.treelayout.util.AbstractTreeForTreeLayout:
getChildrengetChildrenReversegetFirstChildgetLastChildgetRootisChildOfParentisLeaf

Field Detail

childrenMapback to summary
private Map<TreeNode, List<TreeNode>> childrenMap
emptyListback to summary
private List<TreeNode> emptyList
parentsback to summary
private Map<TreeNode, TreeNode> parents

Constructor Detail

DefaultTreeForTreeLayoutback to summary
public DefaultTreeForTreeLayout(TreeNode root)

Creates a new instance with a given node as the root

Parameters
root:TreeNode

the node to be used as the root.

Method Detail

addChildback to summary
public void addChild(TreeNode parentNode, TreeNode node)
Parameters
parentNode:TreeNode

[hasNode(parentNode)]

node:TreeNode

[!hasNode(node)]

addChildrenback to summary
public void addChildren(TreeNode parentNode, TreeNode... nodes)
getChildrenListback to summary
public List<TreeNode> getChildrenList(TreeNode node)

Implements abstract org.abego.treelayout.util.AbstractTreeForTreeLayout.getChildrenList.

Doc from org.abego.treelayout.util.AbstractTreeForTreeLayout.getChildrenList.

Return the children of a node as a List.

Time Complexity: O(1)

Also the access to an item of the list must have time complexity O(1).

A client must not modify the returned list.

Parameters
node:TreeNode

 

Returns:List<TreeNode>

the children of the given node. When node is a leaf the list is empty.

Annotations
@Override
getEmptyListback to summary
private List<TreeNode> getEmptyList()
getParentback to summary
public TreeNode getParent(TreeNode node)

Implements abstract org.abego.treelayout.util.AbstractTreeForTreeLayout.getParent.

Doc from org.abego.treelayout.util.AbstractTreeForTreeLayout.getParent.

Returns the parent of a node, if it has one.

Time Complexity: O(1)

Parameters
node:TreeNode

 

Returns:TreeNode

[nullable] the parent of the node, or null when the node is a root.

Annotations
@Override
hasNodeback to summary
public boolean hasNode(TreeNode node)
Parameters
node:TreeNode

 

Returns:boolean

true iff the node is in the tree