1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
3 import java.util.ArrayList;
6 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
7 import at.ac.tuwien.sbc.valesriegler.types.Table;
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;
17 protected String[] getColumns() {
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) {
30 return table.isFree();
32 return table.getGroupId();
34 throw new RuntimeException(UNHANDLEDCOLUMN);
38 public int getNumberOfFreeTables() {
39 return getIdsOfFreeTables().size();
42 public List<Integer> getIdsOfFreeTables() {
43 List<Integer> ids = new ArrayList<>();
45 synchronized (items) {
46 for (Table table : items.values()) {
48 ids.add(table.getId());
56 public List<Table> createFreeTables(int numberOfTables) {
57 synchronized (items) {
58 List<Table> tables = new ArrayList<Table>();
59 for (int i = 0; i < numberOfTables; i++) {
60 Table table = createFreeTable();
70 private Table createFreeTable() {
74 public void mergeTables(List<Table> tables) {
75 for (Table table : tables) {
76 items.put(table.getId(), table);
78 fireTableDataChanged();