Opus5
Class NaryTree
java.lang.Object
|
+--Opus5.AbstractObject
|
+--Opus5.AbstractContainer
|
+--Opus5.AbstractTree
|
+--Opus5.NaryTree
- All Implemented Interfaces:
- Comparable, Container, Tree
- public class NaryTree
- extends AbstractTree
A node in an N-ary tree.
- Version:
- $Id: NaryTree.java,v 3.1 1998/07/28 01:32:17 brpreiss Exp $
- Author:
- Bruno R. Preiss, P.Eng.
|
Field Summary |
protected int |
degree
The degree of this node. |
protected java.lang.Object |
key
The key in this node. |
protected NaryTree[] |
subtree
The subtrees of this node. |
|
Constructor Summary |
NaryTree(int degree)
Construct an empty NaryTree with the specified degree. |
NaryTree(int degree,
java.lang.Object key)
Construct an NaryTree with the specified degree
and the specified key. |
|
Method Summary |
void |
attachKey(java.lang.Object object)
Attaches the specified object as the key of this N-ary tree node. |
void |
attachSubtree(int i,
NaryTree t)
Attaches the specified tree as the specified subtree of this node. |
protected int |
compareTo(Comparable arg)
Compares this N-ary tree with the specified comparable object. |
java.lang.Object |
detachKey()
Detaches the key from this node; making it the empty node. |
int |
getDegree()
Returns the degree of this N-ary tree node. |
java.lang.Object |
getKey()
Returns the key of this N-ary tree node. |
Tree |
getSubtree(int i)
Returns the specified subtree of this node. |
boolean |
isEmpty()
Tests whether this N-ary tree node is empty. |
boolean |
isLeaf()
Tests whether this N-ary tree node is a leaf node. |
void |
purge()
Purges this N-ary tree node, making it empty. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
key
protected java.lang.Object key
- The key in this node.
degree
protected int degree
- The degree of this node.
subtree
protected NaryTree[] subtree
- The subtrees of this node.
NaryTree
public NaryTree(int degree)
- Construct an empty
NaryTree with the specified degree.
- Parameters:
degree - The desired degree.
NaryTree
public NaryTree(int degree,
java.lang.Object key)
- Construct an
NaryTree with the specified degree
and the specified key.
- Parameters:
degree - The desired degree.key - The desired key.
purge
public void purge()
- Purges this N-ary tree node, making it empty.
getDegree
public int getDegree()
- Returns the degree of this N-ary tree node.
- Returns:
- The degree of this node.
isLeaf
public boolean isLeaf()
- Tests whether this N-ary tree node is a leaf node.
- Returns:
- True if this node is not empty and all its subtree are;
false otherwise.
isEmpty
public boolean isEmpty()
- Tests whether this N-ary tree node is empty.
- Overrides:
isEmpty in class AbstractContainer
- Returns:
- True if this node is empty; false otherwise.
getKey
public java.lang.Object getKey()
- Returns the key of this N-ary tree node.
- Returns:
- The key of this N-ary tree node.
- Throws:
InvalidOperationException - If this node is empty.
attachKey
public void attachKey(java.lang.Object object)
- Attaches the specified object as the key of this N-ary tree node.
The node must be initially empty.
- Parameters:
object - The key to attach.- Throws:
InvalidOperationException - If this node is not empty.
detachKey
public java.lang.Object detachKey()
- Detaches the key from this node; making it the empty node.
- Throws:
InvalidOperationException - If this is not a leaf node.
getSubtree
public Tree getSubtree(int i)
- Returns the specified subtree of this node.
- Parameters:
i - The desired subtree.- Returns:
- The specified subtree of this node.
- Throws:
InvalidOperationException - If this node is empty.
attachSubtree
public void attachSubtree(int i,
NaryTree t)
- Attaches the specified tree as the specified subtree of this node.
- Parameters:
i - The number of the subtree of this node.t - The tree to attach.- Throws:
InvalidOperationException - If this node is empty or if it is not empty and
the specified subtree is also not empty.
compareTo
protected int compareTo(Comparable arg)
- Compares this N-ary tree with the specified comparable object.
This method is not implemented.
- Overrides:
compareTo in class AbstractObject
- Parameters:
arg - The comparable object with which to compare this tree.- Throws:
MethodNotImplemented - Always.