-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
52 lines (42 loc) · 1.38 KB
/
Customer.java
File metadata and controls
52 lines (42 loc) · 1.38 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
package cs2030.simulator;
import java.util.function.Supplier;
import cs2030.util.Lazy;
class Customer {
private static final double DEFAULT_SERVICE_TIME = 1.0;
private final int id;
private final Supplier<Double> arrivalTime;
private final Lazy<Double> serviceTime;
Customer(int id, double arrivalTime) {
this.id = id;
this.arrivalTime = () -> arrivalTime;
this.serviceTime = Lazy.<Double>of(() -> DEFAULT_SERVICE_TIME);
}
Customer(int id, double arrivalTime, Supplier<Double> serviceTime) {
this.id = id;
this.arrivalTime = () -> arrivalTime;
this.serviceTime = Lazy.<Double>of(serviceTime);
}
Customer(int id, double arrivalTime, Lazy<Double> serviceTime) {
this.id = id;
this.arrivalTime = () -> arrivalTime;
this.serviceTime = serviceTime;
}
Customer(int id, Supplier<Double> arrivalTime, Lazy<Double> serviceTime) {
this.id = id;
this.arrivalTime = arrivalTime;
this.serviceTime = serviceTime;
}
Customer wait(Supplier<Double> waitUntil) {
return new Customer(this.id, waitUntil, this.serviceTime);
}
int getID() {
return id;
}
double getFinishTime() {
return this.arrivalTime.get() + this.serviceTime.get();
}
@Override
public String toString() {
return String.format("%d", id);
}
}