Package org.abego.treelayout.util
Class AbstractTreeForTreeLayout<TreeNode>
- java.lang.Object
-
- org.abego.treelayout.util.AbstractTreeForTreeLayout<TreeNode>
-
- Type Parameters:
TreeNode- Type of elements used as nodes in the tree
- All Implemented Interfaces:
TreeForTreeLayout<TreeNode>
- Direct Known Subclasses:
DefaultTreeForTreeLayout
public abstract class AbstractTreeForTreeLayout<TreeNode> extends Object implements TreeForTreeLayout<TreeNode>
Provides an easy way to implement theTreeForTreeLayoutinterface by defining just two simple methods and a constructor.To use this class the underlying tree must provide the children as a list (see
getChildrenList(Object)and give direct access to the parent of a node (seegetParent(Object)).See also
DefaultTreeForTreeLayout.- Author:
- Udo Borkowski (ub@abego.org)
-
-
Constructor Summary
Constructors Constructor Description AbstractTreeForTreeLayout(TreeNode root)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Iterable<TreeNode>getChildren(TreeNode node)Returns the children of a parent node.abstract List<TreeNode>getChildrenList(TreeNode node)Return the children of a node as aList.Iterable<TreeNode>getChildrenReverse(TreeNode node)Returns the children of a parent node, in reverse order.TreeNodegetFirstChild(TreeNode parentNode)Returns the first child of a parent node.TreeNodegetLastChild(TreeNode parentNode)Returns the last child of a parent node.abstract TreeNodegetParent(TreeNode node)Returns the parent of a node, if it has one.TreeNodegetRoot()Returns the the root of the tree.booleanisChildOfParent(TreeNode node, TreeNode parentNode)Tells if a node is a child of a given parentNode.booleanisLeaf(TreeNode node)Tells if a node is a leaf in the tree.
-
-
-
Constructor Detail
-
AbstractTreeForTreeLayout
public AbstractTreeForTreeLayout(TreeNode root)
-
-
Method Detail
-
getParent
public abstract TreeNode getParent(TreeNode node)
Returns the parent of a node, if it has one.Time Complexity: O(1)
- Parameters:
node-- Returns:
- [nullable] the parent of the node, or null when the node is a root.
-
getChildrenList
public abstract List<TreeNode> getChildrenList(TreeNode node)
Return 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.
- Parameters:
node-- Returns:
- the children of the given node. When node is a leaf the list is empty.
-
getRoot
public TreeNode getRoot()
Description copied from interface:TreeForTreeLayoutReturns the the root of the tree.Time Complexity: O(1)
- Specified by:
getRootin interfaceTreeForTreeLayout<TreeNode>- Returns:
- the root of the tree
-
isLeaf
public boolean isLeaf(TreeNode node)
Description copied from interface:TreeForTreeLayoutTells if a node is a leaf in the tree.Time Complexity: O(1)
- Specified by:
isLeafin interfaceTreeForTreeLayout<TreeNode>- Parameters:
node-- Returns:
- true iff node is a leaf in the tree, i.e. has no children.
-
isChildOfParent
public boolean isChildOfParent(TreeNode node, TreeNode parentNode)
Description copied from interface:TreeForTreeLayoutTells if a node is a child of a given parentNode.Time Complexity: O(1)
- Specified by:
isChildOfParentin interfaceTreeForTreeLayout<TreeNode>- Parameters:
node-parentNode-- Returns:
- true iff the node is a child of the given parentNode
-
getChildren
public Iterable<TreeNode> getChildren(TreeNode node)
Description copied from interface:TreeForTreeLayoutReturns the children of a parent node.Time Complexity: O(1)
- Specified by:
getChildrenin interfaceTreeForTreeLayout<TreeNode>- Parameters:
node- [!isLeaf(parentNode)]- Returns:
- the children of the given parentNode, from first to last
-
getChildrenReverse
public Iterable<TreeNode> getChildrenReverse(TreeNode node)
Description copied from interface:TreeForTreeLayoutReturns the children of a parent node, in reverse order.Time Complexity: O(1)
- Specified by:
getChildrenReversein interfaceTreeForTreeLayout<TreeNode>- Parameters:
node- [!isLeaf(parentNode)]- Returns:
- the children of given parentNode, from last to first
-
getFirstChild
public TreeNode getFirstChild(TreeNode parentNode)
Description copied from interface:TreeForTreeLayoutReturns the first child of a parent node.Time Complexity: O(1)
- Specified by:
getFirstChildin interfaceTreeForTreeLayout<TreeNode>- Parameters:
parentNode- [!isLeaf(parentNode)]- Returns:
- the first child of the parentNode
-
getLastChild
public TreeNode getLastChild(TreeNode parentNode)
Description copied from interface:TreeForTreeLayoutReturns the last child of a parent node.Time Complexity: O(1)
- Specified by:
getLastChildin interfaceTreeForTreeLayout<TreeNode>- Parameters:
parentNode- [!isLeaf(parentNode)]- Returns:
- the last child of the parentNode
-
-