-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelfchecks.java
More file actions
48 lines (41 loc) · 1.5 KB
/
Selfchecks.java
File metadata and controls
48 lines (41 loc) · 1.5 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
class Selfchecks extends Server {
private final ImList<Double> availableTimes;
Selfchecks(int id, int qmax, int queue, ImList<Double> availableTimes) {
super(id, qmax, queue);
this.availableTimes = availableTimes;
}
public int checkAvailable(double arrivalTime) {
for (int i = 0; i < availableTimes.size(); i++) {
if (availableTimes.get(i) <= arrivalTime) {
return i;
}
}
return -1;
}
public Server enqueue() {
return new Selfchecks(this.id, this.qmax, this.queue + 1, this.availableTimes);
}
public Server dequeue() {
if (queue == 0) {
return this;
} else {
return new Selfchecks(this.id, this.qmax, this.queue - 1, this.availableTimes);
}
}
public Server updateAvailableTime(int index, double newAvailableTime) {
return new Selfchecks(this.id, this.qmax, this.queue, this.availableTimes.set(index,
newAvailableTime));
}
public double requiredWaitingTime(double currentTime) {
double earliestAvailableTime = Double.POSITIVE_INFINITY;
for (int i = 0; i < availableTimes.size(); i++) {
if (earliestAvailableTime > availableTimes.get(i)) {
earliestAvailableTime = availableTimes.get(i);
}
}
return earliestAvailableTime - currentTime;
}
public String toString(int subId) {
return String.format("self-check %d", this.id + subId);
}
}