|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.foray.common.AbstractOrderedTreeNode
public abstract class AbstractOrderedTreeNode
An implementation of the TreeNode
interface that provides methods for
various traversal needs.
Consideration was given to using DefaultMutableTreeNode
instead of
creating this class.
However, the data portion of that class was not deemed suitable.
Nested Class Summary | |
---|---|
class |
AbstractOrderedTreeNode.PostOrderDescendantIterator
A post-order iterator over the descendants of a given node. |
Constructor Summary | |
---|---|
AbstractOrderedTreeNode()
|
Method Summary | |
---|---|
Enumeration<? extends OrderedTreeNode> |
children()
|
abstract boolean |
getAllowsChildren()
|
int |
getChildCount()
|
abstract List<? extends OrderedTreeNode> |
getChildren()
Return the List of this node's children. |
OrderedTreeNode |
getFirstChild()
Returns the first child of this node. |
OrderedTreeNode |
getFirstLeaf()
Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf. |
int |
getIndex(TreeNode node)
|
OrderedTreeNode |
getLastChild()
Returns the last child of this node. |
OrderedTreeNode |
getLastLeaf()
Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf. |
int |
getLevel()
Returns the number of levels above this node -- the distance from the root to this node. |
OrderedTreeNode |
getNextLeaf()
Returns the leaf after this node or null if this node is the last leaf in the tree. |
OrderedTreeNode |
getNextSibling()
Returns the next sibling node. |
OrderedTreeNode |
getPreviousLeaf()
Returns the leaf before this node or null if this node is the first leaf in the tree. |
OrderedTreeNode |
getPreviousSibling()
Returns the previous sibling node. |
OrderedTreeNode |
getSharedAncestor(OrderedTreeNode aNode)
Returns the nearest common ancestor to this node and aNode . |
abstract List<? extends OrderedTreeNode> |
getSiblings()
Returns the List of this node's parent's children, which includes this node. |
boolean |
hasChildren()
Reports whether this node has any children. |
boolean |
isLeaf()
|
boolean |
isNodeAncestor(OrderedTreeNode anotherNode)
Returns true if anotherNode is an ancestor of this node
-- if it is this node, this node's parent, or an ancestor of this
node's parent. |
boolean |
isNodeDescendant(OrderedTreeNode anotherNode)
Returns true if anotherNode is a descendant of this node -- if it is this node, one of this node's
children, or a descendant of one of this node's children. |
OrderedTreeNode |
nextPostOrderNode()
Returns the next node in the tree relative to the current node, in post-order traversal order. |
OrderedTreeNode |
nextPreOrderNode()
Returns the next node in the tree relative to the current node, in pre-order traversal order. |
Iterator<OrderedTreeNode> |
postOrderDescendantIterator()
Returns an iterator that will iterate the descendant nodes of this node in post-traversal (depth-first) order. |
int |
siblingIndex()
Returns this node's position within the siblings. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.foray.common.OrderedTreeNode |
---|
getOrderedParent |
Methods inherited from interface javax.swing.tree.TreeNode |
---|
getChildAt, getParent |
Constructor Detail |
---|
public AbstractOrderedTreeNode()
Method Detail |
---|
public Enumeration<? extends OrderedTreeNode> children()
children
in interface TreeNode
public Iterator<OrderedTreeNode> postOrderDescendantIterator()
public abstract List<? extends OrderedTreeNode> getChildren()
public abstract boolean getAllowsChildren()
getAllowsChildren
in interface TreeNode
public int getChildCount()
getChildCount
in interface TreeNode
public int getIndex(TreeNode node)
getIndex
in interface TreeNode
public boolean isLeaf()
isLeaf
in interface TreeNode
public abstract List<? extends OrderedTreeNode> getSiblings()
public int siblingIndex()
OrderedTreeNode
siblingIndex
in interface OrderedTreeNode
public OrderedTreeNode getPreviousSibling()
OrderedTreeNode
getPreviousSibling
in interface OrderedTreeNode
public OrderedTreeNode getNextSibling()
OrderedTreeNode
getNextSibling
in interface OrderedTreeNode
public boolean hasChildren()
OrderedTreeNode
hasChildren
in interface OrderedTreeNode
public OrderedTreeNode getFirstChild()
OrderedTreeNode
getFirstChild
in interface OrderedTreeNode
public OrderedTreeNode getLastChild()
OrderedTreeNode
getLastChild
in interface OrderedTreeNode
public OrderedTreeNode nextPreOrderNode()
OrderedTreeNode
nextPreOrderNode
in interface OrderedTreeNode
public OrderedTreeNode nextPostOrderNode()
nextPostOrderNode
in interface OrderedTreeNode
public OrderedTreeNode getFirstLeaf()
DefaultMutableTreeNode
).
This implementation was liberated from DefaultMutableTreeNode
).
getFirstLeaf
in interface OrderedTreeNode
TreeNode.isLeaf()
,
DefaultMutableTreeNode.isNodeDescendant(javax.swing.tree.DefaultMutableTreeNode)
public OrderedTreeNode getLastLeaf()
DefaultMutableTreeNode
).
This implementation was liberated from DefaultMutableTreeNode
).
getLastLeaf
in interface OrderedTreeNode
TreeNode.isLeaf()
,
DefaultMutableTreeNode.isNodeDescendant(javax.swing.tree.DefaultMutableTreeNode)
public OrderedTreeNode getNextLeaf()
In this implementation of the MutableNode
interface,
this operation is very inefficient. In order to determine the
next node, this method first performs a linear search in the
parent's child-list in order to find the current node.
That implementation makes the operation suitable for short
traversals from a known position. But to traverse all of the
leaves in the tree, you should use depthFirstEnumeration
to enumerate the nodes in the tree and use isLeaf
on each node to determine which are leaves.
(Liberated from DefaultMutableTreeNode
).
This implementation was liberated from DefaultMutableTreeNode
).
getNextLeaf
in interface OrderedTreeNode
DefaultMutableTreeNode.depthFirstEnumeration()
,
TreeNode.isLeaf()
public OrderedTreeNode getPreviousLeaf()
In this implementation of the MutableNode
interface,
this operation is very inefficient. In order to determine the
previous node, this method first performs a linear search in the
parent's child-list in order to find the current node.
That implementation makes the operation suitable for short
traversals from a known position. But to traverse all of the
leaves in the tree, you should use depthFirstEnumeration
to enumerate the nodes in the tree and use isLeaf
on each node to determine which are leaves.
(Liberated from DefaultMutableTreeNode
).
This implementation was liberated from DefaultMutableTreeNode
).
getPreviousLeaf
in interface OrderedTreeNode
DefaultMutableTreeNode.depthFirstEnumeration()
,
TreeNode.isLeaf()
public boolean isNodeAncestor(OrderedTreeNode anotherNode)
OrderedTreeNode
anotherNode
is an ancestor of this node
-- if it is this node, this node's parent, or an ancestor of this
node's parent. (Note that a node is considered an ancestor of itself.)
If anotherNode
is null, this method returns false. This
operation is at worst O(h) where h is the distance from the root to
this node.
isNodeAncestor
in interface OrderedTreeNode
anotherNode
- node to test as an ancestor of this node
anotherNode
public boolean isNodeDescendant(OrderedTreeNode anotherNode)
anotherNode
is a descendant of this node -- if it is this node, one of this node's
children, or a descendant of one of this node's children.
Note that a node is considered a descendant of itself.
If anotherNode
is null, returns false.
This operation is at worst O(h) where h is the distance from the root to anotherNode
.
This implementation was liberated from DefaultMutableTreeNode
).
anotherNode
- Node to test as descendant of this node.
anotherNode
isNodeAncestor(org.foray.common.OrderedTreeNode)
,
getSharedAncestor(org.foray.common.OrderedTreeNode)
public OrderedTreeNode getSharedAncestor(OrderedTreeNode aNode)
aNode
.
Returns null, if no such ancestor exists -- if this node and aNode
are in different trees or if
aNode
is null.
A node is considered an ancestor of itself.
This implementation was liberated from DefaultMutableTreeNode
).
aNode
- node to find common ancestor with
aNode
,
or null if noneisNodeAncestor(org.foray.common.OrderedTreeNode)
,
isNodeDescendant(org.foray.common.OrderedTreeNode)
public int getLevel()
OrderedTreeNode
DefaultMutableTreeNode
).
getLevel
in interface OrderedTreeNode
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |