package lectures.undo_commands;
import util.annotations.WebDocuments;
import java.util.ArrayList;
import java.util.List;
@WebDocuments({"Lectures/UndoCommands.pptx", "Lectures/UndoCommands.pdf", "Videos/UndoCommands.avi"})
public class HistoryUndoer implements Undoer {
List<Command> historyList = new ArrayList();
int nextCommandIndex = 0;
public void execute (Command c) {
while(nextCommandIndex < historyList.size()) {
historyList.remove(nextCommandIndex); }
c.execute();
historyList.add(c);
nextCommandIndex++;
}
public void undo() {
if (nextCommandIndex == 0)return;
nextCommandIndex--;
Command c = historyList.get(nextCommandIndex);
c.undo();
}
public void redo() {
if (nextCommandIndex == historyList.size()) return;
Command c = historyList.get(nextCommandIndex);
c.execute();
nextCommandIndex++;
}
}