Source of StackComposition.java


  1: // Fig. 17.12: StackComposition.java
  2: // Class StackComposition definition with composed List object.
  3: package com.deitel.jhtp6.ch17;
  4: 
  5: public class StackComposition 
  6: {
  7:    private List stackList;
  8: 
  9:    // no-argument constructor
 10:    public StackComposition() 
 11:    { 
 12:       stackList = new List( "stack" ); 
 13:    } // end StackComposition no-argument constructor
 14: 
 15:    // add object to stack
 16:    public void push( Object object )
 17:    { 
 18:       stackList.insertAtFront( object ); 
 19:    } // end method push
 20: 
 21:    // remove object from stack
 22:    public Object pop() throws EmptyListException
 23:    { 
 24:       return stackList.removeFromFront(); 
 25:    } // end method pop
 26: 
 27:    // determine if stack is empty
 28:    public boolean isEmpty() 
 29:    { 
 30:       return stackList.isEmpty(); 
 31:    } // end method isEmpty
 32: 
 33:    // output stack contents
 34:    public void print() 
 35:    { 
 36:       stackList.print(); 
 37:    } // end method print
 38: } // end class StackComposition
 39: 
 40: 
 41: /**************************************************************************
 42:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 43:  * Pearson Education, Inc. All Rights Reserved.                           *
 44:  *                                                                        *
 45:  * DISCLAIMER: The authors and publisher of this book have used their     *
 46:  * best efforts in preparing the book. These efforts include the          *
 47:  * development, research, and testing of the theories and programs        *
 48:  * to determine their effectiveness. The authors and publisher make       *
 49:  * no warranty of any kind, expressed or implied, with regard to these    *
 50:  * programs or to the documentation contained in these books. The authors *
 51:  * and publisher shall not be liable in any event for incidental or       *
 52:  * consequential damages in connection with, or arising out of, the       *
 53:  * furnishing, performance, or use of these programs.                     *
 54:  *************************************************************************/