nz.ac.waikato.jdsl.core.api
Interface InspectableTree

All Superinterfaces:
InspectableContainer, InspectablePositionalContainer
All Known Subinterfaces:
BinaryTree, InspectableBinaryTree, Tree
All Known Implementing Classes:
NodeBinaryTree, NodeTree

public interface InspectableTree
extends InspectablePositionalContainer

Please refer to the documentation of Tree

Version:
JDSL 2.1.1
Author:
Mike Boilen (mgb), Andrew Schwerin (schwerin), Luca Vismara (lv), Galina Shubina (gs)
See Also:
Tree

Method Summary
 Position childAtRank(Position node, int rank)
           
 PositionIterator children(Position node)
          Returns an iterator over the children of the node in order.
 Position firstChild(Position node)
           
 boolean isExternal(Position node)
          Checks if a position is a leaf of this tree.
 boolean isInternal(Position node)
          Checks if a position is an internal node of this tree.
 boolean isRoot(Position node)
          Checks if a position is the root of this tree.
 Position lastChild(Position node)
           
 int numChildren(Position node)
           
 Position parent(Position node)
          Gets the parent of a given node.
 int rankOfChild(Position child)
           
 Position root()
          Gets the root of this tree.
 Position siblingAfter(Position node)
           
 Position siblingBefore(Position node)
           
 PositionIterator siblings(Position node)
          Returns an iterator over the siblings of the node in order.
 
Methods inherited from interface nz.ac.waikato.jdsl.core.api.InspectablePositionalContainer
positions
 
Methods inherited from interface nz.ac.waikato.jdsl.core.api.InspectableContainer
contains, elements, isEmpty, size
 

Method Detail

isRoot

boolean isRoot(Position node)
               throws InvalidAccessorException
Checks if a position is the root of this tree.

Parameters:
node - a node
Returns:
true if node is the root of this tree
Throws:
InvalidAccessorException - if node is null or does not belong to this tree

isInternal

boolean isInternal(Position node)
                   throws InvalidAccessorException
Checks if a position is an internal node of this tree.

Parameters:
node - a node
Returns:
true if node has at least one child
Throws:
InvalidAccessorException - if node is null or does not belong to this tree

isExternal

boolean isExternal(Position node)
                   throws InvalidAccessorException
Checks if a position is a leaf of this tree.

Parameters:
node - Any node of the tree
Returns:
true if node has no children
Throws:
InvalidAccessorException - if node is null or does not belong to this tree

root

Position root()
Gets the root of this tree.

Returns:
The top node of the tree (may also be a leaf if the tree has exactly one node)

parent

Position parent(Position node)
                throws BoundaryViolationException,
                       InvalidAccessorException
Gets the parent of a given node.

Parameters:
node - a node
Returns:
parent position of the given node
Throws:
BoundaryViolationException - if node is the root of the tree
InvalidAccessorException - if node is null or does not belong to this tree

children

PositionIterator children(Position node)
                          throws InvalidAccessorException
Returns an iterator over the children of the node in order. If the node is a leaf, the iterator has no elements. The iterator returned is a snapshot -- it iterates over all positions that were children of node at the moment that children(.) was called, regardless of subsequent modifications to the container.

Parameters:
node - a node of the tree
Returns:
iterator over all the children of node
Throws:
InvalidAccessorException - if node is null or does not belong to this tree

siblings

PositionIterator siblings(Position node)
                          throws BoundaryViolationException,
                                 InvalidAccessorException
Returns an iterator over the siblings of the node in order. in order. If the node has no siblings, the iterator has no elements. The iterator returned is a snapshot -- it iterates over all positions that were siblings of node at the moment that siblings(.) was called, regardless of subsequent modifications to the container.

Parameters:
node - a node of the tree
Returns:
iterator over all the other children of the same parent
Throws:
BoundaryViolationException - if node is the root of the tree
InvalidAccessorException - if node is null or does not belong to this tree

numChildren

int numChildren(Position node)
                throws InvalidAccessorException
Parameters:
node - a node of the tree
Returns:
the number of children of node
Throws:
InvalidAccessorException - if node is null or does not belong to this tree

siblingAfter

Position siblingAfter(Position node)
                      throws BoundaryViolationException,
                             InvalidAccessorException
Parameters:
node - a node
Returns:
the sibling after node
Throws:
BoundaryViolationException - if node is either the last child of a node or the root
InvalidAccessorException - if node is null or does not belong to this tree

childAtRank

Position childAtRank(Position node,
                     int rank)
                     throws BoundaryViolationException,
                            InvalidAccessorException
Parameters:
node - a node
rank - an integer index of the children of node; childAtRank(0) is the first child, childAtRank(numChildren(node)-1) is the last child
Returns:
the child of node at the specified rank
Throws:
BoundaryViolationException - if rank < 0 or rank > numChildren(node)-1 or node is a leaf
InvalidAccessorException - if node is null or does not belong to this tree

siblingBefore

Position siblingBefore(Position node)
                       throws BoundaryViolationException,
                              InvalidAccessorException
Parameters:
node - a node
Returns:
the sibling before node
Throws:
BoundaryViolationException - if node is either the first child of a node or the root
InvalidAccessorException - if node is null or does not belong to this tree

firstChild

Position firstChild(Position node)
                    throws BoundaryViolationException,
                           InvalidAccessorException
Parameters:
node - a node
Returns:
the first child of node
Throws:
BoundaryViolationException - if node is a leaf
InvalidAccessorException - if node is null or does not belong to this tree

lastChild

Position lastChild(Position node)
                   throws BoundaryViolationException,
                          InvalidAccessorException
Parameters:
node - a node
Returns:
the last child of node
Throws:
BoundaryViolationException - if node is a leaf
InvalidAccessorException - if node is null or does not belong to this tree

rankOfChild

int rankOfChild(Position child)
                throws BoundaryViolationException,
                       InvalidAccessorException
Parameters:
child - a node
Returns:
rank of child
Throws:
BoundaryViolationException - if child is the root
InvalidAccessorException - if child is null or does not belong to this tree


Copyright © 2009 ModelJUnit Project. All Rights Reserved.