import java.util.ArrayDeque; public class DequeTestProgram { private static int UNDO_LIST_CAPACITY = 5; private static ArrayDeque operations; private static void performOperation(String x) { if (operations.size() == UNDO_LIST_CAPACITY) operations.removeFirst(); operations.addLast(x); } private static void undo() { operations.removeLast(); } public static void main(String[] args) { operations = new ArrayDeque(); System.out.println("Simulating some cut/paste/move operations ... "); performOperation("cut1"); performOperation("paste1"); performOperation("move1"); System.out.println("Here is the undo list now: " + operations); System.out.println("Simulating an undo operation ..."); undo(); System.out.println("Here is the undo list now: " + operations); System.out.println("Simulating another undo operation ..."); undo(); System.out.println("Here is the undo list now: " + operations); System.out.println("Simulating some more cut/paste/move operations ... "); performOperation("cut2"); performOperation("paste2"); performOperation("move2"); performOperation("move3"); System.out.println("Here is the undo list now: " + operations); System.out.println("Simulating some more paste operations ... "); performOperation("paste3"); performOperation("paste4"); System.out.println("Here is the undo list now: " + operations); } }