Source of J9.20.java


  1: /** Makes a clone of this node and its subtrees.
  2:     @author Frank M. Carrano, Timothy M. Henry
  3:     @version 5.0
  4:     @return  The clone of the subtree rooted at this node. */
  5: public Object clone()
  6: {
  7:    BinaryNode<T> theCopy = null;
  8:    try
  9:    {
 10:       @SuppressWarnings("unchecked")
 11:       BinaryNode<T> temp = (BinaryNode<T>)super.clone();
 12:       theCopy = temp;
 13:    }
 14:    catch (CloneNotSupportedException e)
 15:    {
 16:       throw new Error("BinaryNode cannot clone: " + e.toString());
 17:    }

 19:    theCopy.data = (T)data.clone();

 21:    if (left != null)
 22:       theCopy.left = (BinaryNode<T>)left.clone();

 24:    if (right != null)
 25:       theCopy.right = (BinaryNode<T>)right.clone();

 27:    return theCopy;
 28: } // end clone