-
Notifications
You must be signed in to change notification settings - Fork 0
/
CmdStartNewDay.java
38 lines (29 loc) · 1.04 KB
/
CmdStartNewDay.java
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
32
33
34
35
36
37
38
public class CmdStartNewDay extends RecordedCommand{
private String dateString;
private SystemDate prevDate;
public void execute(String[] cmdParts) throws ExInsufficientCmdArgs, ExInvalidNewDay, ExInvalidDayFormat{
if(cmdParts.length<2){
throw new ExInsufficientCmdArgs();
}
prevDate = SystemDate.getInstance();
dateString = cmdParts[1];
SystemDate newSysDate = new SystemDate(dateString); // may lead to an invalid date format exception
if(newSysDate.compareTo(prevDate)<=0){
throw new ExInvalidNewDay(prevDate);
}
SystemDate.setToNULL();
SystemDate.createTheInstance(dateString);
addUndoCommand(this);
clearRedoList();
System.out.println("Done.");
}
public void undoMe(){
SystemDate.set(prevDate);
addRedoCommand(this);
}
public void redoMe(){
SystemDate.setToNULL();
SystemDate.createTheInstance(dateString);
addUndoCommand(this);
}
}