From 22ebcc96ac298a705a1fc8d4bc1f4be0bb9db021 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Sat, 4 May 2013 17:11:50 +0200 Subject: [PATCH] prepare merge of jms branch. --- .../tuwien/sbc/valesriegler/group/Group.java | 43 +++++++++--- .../{MinimalGroup.java => GroupData.java} | 2 +- .../sbc/valesriegler/group/GroupState.java | 2 +- .../group/gui/GroupOverviewModel.java | 70 +++++++++++-------- .../gui/tablemodels/GroupsOverviewModel.java | 6 +- 5 files changed, 80 insertions(+), 43 deletions(-) rename src/main/java/at/ac/tuwien/sbc/valesriegler/group/{MinimalGroup.java => GroupData.java} (89%) diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java index f7f87fb..1a1446f 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java @@ -1,39 +1,62 @@ package at.ac.tuwien.sbc.valesriegler.group; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import at.ac.tuwien.sbc.valesriegler.common.PizzaType; -public class Group implements Serializable { - private MinimalGroup minimalGroup = new MinimalGroup(); - +// TODO: move all data to GroupData. Angabe: Jede gruppe muss in einem eigenen Thread laufen. +// Use this class as local datastore only and GroupData as serializable datastore. +public class Group implements Runnable { + private static final Logger log = LoggerFactory.getLogger(Group.class); + private GroupData groupData = new GroupData(); + private List pizzas = new ArrayList(); - private GroupState state = GroupState.WAITING; - + private GroupState state = GroupState.NEW; + public int getId() { - return minimalGroup.getId(); + return groupData.getId(); } + public void setId(int id) { - this.minimalGroup.setId(id); + groupData.setId(id); } + public int getSize() { - return this.minimalGroup.getSize(); + return groupData.getSize(); } + public void setSize(int size) { - this.minimalGroup.setSize(size); + groupData.setSize(size); } + public List getPizzas() { return pizzas; } + public void setPizzas(List pizzas) { this.pizzas = pizzas; } + public GroupState getState() { return state; } + public void setState(GroupState state) { this.state = state; } + + public void goGrabSomeFood() { + state = GroupState.WAITING; + log.info("goGrabSomeFood()"); + } + + @Override + public void run() { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupData.java similarity index 89% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupData.java index dd97a4b..00b936c 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupData.java @@ -7,7 +7,7 @@ import java.io.Serializable; * * @author Gregor Riegler */ -public class MinimalGroup implements Serializable { +public class GroupData implements Serializable { private int id; private int size; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupState.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupState.java index 1b9e817..f564a8c 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupState.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupState.java @@ -3,5 +3,5 @@ package at.ac.tuwien.sbc.valesriegler.group; import java.io.Serializable; public enum GroupState implements Serializable { - WAITING, SITTING, ORDERED, EATING, PAY, GONE + NEW, WAITING, SITTING, ORDERED, EATING, PAY, GONE } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java index 1696fa9..69d4aa5 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java @@ -1,6 +1,5 @@ package at.ac.tuwien.sbc.valesriegler.group.gui; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; @@ -14,67 +13,82 @@ import at.ac.tuwien.sbc.valesriegler.group.Group; public class GroupOverviewModel extends TableModel { private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class); - + private static final String STATE = "State"; private static final String PIZZAS = "Pizzas"; private static final String SIZE = "Size"; private static final String ID = "ID"; - private static final String[] COLUMNS = new String[] { - ID, SIZE, PIZZAS, STATE - }; - + private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE }; + @Override protected String[] getColumns() { return COLUMNS; } - + + public List getItems() { + return items; + } + @Override public Object getValueAt(int rowIndex, int columnIndex) { Group group = items.get(rowIndex); String wantedColumn = COLUMNS[columnIndex]; - switch(wantedColumn) { - case ID : + switch (wantedColumn) { + case ID: int groupId = group.getId(); log.info("This is the group id : {}", groupId); - return groupId; - case SIZE : + return groupId; + case SIZE: int groupSize = group.getSize(); log.info("This is the size : {}", groupSize); - return groupSize; - case PIZZAS : return pizzaDisplay(group.getPizzas()); - case STATE : return group.getState(); - default : throw new RuntimeException(UNHANDLEDCOLUMN); + return groupSize; + case PIZZAS: + return pizzaDisplay(group.getPizzas()); + case STATE: + return group.getState(); + default: + throw new RuntimeException(UNHANDLEDCOLUMN); } } /** * - * @return A display string for PizzaTypes. - *

- * e.g. Cardinale, Cardinale, Margherita is displayed as "2xCARDINALE,1xMARGHERITA" + * @return A display string for PizzaTypes. + *

+ * e.g. Cardinale, Cardinale, Margherita is displayed as + * "2xCARDINALE,1xMARGHERITA" */ private String pizzaDisplay(List pizzas) { HashMap pizzaCount = new HashMap(); for (PizzaType pizzaType : pizzas) { - if(pizzaCount.containsKey(pizzaType)) { - pizzaCount.put(pizzaType, pizzaCount.get(pizzaType)+1); - } - else pizzaCount.put(pizzaType, 1); + if (pizzaCount.containsKey(pizzaType)) { + pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1); + } else + pizzaCount.put(pizzaType, 1); } Set pizzaTypes = pizzaCount.keySet(); StringBuilder sb = new StringBuilder(); - + boolean multiplePizzas = false; for (PizzaType pizzaType : pizzaTypes) { - if(multiplePizzas) sb.append(","); - else multiplePizzas = true; - + if (multiplePizzas) + sb.append(","); + else + multiplePizzas = true; + sb.append(pizzaCount.get(pizzaType) + "x"); sb.append(pizzaType.toString()); } - + return sb.toString(); } - + @Override + public void addItems(List newItems) { + log.info("addItems()"); + super.addItems(newItems); + for (Group g : newItems) { + g.goGrabSomeFood(); + } + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java index 86ab447..4427ae8 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java @@ -1,9 +1,9 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; import at.ac.tuwien.sbc.valesriegler.common.TableModel; -import at.ac.tuwien.sbc.valesriegler.group.MinimalGroup; +import at.ac.tuwien.sbc.valesriegler.group.GroupData; -public class GroupsOverviewModel extends TableModel { +public class GroupsOverviewModel extends TableModel { private static final String ID = "ID"; private static final String SIZE = "Size"; @@ -18,7 +18,7 @@ public class GroupsOverviewModel extends TableModel { @Override public Object getValueAt(int rowIndex, int columnIndex) { - MinimalGroup group = items.get(rowIndex); + GroupData group = items.get(rowIndex); String wantedColumn = COLUMNS[columnIndex]; switch(wantedColumn) { case ID : return group.getId(); -- 2.43.0