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 Table table = items.get(rowIndex);
24 String wantedColumn = COLUMNS[columnIndex];
25 switch (wantedColumn) {
29 return table.isFree();
31 return table.getGroupId();
33 throw new RuntimeException(UNHANDLEDCOLUMN);
37 public int getNumberOfFreeTables() {
38 return getIdsOfFreeTables().size();
41 public List<Integer> getIdsOfFreeTables() {
42 List<Integer> ids = new ArrayList<>();
44 synchronized (items) {
45 for (Table table : items) {
47 ids.add(table.getId());
55 public List<Table> createFreeTables(int numberOfTables) {
56 synchronized (items) {
57 List<Table> tables = new ArrayList<Table>();
58 for (int i = 0; i < numberOfTables; i++) {
59 Table table = createFreeTable();
68 private Table createFreeTable() {