/*
 * StackClass.java  
 *
 * Copyright 2001
 * College of Computer Science
 * Northeastern University
 * Boston, MA  02115
 *
 * This software may be used for educational purposes as long as
 * this copyright notice is retained intact at the top of all files.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either in whole
 * or in part without explicit permission.
 *
 * Contact information:
 *   Richard Rasala    rasala@ccs.neu.edu
 *   Viera Proulx      vkp@ccs.neu.edu
 *   Jeff Raab         jmr@ccs.neu.edu
 *   Jennifer McDonald jenimac@ccs.neu.edu
 * 
 * Telephone:          617-373-2462
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */
 
import java.util.Stack;

public class StackClass {

	public interface Action {
		
		public void doAction(Stack s);
		public void undoAction(Stack s);
		public String getActionString();
	}
	
	public static Action pushAction(final Symbol x) {
	
		return new Action() {
		
			Symbol z = x;
			
			public void doAction(Stack s) {
				s.push(z);
			}
			
			public void undoAction(Stack s) {
				s.pop();
			}
			
			public String getActionString() {
				return "Pushed " + z.toStringData();
			}
		};
	}
	
	public static Action popAction() {
	
		return new Action() {
			
			Symbol z;
			
			public void doAction(Stack s) {
				z = (Symbol) s.pop();
			}
			
			public void undoAction(Stack s) {
				s.push(z);
			}
			
			public String getActionString() {
				return "Popped Stack";
			}
		};
	}
	
	public static Action nopAction() {
	
		return new Action() {
			
			public void doAction(Stack s) {
				// do nothing
			}
			
			public void undoAction(Stack s) {
				// do nothing
			}
			
			public String getActionString() {
				return "No Action";
			}
		};
	}
}
