-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneSystem.java
More file actions
33 lines (29 loc) · 1.03 KB
/
PhoneSystem.java
File metadata and controls
33 lines (29 loc) · 1.03 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
package simModel;
import java.util.Comparator;
import java.util.PriorityQueue;
public class PhoneSystem {
protected PriorityQueue<Call> list;
protected int trunklinesNum;
protected int reservedLines;
protected int numOfCalls;
public PhoneSystem(int trunkLinesNum, int reservedLines) {
Comparator<Call> comp = new CallComparator();
this.trunklinesNum = trunkLinesNum;
this.reservedLines = reservedLines;
list = new PriorityQueue<Call>(trunkLinesNum, comp);
}
public class CallComparator implements Comparator<Call> {
public int compare(Call a, Call b) {
if(a.uType > b.uType) {
return -1;
} else if(a.uType < b.uType) {
return 1;
} else if(a.uType == b.uType && a.uStartWaitTime < b.uStartWaitTime) {
return -1;
} else if(a.uType == b.uType && a.uStartWaitTime > b.uStartWaitTime) {
return 1;
}
return 0; // Never going to happen
}
}
}