edu.toronto.cs.util
Class NaryTree

java.lang.Object
  extended by edu.toronto.cs.util.NaryTree

public class NaryTree
extends java.lang.Object

This is an N-ary Tree class.


Field Summary
protected  java.util.Map children
           
protected  java.lang.Object data
           
 
Constructor Summary
NaryTree()
          Constructs a new NaryTree assigning null to Data and no children.
NaryTree(java.lang.Object d)
          Constructs a new NaryTree contaning the specified Object as its data and no children.
NaryTree(java.lang.Object d, java.util.Map c)
          Constructs a new NaryTree with given data as well as the children.
 
Method Summary
 boolean existChild(java.lang.Object name)
          Checks whether such a child exists.
 NaryTree getChild(java.lang.Object id)
          Gets the child with the specified id.
 java.util.Map getChildren()
          Retrieves the Map of children.
 java.lang.Object getData()
          Retrieves the data from the NaryTree.
 int getNumChildren()
          Gets the number of children that this tree node has.
 void setChild(java.lang.Object id, NaryTree child)
          Changes the nth child of the NaryTree.
 void setChildren(java.util.Map c)
          Assigns a new Map of children.
 void setData(java.lang.Object d)
          Changes the data in the NaryTree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected java.lang.Object data

children

protected java.util.Map children
Constructor Detail

NaryTree

public NaryTree()
Constructs a new NaryTree assigning null to Data and no children.


NaryTree

public NaryTree(java.lang.Object d)
Constructs a new NaryTree contaning the specified Object as its data and no children.

Parameters:
d - -- data to be stored in the root node.

NaryTree

public NaryTree(java.lang.Object d,
                java.util.Map c)
Constructs a new NaryTree with given data as well as the children.

Parameters:
d - -- data to be stored in the root node.
c - -- a Map contaning children (of type NaryTree).
Method Detail

getData

public java.lang.Object getData()
Retrieves the data from the NaryTree.

Returns:
-- data contained in the root node.

getNumChildren

public int getNumChildren()
Gets the number of children that this tree node has.


getChildren

public java.util.Map getChildren()
Retrieves the Map of children.

Returns:
-- a Map of children.

getChild

public NaryTree getChild(java.lang.Object id)
Gets the child with the specified id.


setData

public void setData(java.lang.Object d)
Changes the data in the NaryTree.


setChild

public void setChild(java.lang.Object id,
                     NaryTree child)
Changes the nth child of the NaryTree.


setChildren

public void setChildren(java.util.Map c)
Assigns a new Map of children.

Parameters:
c - -- a Map of children.

existChild

public boolean existChild(java.lang.Object name)
Checks whether such a child exists.