]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java
Waiter listens for free tables and for new guests. When a table gets free he tries...
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / pizzeria / gui / tablemodels / TablesOverviewModel.java
1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
7 import at.ac.tuwien.sbc.valesriegler.types.Table;
8
9 public class TablesOverviewModel extends TableModel<Table> {
10         private static final String TABLE_ID = "ID";
11         private static final String STATUS = "Is free";
12         private static final String GROUP_ID = "Group ID";
13         private static final String[] COLUMNS = new String[] { TABLE_ID, STATUS, GROUP_ID };
14         private int idCounter = 1;
15
16         @Override
17         protected String[] getColumns() {
18                 return COLUMNS;
19         }
20
21         @Override
22         public Object getValueAt(int rowIndex, int columnIndex) {
23                 List<Table> values = new ArrayList<>(items.values());
24                 Table table = values.get(rowIndex);
25                 String wantedColumn = COLUMNS[columnIndex];
26                 switch (wantedColumn) {
27                 case TABLE_ID:
28                         return table.getId();
29                 case STATUS:
30                         return table.isFree();
31                 case GROUP_ID:
32                         return table.getGroupId();
33                 default:
34                         throw new RuntimeException(UNHANDLEDCOLUMN);
35                 }
36         }
37
38         public int getNumberOfFreeTables() {
39                 return getIdsOfFreeTables().size();
40         }
41
42         public List<Integer> getIdsOfFreeTables() {
43                 List<Integer> ids = new ArrayList<>();
44
45                 synchronized (items) {
46                         for (Table table : items.values()) {
47                                 if (table.isFree()) {
48                                         ids.add(table.getId());
49                                 }
50                         }
51                 }
52
53                 return ids;
54         }
55
56         public List<Table> createFreeTables(int numberOfTables) {
57                 List<Table> tables = new ArrayList<Table>();
58                 for (int i = 0; i < numberOfTables; i++) {
59                         Table table = createFreeTable();
60                         tables.add(table);
61                 }
62
63 //              setItems(tables);
64
65                 return tables;
66         }
67
68         private Table createFreeTable() {
69                 return new Table();
70         }
71 }