|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Tree
A positional container representing an ordered tree.
The children of each internal node
are ordered. A tree always has at least one node
(isEmpty()
always returns false
). The
smallest tree is a single external node.
InspectableTree
Method Summary | |
---|---|
java.lang.Object |
contract(Position node)
Replaces a node with its children in the appropriate order. |
Tree |
cut(Position node)
Cuts this tree above the given node , and replaces
this position with an external node with a null element. |
Position |
expand(Position fromChild,
Position toChild,
java.lang.Object elem)
Replaces a set of consecutive children with a new node having those children as its children in the appropriate order. |
Position |
insertAfterSibling(Position node,
java.lang.Object elem)
Inserts a new sibling after a given node |
Position |
insertBeforeSibling(Position node,
java.lang.Object elem)
Inserts a new sibling before a given node. |
Position |
insertChildAtRank(Position node,
int rank,
java.lang.Object elem)
Inserts a new child of node at the specified rank. |
Position |
insertFirstChild(Position node,
java.lang.Object elem)
Inserts a new child of node as the first child. |
Position |
insertLastChild(Position node,
java.lang.Object elem)
Inserts a new child of node as the last child. |
java.lang.Object |
link(Position extNode,
Tree t)
Links tree t at external node extNode
by replacing ExtNode with the root of t . |
java.lang.Object |
removeExternal(Position node)
Removes an external node (a leaf). |
Tree |
replaceSubtree(Position node,
Tree t)
Replaces the subtree rooted at node with the tree
t . |
Methods inherited from interface nz.ac.waikato.jdsl.core.api.InspectableTree |
---|
childAtRank, children, firstChild, isExternal, isInternal, isRoot, lastChild, numChildren, parent, rankOfChild, root, siblingAfter, siblingBefore, siblings |
Methods inherited from interface nz.ac.waikato.jdsl.core.api.PositionalContainer |
---|
swapElements |
Methods inherited from interface nz.ac.waikato.jdsl.core.api.InspectablePositionalContainer |
---|
positions |
Methods inherited from interface nz.ac.waikato.jdsl.core.api.Container |
---|
newContainer, replaceElement |
Methods inherited from interface nz.ac.waikato.jdsl.core.api.InspectableContainer |
---|
contains, elements, isEmpty, size |
Method Detail |
---|
Tree cut(Position node) throws InvalidAccessorException
node
, and replaces
this position with an external node with a null element. The
subtree cut off at that point is returned to the user as a brand
new Tree
intstance.
node
- The position above which to make the cut;
will be the root of the returned tree
InvalidAccessorException
- if node
is null
or does not belong to this tree.java.lang.Object link(Position extNode, Tree t) throws InvalidAccessorException, InvalidContainerException
t
at external node extNode
by replacing ExtNode
with the root of t
.
As a result of this method, the positions of tree t
become positions of this tree and tree t
becomes
a tree with a single node with a null element.
extNode
- The position to insert the tree
t
at.t
- The subtree to insert at the position.
extNode
InvalidAccessorException
- if extNode
is
not external, is null, or does not belong to this tree.
InvalidContainerException
- if t
is null,
incompatible with, or equal to this tree.Tree replaceSubtree(Position node, Tree t) throws InvalidAccessorException, InvalidContainerException
node
with the tree
t
. The positions of t
become positions
of this tree. The cut subtree with the node
as its
root is returned to the user as a new tree instance. All the
positions of this subtree become positions of this new tree.
Note that link(.)
and cut(.)
can both
be implemented in terms of this method.
node
- a nodet
- the tree that will replace the tree rooted
at node
node
as its root
InvalidAccessorException
- if node
is null
or does not belong to this tree.
InvalidContainerException
- if t
is null,
incompatible with, or equal to this tree.Position insertAfterSibling(Position node, java.lang.Object elem) throws BoundaryViolationException, InvalidAccessorException
node
- a node different from the rootelem
- the object to be stored in the new node
BoundaryViolationException
- if node
is the root
InvalidAccessorException
- if node
is null
or does not belong to this treePosition insertChildAtRank(Position node, int rank, java.lang.Object elem) throws BoundaryViolationException, InvalidAccessorException
node
- a noderank
- an integer index of the children of node
from 0 to numChildren(node) (inclusive)elem
- the object to be stored in the new node
BoundaryViolationException
- if rank
< 0 or
rank
> numChildren(node
)
InvalidAccessorException
- if node
is null
or does not belong to this treePosition insertBeforeSibling(Position node, java.lang.Object elem) throws BoundaryViolationException, InvalidAccessorException
node
- a nodeelem
- the object to be stored in the new node
BoundaryViolationException
- if node
is the root
InvalidAccessorException
- if node
is null
or does not belong to this treePosition insertFirstChild(Position node, java.lang.Object elem) throws InvalidAccessorException
node
as the first child.
node
- a nodeelem
- the object to be stored in the new node
InvalidAccessorException
- if node
is null
or does not belong to this treePosition insertLastChild(Position node, java.lang.Object elem) throws InvalidAccessorException
node
- a nodeelem
- the object to be stored in the new node
InvalidAccessorException
- if node
is null
or does not belong to this treejava.lang.Object removeExternal(Position node) throws BoundaryViolationException, InvalidAccessorException
node
- a leaf node different from the root
node
BoundaryViolationException
- if node
is not
external or is the root
InvalidAccessorException
- if node
is null
or does not belong to this treejava.lang.Object contract(Position node) throws BoundaryViolationException, InvalidAccessorException
node
, and then inserts its children,
maintaining their order, between siblingBefore(node
)
and siblingAfter(node
).
node
- a node
node
BoundaryViolationException
- if node
is the
root or an external node
InvalidAccessorException
- if node
is null
or does not belong to this treePosition expand(Position fromChild, Position toChild, java.lang.Object elem) throws InvalidAccessorException
fromChild
and
toChild
(inclusive), inserts a new node in their
place, and makes the removed children the children of the new
node, maintaining their order.
fromChild
- a nodetoChild
- any higher-ranked sibling of
fromChild
or fromChild
itselfelem
- the object to be stored in the new node
InvalidAccessorException
- if fromChild
and
toChild
are not siblings, or if toChild
is a lower-ranked sibling of fromChild
, or if either
of them is null or does not belong to this tree
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |