-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelfServeCounterManager.java
More file actions
84 lines (66 loc) · 2.19 KB
/
SelfServeCounterManager.java
File metadata and controls
84 lines (66 loc) · 2.19 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
class SelfServeCounterManager implements Servable {
private final ImList<Servable> q;
private static final double THRESHOLD = 1E-15;
private final int maxWait;
private final int currWait;
private final boolean isCounter;
private final int idx;
SelfServeCounterManager(ImList<Servable> start, int maxWait, int currWait, int idx) {
q = start;
this.idx = idx;
this.maxWait = maxWait;
this.currWait = currWait;
this.isCounter = true;
}
public SelfServeCounterManager setTime(int idx, double time) {
Servable updatedCounter = q.get(idx).setTime(0, time);
return new SelfServeCounterManager(q.set(
idx, updatedCounter), this.maxWait, this.currWait, this.idx);
}
public SelfServeCounterManager updateWait(int num) {
int change = this.currWait + num;
change = change <= 0 ? 0 : change;
change = change > this.maxWait ? this.maxWait : change;
return new SelfServeCounterManager(q, this.maxWait, change, this.idx);
}
public boolean canServe(int idx, Customer cus) {
Servable currCounter = q.get(idx);
double diff = currCounter.getTime(0) - cus.getTime();
return Math.abs(diff) < THRESHOLD || diff < 0;
}
public int getIdx() {
return this.idx;
}
public boolean isCounter() {
return this.isCounter;
}
public ImList<Servable> getQ() {
return this.q;
}
public Servable setQ(ImList<Servable> nextQ) {
return new SelfServeCounterManager(
nextQ, this.maxWait, this.currWait, this.idx);
}
public boolean canWait() {
return this.currWait < this.maxWait;
}
public int getWait() {
return this.currWait;
}
public double getTime(int idx) {
return q.get(idx).getTime(0);
}
public double getRest() {
return 0;
}
public int getMaxWait() {
return this.maxWait;
}
public int getName() {
return q.get(0).getName();
}
@Override
public String toString() {
return q.get(0).toString();
}
}