-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEquipmentSet.java
More file actions
145 lines (128 loc) · 4.81 KB
/
EquipmentSet.java
File metadata and controls
145 lines (128 loc) · 4.81 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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import java.util.ArrayList;
import java.util.Collections;
public class EquipmentSet implements Comparable<EquipmentSet>{
private String eCode_Set;
private Boolean available;
private String memberID;
private Reservation borrow;
private String currentStatus;
private ArrayList<Reservation> requestList;
public EquipmentSet(String eCode, int setNumber){
this.eCode_Set = eCode + "_" + Integer.toString(setNumber);
this.available = true;
this.currentStatus = "Available";
this.requestList = new ArrayList<>();
this.borrow = new Reservation();
this.memberID = null;
}
public String geteCode_Set(){return this.eCode_Set;}
public String getMemberID() {return this.memberID;}
public String getcurrentStatus(){return this.currentStatus;}
public String getRequestPeriods(){
String returnString = "";
for (int i=0;i<requestList.size();i++) {
returnString += requestList.get(i).toString();
if (i!=requestList.size()-1)
returnString += ", ";
}
return returnString;
}
@Override
public int compareTo(EquipmentSet another) {
return this.eCode_Set.compareTo(another.eCode_Set);
}
public Boolean borrowSet(Day startDay, Day endDay, Member m, String eName, Boolean redo) throws ExMemberAlreadyBorrowing, ExOverlapBorrow{
String mID = m.getMemberID();
Boolean overlap = false;
if (!this.available){
if (borrow.returnID()==mID){
if (borrow.checkIfConflict(startDay,endDay)){
throw new ExMemberAlreadyBorrowing();
}
else{
overlap = true;
}
}
else{
overlap = borrow.checkIfConflict(startDay,endDay);
}
}else{
for (Reservation rl : requestList) {
if (mID == rl.returnID()){
if (rl.checkIfConflict(startDay,endDay)){
throw new ExOverlapBorrow();
}
} else{
overlap = rl.checkIfConflict(startDay,endDay);
if (overlap) break;
}
}
}
if (!overlap){
String mName = m.getName();
this.available = false;
this.memberID = mID;
this.borrow.set(startDay,endDay,mID);
String period = borrow.toString();
String memberStatus = "borrows " + eCode_Set + " (" + eName + ")" + " for " + period;
this.currentStatus = mID + " "+ mName + " borrows for " + period;
m.addBorrowStatus(memberStatus);
if (!redo)
System.out.println(mID + " "+ mName + " " + memberStatus);
return true;
}
return false;
}
public void unborrowSet(Member m){
this.available = true;
this.borrow.reset();
this.memberID = null;
this.currentStatus = "Available";
m.removeBorrowStatus(eCode_Set);
}
public Boolean requestSet(Day startDay, Day endDay, Member m, String eName, Boolean redo) throws ExOverlapRequest{
String mID = m.getMemberID();
Boolean overlap = false;
if (borrow.checkIfConflict(startDay,endDay)){
if (borrow.returnID() == mID){
throw new ExOverlapRequest();
}
overlap = true;
}
for (Reservation rl : requestList) {
if (mID == rl.returnID()){
if (rl.checkIfConflict(startDay,endDay)){
throw new ExOverlapRequest();
}
} else{
overlap = rl.checkIfConflict(startDay,endDay);
if (overlap) break;
}
}
if (!overlap){
String mName = m.getName();
Reservation r = new Reservation(startDay,endDay,mID);
String memberStatus = "requests " + eCode_Set + " (" + eName + ")" + " for " + r.toString();
m.addRequestStatus(memberStatus);
requestList.add(r);
Collections.sort(requestList);
if (!redo)
System.out.println(mID + " "+ mName + " " + memberStatus);
return true;
}
return false;
}
public Boolean unRequestSet(Member m, int requestDays, String sDay){
String mID = m.getMemberID();
Day startDay = new Day(sDay);
Day endDay = startDay.incrementByDays(requestDays);
for (Reservation rl : requestList) {
if (rl.equals(startDay,endDay,mID)){
requestList.remove(rl);
m.removeRequestStatus(eCode_Set,startDay.toString(),endDay.toString());
return true;
}
}
return false;
}
}