Source of JI9.20.java


  1: /** Makes a clone of this node and its subtrees.
  2:  @return  The clone of the subtree rooted at this node. */
  3: public Object clone()
  4: {
  5:    BinaryNode<T> theCopy = null;
  6:    try
  7:    {
  8:       @SuppressWarnings("unchecked")
  9:       BinaryNode<T> temp = (BinaryNode<T>)super.clone();
 10:       theCopy = temp;
 11:    }
 12:    catch (CloneNotSupportedException e)
 13:    {
 14:       throw new Error("BinaryNode cannot clone: " + e.toString());
 15:    }
 16: 
 17:    theCopy.data = (T)data.clone();
 18: 
 19:    if (left != null)
 20:       theCopy.left = (BinaryNode<T>)left.clone();
 21: 
 22:    if (right != null)
 23:       theCopy.right = (BinaryNode<T>)right.clone();
 24: 
 25:    return theCopy;
 26: } // end clone
 27: // Version 4.0