1 package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels;
3 import at.ac.tuwien.sbc.valesriegler.common.TableModel;
4 import at.ac.tuwien.sbc.valesriegler.common.Util;
5 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
6 import at.ac.tuwien.sbc.valesriegler.types.Table;
8 import java.util.ArrayList;
11 public class TablesOverviewModel extends TableModel<Table> {
12 private static final String TABLE_ID = "ID";
13 private static final String STATUS = "Is free";
14 private static final String GROUP_ID = "Group ID";
15 private static final String[] COLUMNS = new String[] { TABLE_ID, STATUS, GROUP_ID };
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();
70 private Table createFreeTable() {
74 public int getTableIdOfGroup(GroupData group) {
75 synchronized (items) {
76 for (Table table : items.values()) {
77 if (table.getGroupId() == group.getId()) {
82 throw new RuntimeException("Could not find table with the wanted group");
85 public Table getTableById(int tableId) {
86 synchronized (items) {
87 for (Table table : items.values()) {
88 if (table.getId() == tableId) {
93 throw new RuntimeException("Could not find table with the wanted group");