-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCmdCreate.java
More file actions
36 lines (30 loc) · 934 Bytes
/
CmdCreate.java
File metadata and controls
36 lines (30 loc) · 934 Bytes
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
public class CmdCreate extends RecordedCommand{
//We add instance fields in the objects to store the data which will be needed upon undo/redo
private Equipment e;
@Override
public void execute(String[] cmdParts) throws ExInsufficientArguments, ExEquipmentCodeAlreadyInUse
{
if (cmdParts.length<3)
throw new ExInsufficientArguments();
Equipment existingEquipment = Club.getInstance().searchEquipment(cmdParts[1]);
if (existingEquipment != null)
throw new ExEquipmentCodeAlreadyInUse(cmdParts[1],existingEquipment.getName());
e = new Equipment(cmdParts[1],cmdParts[2]);
Club.getInstance().addEquipment(e);
addUndoCommand(this);
clearRedoList();
System.out.println("Done.");
}
@Override
public void undoMe()
{
Club.getInstance().removeEquipment(e);
addRedoCommand(this);
}
@Override
public void redoMe()
{
Club.getInstance().addEquipment(e);
addUndoCommand(this);
}
}