Source of JI9.15.java


  1: public Object clone()
  2: {
  3:    LList<T> theCopy = null;
  4:    try
  5:    {
  6:       @SuppressWarnings("unchecked")
  7:       LList<T> temp = (LList<T>)super.clone();
  8:       theCopy = temp;
  9:    }
 10:    catch (CloneNotSupportedException e)
 11:    {
 12:       throw new Error(e.toString());
 13:    }
 14:    // Copy underlying chain of nodes
 15:    if (firstNode == null) // If chain is empty
 16:    {
 17:       theCopy.firstNode = null;
 18:    }
 19:    else
 20:    {
 21:       // Make a copy of the first node
 22:       @SuppressWarnings("unchecked")
 23:       Node temp = (Node)firstNode.clone();
 24:       theCopy.firstNode = temp;
 25:       // Make a copy of the rest of chain
 26:       Node newRef = theCopy.firstNode;
 27:       Node oldRef = firstNode.getNextNode();
 28:       for (int count = 2; count <= numberOfEntries; count++)
 29:       {
 30:          // Clone node and its data; link clone to new chain
 31:          @SuppressWarnings("unchecked")
 32:          Node temp2 = (Node)oldRef.clone();
 33:          newRef.setNextNode(temp2);
 34:          newRef = newRef.getNextNode();
 35:          oldRef = oldRef.getNextNode();
 36:       } // end for
 37:    } // end if
 38:    return theCopy;
 39: } // end clone
 40: // Version 4.0