public class ActionHistory { private class Node { private T content = null; private Node nextNode = null; public Node(T content) { setContent(content); } private void setContent(T content) { this.content = content; } private T getContent() { return this.content; } private void setNextNode(Node nextNode) { this.nextNode = nextNode; } private Node getNextNode() { return this.nextNode; } } private Node head = null; public ActionHistory() {} public boolean isEmpty() { if (head == null) { return true; } return false; } public void push(Object content) { if (isEmpty()) { head = new Node(content); } else { Node newNode = new Node(content); newNode.setNextNode(head); head = newNode; } } public Object pop() { if (isEmpty()) { return null; } Object content = head.getContent(); head = head.getNextNode(); return content; } public Object top() { return ((isEmpty()) ? null : head.getContent()); } }