Commit 6b6746d8 authored by Marvin Plettner's avatar Marvin Plettner
Browse files

Properly publishes to multiple queues; warehouse # is in order now

parent 7f44b624
......@@ -3,7 +3,7 @@ TARGET="./target/"
JAR="swingmq-1.0-SNAPSHOT-jar-with-dependencies.jar"
CLASSPATH="${TARGET}${JAR}"
java -cp ${CLASSPATH} com.sodapopsoftware.mq.SwingPublisher &
java -cp ${CLASSPATH} com.sodapopsoftware.mq.SwingPublisher -h 2 &
java -cp ${CLASSPATH} com.sodapopsoftware.mq.SwingWarehouse &
java -cp ${CLASSPATH} com.sodapopsoftware.mq.SwingWarehouse -w 2 -x 50 -y 50 &
java -cp ${CLASSPATH} com.sodapopsoftware.mq.SwingWarehouse -w 2 -x 100 -y 100 &
......@@ -93,8 +93,8 @@ public class SwingPublisher extends JFrame implements ToolBarListener {
@Override
public void singleOrder() {
final Order order = this.orderFactory.create();
final int warehouseNumber = this.randomUtils.createBetween(1, this.maxWarehouses);
final Order order = this.orderFactory.create(warehouseNumber);
this.orderPublishingServices.publish(warehouseNumber, order);
this.swingPublisherView.add(order);
}
......
......@@ -16,22 +16,28 @@ public class Order implements Serializable, Iterable<LineItem> {
private static final long serialVersionUID = -575188258094997934L;
private final int warehouseNumber;
private final int orderNumber;
private final List<LineItem> lineItems;
private Order(int orderNumber, List<LineItem> lineItems) {
private Order(int warehouseNumber, int orderNumber, List<LineItem> lineItems) {
this.warehouseNumber = warehouseNumber;
this.orderNumber = orderNumber;
this.lineItems = lineItems;
}
public LineItem get(int index) {
return this.lineItems.get(index);
public int getWarehouseNumber() {
return this.warehouseNumber;
}
public int getOrderNumber() {
return this.orderNumber;
}
public LineItem get(int index) {
return this.lineItems.get(index);
}
@Override
public Iterator<LineItem> iterator() {
return this.lineItems.iterator();
......@@ -63,12 +69,18 @@ public class Order implements Serializable, Iterable<LineItem> {
*/
public static class OrderBuilder {
private int warehouseNumber;
private int orderNumber;
private final List<LineItem> lineItems = new LinkedList<>();
public OrderBuilder() {
}
public OrderBuilder warehouseNumber(int warehouseNumber) {
this.warehouseNumber = warehouseNumber;
return this;
}
public OrderBuilder orderNumber(int orderNumber) {
this.orderNumber = orderNumber;
return this;
......@@ -80,10 +92,10 @@ public class Order implements Serializable, Iterable<LineItem> {
}
public Order build() {
if (this.lineItems.size() == 0 || this.orderNumber == 0) {
if (this.warehouseNumber == 0 || this.lineItems.size() == 0 || this.orderNumber == 0) {
throw new AppException("Order is missing a number or has zero line items");
}
return new Order(this.orderNumber, this.lineItems);
return new Order(this.warehouseNumber, this.orderNumber, this.lineItems);
}
}
......
......@@ -10,10 +10,11 @@ public class OrderFactory {
public OrderFactory() {
}
public Order create() {
public Order create(int warehouseNumber) {
final int NumberOfLineItems = this.randomUtils.createBetween(1, 10);
final Order.OrderBuilder orderBuilder = new Order.OrderBuilder();
orderBuilder.warehouseNumber(warehouseNumber);
orderBuilder.orderNumber(this.randomUtils.createBetween(1000000, 1999999));
for (int index = 0; index < NumberOfLineItems; index++) {
orderBuilder.lineItem(this.lineItemFactory.create());
......
......@@ -11,7 +11,7 @@ public class OrderTableModel extends AbstractTableModel {
private static final long serialVersionUID = 40386320243981477L;
private final String[] columnNames = { "Order #", "Item Count", "Total Cost" };
private final String[] columnNames = { "Warehouse #", "Order #", "Item Count", "Total Cost" };
private final List<Order> tableRows = new ArrayList<>();
@Override
......@@ -37,12 +37,15 @@ public class OrderTableModel extends AbstractTableModel {
switch (col) {
case 0:
returnValue = order.getOrderNumber();
returnValue = order.getWarehouseNumber();
break;
case 1:
returnValue = order.getItemCount();
returnValue = order.getOrderNumber();
break;
case 2:
returnValue = order.getItemCount();
break;
case 3:
returnValue = order.getTotalCost();
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment