-
Notifications
You must be signed in to change notification settings - Fork 0
/
Done.java
60 lines (47 loc) · 1.51 KB
/
Done.java
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
class Done implements Event {
private final Customer customer;
private final double time;
private static final int priority = 0;
private final Servable server;
private final boolean toPrint;
private static final EventType type = EventType.DONE;
Done(Customer customer, Servable s) {
this.customer = customer;
this.time = customer.getTime();
this.server = s;
this.toPrint = true;
}
public Pair<Event, ImList<Servable>> process(ImList<Servable> server) {
Servable currServer = server.get(this.server.getIdx());
if (currServer.isCounter()) {
return new Pair<Event, ImList<Servable>>(this, server);
}
currServer = currServer.setTime(0, currServer.getTime(0) + currServer.getRest());
server = server.set(this.server.getIdx(),
currServer);
return new Pair<Event, ImList<Servable>>(this, server);
}
public double getTime() {
return this.time;
}
public Customer getCustomer() {
return this.customer;
}
public EventType getType() {
return Done.type;
}
public int getPriority() {
return Done.priority;
}
public boolean canPrint() {
return this.toPrint;
}
public Servable getServer() {
return this.server;
}
@Override
public String toString() {
return String.format("%.3f %s done serving by %s",
this.getTime(), this.customer.toString(), this.server.toString());
}
}