package seedu.ezdo.model;

import java.util.EmptyStackException;
//@@author A0139248X
/*
 * Array-based implementation for a stack with fixed size. Used for undo & redo stacks.
 * If stack goes past max capacity, the oldest item to be pushed is replaced.
 */
public class FixedStack<T> {
    private int index;
    private T[] array;

    public FixedStack(int capacity) {
        array = (T[]) new Object[capacity];
        index = -1;
    }

    public void push(T item) {
        index = (index + 1) % ModelManager.STACK_CAPACITY; // wraps around
        array[index] = item;
    }

    public T pop() throws EmptyStackException {
        if (index == -1 || array[index] == null) {
            throw new EmptyStackException();
        }
        T item = array[index];
        array[index] = null;
        if (index == 0) {
            index = array.length - 1;
        } else {
            index = index - 1;
        }
        return item;
    }

    public boolean isEmpty() {
        for (int i = 0; i < array.length; i++) {
            if (array[i] != null) {
                return false;
            }
        }
        return true;
    }

    public void clear() {
        for (int i = 0; i < array.length; i++) {
            array[i] = null;
        }
        index = -1;
    }
}

@@ -1,8 +1,29 @@
+//@@author A0139248X%0A
 package 
@@ -83,31 +83,12 @@
 on;%0A
-//@@author A0139248X
 %0A/*
+*
 %0A * 
@@ -229,12 +229,15 @@
 em t
-o be
+hat was
  pus
@@ -286,16 +286,68 @@
 ck%3CT%3E %7B%0A
+%0A    private static final int STARTING_INDEX = -1;%0A%0A
     priv
@@ -475,34 +475,46 @@
         index = 
--1
+STARTING_INDEX
 ;%0A    %7D%0A%0A    pub
@@ -717,18 +717,30 @@
 ndex == 
--1
+STARTING_INDEX
  %7C%7C arra
@@ -899,16 +899,58 @@
  == 0) %7B
+ // top of stack is 0, need to wrap around
 %0A       
@@ -1394,18 +1394,30 @@
 index = 
--1
+STARTING_INDEX
 ;%0A    %7D%0A

Add header comments Remove magic numbers