Source of LinkedChainBase.java


  1: /**
  2:    An abstract base class for use in implementing the ADT list
  3:    by using a chain of nodes. All methods are implemented, but
  4:    since the class is abstract, no instances can be created.
  5:    
  6:    @author Frank M. Carrano
  7:    @author Timothy M. Henry
  8:    @version 4.0
  9: */
 10: public abstract class LinkedChainBase<T>
 11: {
 12:         private Node firstNode; // Reference to first node
 13:         private int  numberOfEntries;
 14:         public LinkedChainBase()
 15:         {
 16:                 initializeDataFields();
 17:         } // end default constructor
 18: /* < Implementations of the public methods clear, getLength, isEmpty, and toArray go here. >
 19:    . . .
 20:    
 21:    < Implementations of the protected, final methods getNodeAt, getFirstNode, addFirstNode,
 22:      addAfterNode, removeFirstNode, removeAfterNode, and initializeDataFields go here. >
 23:    . . . */
 24:         protected final class Node
 25:         {
 26:                 private T data;     // Entry in list
 27:                 private Node next;  // Link to next node
 28:                 protected Node(T dataPortion)
 29:                 {
 30:                         data = dataPortion;
 31:                         next = null;        
 32:                 } // end constructor
 33:                 private Node(T dataPortion, Node nextNode) // PRIVATE!
 34:                 {
 35:                         data = dataPortion;
 36:                         next = nextNode;        
 37:                 } // end constructor
 38: /*    < Implementations of the protected methods getData, setData, and getNextNode go here. >
 39:       . . .
 40:       
 41:       < Implementation of the private method setNextNode goes here. >
 42:       . . . */
 43:         } // end Node
 44: } // end LinkedChainBase