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