-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanServer.java
More file actions
56 lines (47 loc) · 1.6 KB
/
HumanServer.java
File metadata and controls
56 lines (47 loc) · 1.6 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
import java.util.function.Supplier;
class HumanServer extends Server {
private final double availableTime;
private final Supplier<Double> restTimes;
HumanServer(int id, int qmax, int queue, double availableTime, Supplier<Double> restTimes) {
super(id, qmax, queue);
this.availableTime = availableTime;
this.restTimes = restTimes;
}
public int checkAvailable(double currentTime) {
if (availableTime <= currentTime) {
return 0;
} else {
return -1;
}
}
public Server enqueue() {
return new HumanServer(this.id, this.qmax, this.queue + 1, this.availableTime,
this.restTimes);
}
public Server dequeue() {
if (queue == 0) {
return this;
} else {
return new HumanServer(this.id, this.qmax, this.queue - 1, this.availableTime,
this.restTimes);
}
}
public Server checkRest() {
double restTime = restTimes.get();
if (restTime > 0) {
return new HumanServer(this.id, this.qmax, this.queue, this.availableTime + restTime,
this.restTimes);
} else {
return this;
}
}
public Server updateAvailableTime(int index, double newAvailableTime) {
return new HumanServer(this.id, this.qmax, this.queue, newAvailableTime, this.restTimes);
}
public double requiredWaitingTime(double currentTime) {
return this.availableTime - currentTime;
}
public String toString(int subId) {
return String.format("%d", this.id);
}
}