-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecordedCommand.java
More file actions
31 lines (26 loc) · 1.18 KB
/
RecordedCommand.java
File metadata and controls
31 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
public abstract class RecordedCommand implements Command{
public abstract void undoMe();
public abstract void redoMe() throws ExMissingEquipmentRecord, ExOverlapBorrow, ExOverlapRequest, ExNoAvailableSet, ExMemberAlreadyBorrowing;
private static ArrayList<RecordedCommand> undoList=new ArrayList<>();
private static ArrayList<RecordedCommand> redoList=new ArrayList<>();
protected static void addUndoCommand(RecordedCommand cmd) {undoList.add(cmd);}
protected static void addRedoCommand(RecordedCommand cmd) {redoList.add(cmd);}
protected static void clearRedoList() {redoList.clear();}
public static void undoOneCommand(){
if (undoList.size() == 0){
System.out.println( "Nothing to undo.");
}
else{
undoList.remove(undoList.size()-1).undoMe();
}
}
public static void redoOneCommand() throws ExMissingEquipmentRecord, ExOverlapBorrow, ExOverlapRequest, ExNoAvailableSet, ExMemberAlreadyBorrowing{
if (redoList.size() == 0){
System.out.println( "Nothing to redo.");
}
else{
redoList.remove(redoList.size()-1).redoMe();
}
}
}