-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServes.java
More file actions
63 lines (49 loc) · 1.61 KB
/
Serves.java
File metadata and controls
63 lines (49 loc) · 1.61 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
class Serves implements Event {
private final Customer customer;
private final double time;
private static final int priority = 2;
private final Servable server;
private final boolean toPrint;
private static final EventType type = EventType.SERVED;
Serves(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> serverList) {
Servable currServer = serverList.get(this.server.getIdx());
Customer newCus = this.customer.setTime(this.server.getTime(0));
currServer = currServer.updateWait(-1);
serverList = serverList.set(this.server.getIdx(),
currServer);
Event nextEvent = new Done(newCus, currServer);
if (currServer.isCounter()) {
nextEvent = new Done(newCus, this.server);
}
return new Pair<Event, ImList<Servable>>(nextEvent, serverList);
}
public double getTime() {
return this.time;
}
public Customer getCustomer() {
return this.customer;
}
public EventType getType() {
return Serves.type;
}
public int getPriority() {
return Serves.priority;
}
public Servable getServer() {
return this.server;
}
public boolean canPrint() {
return this.toPrint;
}
@Override
public String toString() {
return String.format("%.3f %s serves by %s",
this.getTime(), this.customer.toString(), this.server.toString());
}
}