This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CmdCheckIn.java
71 lines (66 loc) · 2.49 KB
/
CmdCheckIn.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.ArrayList;
public class CmdCheckIn extends RecordedCommand{
private Item item;
private Member returner;
private Member Onholder;
private Day preloanDate;
private boolean isOnhold=false;
private ArrayList<Member> PreQueue=new ArrayList<Member>();
@Override
public void execute(String[] cmdParts) {
try{
if(cmdParts.length!=3){
throw new ExInsufficientCommand();
}
Club club=Club.getInstance();
item=club.findItem(cmdParts[2]);
returner=club.findMember(cmdParts[1]);
item.hasBorrowedBythisPerson(returner);
preloanDate=item.getloanDate();
club.ReturnItems(item, returner);
if(item.myQueueisNotEmpty()){
PreQueue.addAll(item.getQueue());
isOnhold=true;
Onholder=item.getQueue().get(0);
club.setOnhold(Onholder,item);
System.out.printf("Item [%s %s] is ready for pick up by [%s %s]. On hold due on %s.\n",item.getID(),item.getName(),item.getOnholder().getID(),item.getOnholder().getName(),Day.addDay(item.getOnholdDate(), 3));
}
System.out.println("Done.");
addUndoCommand(this);
clearRedoList();
}catch(ExItemNotFound e){
System.out.println(e.getMessage());
} catch (ExMemberIDNotFound e) {
System.out.println(e.getMessage());
} catch (ExItemNotBorrowedBythisMember e) {
System.out.println(e.getMessage());
} catch (ExInsufficientCommand e) {
System.out.println(e.getMessage());
}
}
@Override
public void undoMe() {
Club club=Club.getInstance();
if(!isOnhold){
club.BorrowingItemsAction(item,returner,preloanDate);
}
else{
club.BorrowingItemsAction(item,returner,preloanDate);
club.undoOnholdItemAction(item, Onholder,PreQueue);
}
addRedoCommand(this);
}
@Override
public void redoMe() {
Club club=Club.getInstance();
if(!isOnhold){
club.ReturnItems(item,returner);
}
else{
club.ReturnItems(item,returner);
club.setOnhold(Onholder, item);
System.out.printf("Item [%s %s] is ready for pick up by [%s %s]. On hold due on %s.\n",item.getID(),item.getName(),Onholder.getID(),Onholder.getName(),item.getOnholddueDate());
}
addUndoCommand(this);
}
}