-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManager.java
More file actions
38 lines (30 loc) · 1.29 KB
/
Manager.java
File metadata and controls
38 lines (30 loc) · 1.29 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
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
public class Manager { //singleton
private static Manager ourInstance = new Manager();
private final List<Table> restaurantTables = new ArrayList<Table>(10);
private int currentIndex = 0;
private final Queue<Order> orderQueue = new ConcurrentLinkedQueue<Order>(); // очередь с заказами
private final Queue<Dishes> dishesQueue = new ConcurrentLinkedQueue<Dishes>(); // очередь с готовыми блюдами
public synchronized static Manager getInstance() {
return ourInstance;
}
private Manager() { // создаем 10 столов
for (int i = 0; i < 10; i++) {
restaurantTables.add(new Table());
}
}
public synchronized Table getNextTable() { // официант ходит по кругу от 1 стола к 10
Table table = restaurantTables.get(currentIndex);
currentIndex = (currentIndex + 1) % 10;
return table;
}
public Queue<Order> getOrderQueue() {
return orderQueue;
}
public Queue<Dishes> getDishesQueue() {
return dishesQueue;
}
}