Package org.abego.treelayout.util
Class DefaultTreeForTreeLayout<TreeNode>
- java.lang.Object
-
- org.abego.treelayout.util.AbstractTreeForTreeLayout<TreeNode>
-
- org.abego.treelayout.util.DefaultTreeForTreeLayout<TreeNode>
-
- Type Parameters:
TreeNode- Type of elements used as nodes in the tree
- All Implemented Interfaces:
TreeForTreeLayout<TreeNode>
public class DefaultTreeForTreeLayout<TreeNode> extends AbstractTreeForTreeLayout<TreeNode>
Provides a generic implementation for theTreeForTreeLayoutinterface, 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 (seeaddChild(Object, Object)andaddChildren(Object, Object...)).
-
-
Constructor Summary
Constructors Constructor Description DefaultTreeForTreeLayout(TreeNode root)Creates a new instance with a given node as the root
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(TreeNode parentNode, TreeNode node)voidaddChildren(TreeNode parentNode, TreeNode... nodes)java.util.List<TreeNode>getChildrenList(TreeNode node)Return the children of a node as aList.private java.util.List<TreeNode>getEmptyList()TreeNodegetParent(TreeNode node)Returns the parent of a node, if it has one.booleanhasNode(TreeNode node)-
Methods inherited from class org.abego.treelayout.util.AbstractTreeForTreeLayout
getChildren, getChildrenReverse, getFirstChild, getLastChild, getRoot, isChildOfParent, isLeaf
-
-
-
-
Constructor Detail
-
DefaultTreeForTreeLayout
public DefaultTreeForTreeLayout(TreeNode root)
Creates a new instance with a given node as the root- Parameters:
root- the node to be used as the root.
-
-
Method Detail
-
getEmptyList
private java.util.List<TreeNode> getEmptyList()
-
getParent
public TreeNode getParent(TreeNode node)
Description copied from class:AbstractTreeForTreeLayoutReturns the parent of a node, if it has one.Time Complexity: O(1)
- Specified by:
getParentin classAbstractTreeForTreeLayout<TreeNode>- Parameters:
node-- Returns:
- [nullable] the parent of the node, or null when the node is a root.
-
getChildrenList
public java.util.List<TreeNode> getChildrenList(TreeNode node)
Description copied from class:AbstractTreeForTreeLayoutReturn the children of a node as aList.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.
- Specified by:
getChildrenListin classAbstractTreeForTreeLayout<TreeNode>- Parameters:
node-- Returns:
- the children of the given node. When node is a leaf the list is empty.
-
hasNode
public boolean hasNode(TreeNode node)
- Parameters:
node-- Returns:
- true iff the node is in the tree
-
addChild
public void addChild(TreeNode parentNode, TreeNode node)
- Parameters:
parentNode- [hasNode(parentNode)]node- [!hasNode(node)]
-
-