-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrive.java
More file actions
39 lines (31 loc) · 1.26 KB
/
Arrive.java
File metadata and controls
39 lines (31 loc) · 1.26 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
package cs2030.simulator;
import java.util.Optional;
import cs2030.util.Pair;
class Arrive extends Event {
Arrive(Customer customer, double eventTime) {
super(customer, eventTime);
}
@Override
Pair<Optional<Event>, Shop> execute(Shop shop) {
Customer customer = super.getCustomer();
if (shop.getIdleServer().map(x -> x.isIdle()).orElse(false)) {
Server server = shop.getIdleServer().orElseThrow();
return Pair.<Optional<Event>, Shop>of(
Optional.<Event>of(new Serve(customer, super.getEventTime(), server)),
shop);
} else if (shop.getQueueableServer().map(x -> x.canQ()).orElse(false)) {
Server server = shop.getQueueableServer().orElseThrow();
return Pair.<Optional<Event>, Shop>of(
Optional.<Event>of(new Wait(customer, super.getEventTime(), server)),
shop);
} else {
return Pair.<Optional<Event>, Shop>of(
Optional.<Event>of(new Leave(customer, super.getEventTime())),
shop);
}
}
@Override
public String toString() {
return String.format("%s %s arrives", super.toString(), super.getCustomer().toString());
}
}