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.common.Util;
8 import at.ac.tuwien.sbc.valesriegler.types.Table;
10 public class TablesOverviewModel extends TableModel<Table> {
11 private static final String TABLE_ID = "ID";
12 private static final String STATUS = "Is free";
13 private static final String GROUP_ID = "Group ID";
14 private static final String[] COLUMNS = new String[] { TABLE_ID, STATUS, GROUP_ID };
15 private int idCounter = 1;
18 protected String[] getColumns() {
23 public Object getValueAt(int rowIndex, int columnIndex) {
24 List<Table> values = new ArrayList<>(items.values());
25 Table table = values.get(rowIndex);
26 String wantedColumn = COLUMNS[columnIndex];
27 switch (wantedColumn) {
31 return table.isFree();
33 return Util.getId(table.getGroupId());
35 throw new RuntimeException(UNHANDLEDCOLUMN);
39 public int getNumberOfFreeTables() {
40 return getIdsOfFreeTables().size();
43 public List<Integer> getIdsOfFreeTables() {
44 List<Integer> ids = new ArrayList<>();
46 synchronized (items) {
47 for (Table table : items.values()) {
49 ids.add(table.getId());
57 public List<Table> createFreeTables(int numberOfTables) {
58 List<Table> tables = new ArrayList<Table>();
59 for (int i = 0; i < numberOfTables; i++) {
60 Table table = createFreeTable();
69 private Table createFreeTable() {