net.junaraki.libtree
Class AbstractRootedTree<T>

java.lang.Object
  extended by net.junaraki.libtree.AbstractTree<T>
      extended by net.junaraki.libtree.AbstractRootedTree<T>
Type Parameters:
T - the type of elements maintained by this tree
All Implemented Interfaces:
RootedTree<T>, Tree<T>
Direct Known Subclasses:
AbstractBinaryTree, AbstractOrderedTree, UnorderedTree

public abstract class AbstractRootedTree<T>
extends AbstractTree<T>
implements RootedTree<T>

A skeletal implementation of the RootedTree interface.

Author:
Jun Araki

Constructor Summary
AbstractRootedTree()
          Sole constructor.
 
Method Summary
 boolean contains(java.lang.Object o)
          Returns true if this tree contains a node with the specified element; otherwise returns false.
 void createRoot()
          Creates the root of this tree.
 int getHeight()
          Returns the height of this tree.
 RootedTreeNode<T> getRoot()
          Returns the root of this tree.
 boolean hasRoot()
          Returns true if this tree has the root; otherwise returns false.
 TreeNode<T> search(java.lang.Object o)
          Returns the node of this tree with the specified element.
 void setRoot(RootedTreeNode<T> root)
          Sets the specified node to the root of this tree.
 int size()
          Returns the size of this tree, i.e., the number of elements in this tree.
 java.lang.String toString()
          Returns the string representation which is similar to the Unix tree command.
 
Methods inherited from class net.junaraki.libtree.AbstractTree
isEmpty
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.junaraki.libtree.Tree
isEmpty
 

Constructor Detail

AbstractRootedTree

public AbstractRootedTree()
Sole constructor.

Method Detail

size

public int size()
Description copied from interface: Tree
Returns the size of this tree, i.e., the number of elements in this tree.

Specified by:
size in interface Tree<T>
Returns:
the size of this tree

getHeight

public int getHeight()
Description copied from interface: Tree
Returns the height of this tree.

Specified by:
getHeight in interface Tree<T>
Returns:
the height of this tree

contains

public boolean contains(java.lang.Object o)
Description copied from interface: Tree
Returns true if this tree contains a node with the specified element; otherwise returns false.

Specified by:
contains in interface Tree<T>
Returns:
true if this tree contains a node with the specified element

search

public TreeNode<T> search(java.lang.Object o)
Description copied from interface: Tree
Returns the node of this tree with the specified element.

Specified by:
search in interface Tree<T>
Returns:
the node of this tree with the specified element

createRoot

public void createRoot()
Description copied from interface: RootedTree
Creates the root of this tree.

Specified by:
createRoot in interface RootedTree<T>

getRoot

public RootedTreeNode<T> getRoot()
Description copied from interface: RootedTree
Returns the root of this tree.

Specified by:
getRoot in interface RootedTree<T>
Returns:
the root of this tree

setRoot

public void setRoot(RootedTreeNode<T> root)
Description copied from interface: RootedTree
Sets the specified node to the root of this tree.

Specified by:
setRoot in interface RootedTree<T>

hasRoot

public boolean hasRoot()
Description copied from interface: RootedTree
Returns true if this tree has the root; otherwise returns false.

Specified by:
hasRoot in interface RootedTree<T>
Returns:
true if this tree has the root

toString

public java.lang.String toString()
Returns the string representation which is similar to the Unix tree command.

Overrides:
toString in class java.lang.Object