// Path: src/main/java/com/stacks/Stack.java
// public class Stack<Item> implements Iterable<Item> {
// 
// 	private Node first;
// 	
// 	/**
// 	 * Constructs a Stack object.
// 	 *  
// 	 */
// 	public Stack() {
// 		first = null;
// 	}
// 	
// 	/**
// 	 * inserts an item into the stack.
// 	 * @param item An item to be added onto the stack.
// 	 */
// 	public void push(Item item) {
// 		Node oldfirst = first;
// 		first = new Node();
// 		first.item = item;
// 		first.next = oldfirst;
// 	}
// 	
// 	/**
// 	 * removes the last item inserted in the stack.
// 	 * @return an item inserted recently.
// 	 */
// 	public Item pop() {
// 		if(isEmpty())
// 			throw new NoSuchElementException("No item present on stack");
// 		Item item = first.item;
// 		first = first.next;
// 		return item;
// 	}
// 	
// 	/**
// 	 * retrieves the last item inserted in the stack, but does not remove
// 	 * @return an item inserted recently.
// 	 */
// 	public Item peek() {
// 		if(isEmpty())
// 			throw new NoSuchElementException("No item present on stack");
// 		Item item = first.item;
// 		return item;
// 	}
// 	
// 	/**
// 	 * checks to see if stack is empty.
// 	 * @return true if stack is empty, false otherwise.
// 	 */
// 	public boolean isEmpty() {
// 		return (first == null);
// 	}
// 	
// 	/**
// 	 * returns the number of elements in the stack.
// 	 * @return the size of stack as integer.
// 	 */
// 	public int size() {
// 		int count = 0;
// 		for(Item item : this) {
// 			count++;
// 		}
// 		return count;
// 	}
// 
// 	/**
// 	 * clears the stack object by permanently deleting the content.
// 	 * Once this action is performed, it cannot be undone.
// 	 */
// 	public void clear() {
// 		first = null;
// 	}
// 	/**
// 	 * returns an iterator over the stack data structure.
// 	 * 
// 	 */
// 	public Iterator<Item> iterator() {
// 		return new StackIterator();
// 	}
// 		
// 	/**
// 	 * Node class represents a single node used to store single
// 	 * element on the stack in a link based implementation.
// 	 * 
// 	 * @author Ashish Chopra
// 	 *
// 	 */
// 	private class Node {
// 		Item item;
// 		Node next;
// 	}
// 
// 	/**
// 	 * StackIterator implements Iterator interface
// 	 * to provide iterable capabilities to the stack
// 	 * data structure.
// 	 * 
// 	 * @author Ashish Chopra
// 	 *
// 	 */
// 	private class StackIterator implements Iterator<Item> {
// 
// 		private Node current = first;
// 		
// 		public boolean hasNext() {	
// 			return current != null;	
// 		}
// 
// 		public Item next() {
// 			Item item = current.item;
// 			current = current.next;
// 			return item;
// 		}
// 
// 		public void remove() {
// 			throw new UnsupportedOperationException("Remove operation not supported on stack");
// 		}	
// 	}
// }


import com.stacks.Stack;
/*
 *	File: Checkpoint.java
 *	Author: Ashish Chopra
 *	Date: 27 Nov, 2015
 * ----------------------------------------------------
 *  Checkpoint data structure is used to store actions of an application.
 *  It also provides functionality to undo an action or redo an action.
 *  
 *  This data structure only abstracts the said functionality, without getting
 *  into the details of performing actions. Hence for simplicity, i took
 *  the action to be an integer code that will be stored in the data structure.
 *  
 *  Checkpoint API
 *  ---------------------------------------------------------
 *  		Checkpoint()			// creates a new checkpoint data structure
 *  boolean		add(Item actionCode)	// adds the action code
 *  Item	undo()					// undo the last performed action.
 *  Item	redo()					// redo the last performed undo action.
 *  int		size()					// return the size of all actions stored as of yet.
 *  boolean	isEmpty()				// returns is the checkpoint list is empty.
 *  
 *  
 *    
 */
package com.applications;


public class Checkpoint<Item> {

	private Stack<Item> current;	// maintains the list of actions performed in chronological order.
// Path: src/main/java/com/stacks/Stack.java
// public class Stack<Item> implements Iterable<Item> {
// 
// 	private Node first;
// 	
// 	/**
// 	 * Constructs a Stack object.
// 	 *  
// 	 */
// 	public Stack() {
// 		first = null;
// 	}
// 	
// 	/**
// 	 * inserts an item into the stack.
// 	 * @param item An item to be added onto the stack.
// 	 */
// 	public void push(Item item) {
// 		Node oldfirst = first;
// 		first = new Node();
// 		first.item = item;
// 		first.next = oldfirst;
// 	}
// 	
// 	/**
// 	 * removes the last item inserted in the stack.
// 	 * @return an item inserted recently.
// 	 */
// 	public Item pop() {
// 		if(isEmpty())
// 			throw new NoSuchElementException("No item present on stack");
// 		Item item = first.item;
// 		first = first.next;
// 		return item;
// 	}
// 	
// 	/**
// 	 * retrieves the last item inserted in the stack, but does not remove
// 	 * @return an item inserted recently.
// 	 */
// 	public Item peek() {
// 		if(isEmpty())
// 			throw new NoSuchElementException("No item present on stack");
// 		Item item = first.item;
// 		return item;
// 	}
// 	
// 	/**
// 	 * checks to see if stack is empty.
// 	 * @return true if stack is empty, false otherwise.
// 	 */
// 	public boolean isEmpty() {
// 		return (first == null);
// 	}
// 	
// 	/**
// 	 * returns the number of elements in the stack.
// 	 * @return the size of stack as integer.
// 	 */
// 	public int size() {
// 		int count = 0;
// 		for(Item item : this) {
// 			count++;
// 		}
// 		return count;
// 	}
// 
// 	/**
// 	 * clears the stack object by permanently deleting the content.
// 	 * Once this action is performed, it cannot be undone.
// 	 */
// 	public void clear() {
// 		first = null;
// 	}
// 	/**
// 	 * returns an iterator over the stack data structure.
// 	 * 
// 	 */
// 	public Iterator<Item> iterator() {
// 		return new StackIterator();
// 	}
// 		
// 	/**
// 	 * Node class represents a single node used to store single
// 	 * element on the stack in a link based implementation.
// 	 * 
// 	 * @author Ashish Chopra
// 	 *
// 	 */
// 	private class Node {
// 		Item item;
// 		Node next;
// 	}
// 
// 	/**
// 	 * StackIterator implements Iterator interface
// 	 * to provide iterable capabilities to the stack
// 	 * data structure.
// 	 * 
// 	 * @author Ashish Chopra
// 	 *
// 	 */
// 	private class StackIterator implements Iterator<Item> {
// 
// 		private Node current = first;
// 		
// 		public boolean hasNext() {	
// 			return current != null;	
// 		}
// 
// 		public Item next() {
// 			Item item = current.item;
// 			current = current.next;
// 			return item;
// 		}
// 
// 		public void remove() {
// 			throw new UnsupportedOperationException("Remove operation not supported on stack");
// 		}	
// 	}
// }


// Path: src/main/java/com/applications/Checkpoint.java
import com.stacks.Stack;

/*
 *	File: Checkpoint.java
 *	Author: Ashish Chopra
 *	Date: 27 Nov, 2015
 * ----------------------------------------------------
 *  Checkpoint data structure is used to store actions of an application.
 *  It also provides functionality to undo an action or redo an action.
 *  
 *  This data structure only abstracts the said functionality, without getting
 *  into the details of performing actions. Hence for simplicity, i took
 *  the action to be an integer code that will be stored in the data structure.
 *  
 *  Checkpoint API
 *  ---------------------------------------------------------
 *  		Checkpoint()			// creates a new checkpoint data structure
 *  boolean		add(Item actionCode)	// adds the action code
 *  Item	undo()					// undo the last performed action.
 *  Item	redo()					// redo the last performed undo action.
 *  int		size()					// return the size of all actions stored as of yet.
 *  boolean	isEmpty()				// returns is the checkpoint list is empty.
 *  
 *  
 *    
 */
package com.applications;


public class Checkpoint<Item> {

	private Stack<Item> current;	// maintains the list of actions performed in chronological order.
	private Stack<Item> removed;	// maintains the list of actions undone from current list in chronological order.