public void processShipments() { while (shipmentsNeedProcessing()) { Iterator<Entry<String, Shipment>> shipmentsIterator = this.getStoreShipments().get("unprocessed").entrySet().iterator(); while (shipmentsIterator.hasNext()) { Map.Entry<String, Shipment> pairs = (Entry<String, Shipment>) shipmentsIterator.next(); Shipment shipment = pairs.getValue(); if (!shipment.isProcessed()) { Iterator<Entry<Item, Integer>> it = shipment.getShipmentDetails().entrySet().iterator(); while (it.hasNext()) { Map.Entry<Item, Integer> shipmentDetail = (Map.Entry<Item, Integer>) it.next(); int shipmentQuantity = (Integer) shipmentDetail.getValue(); Item shipmentItem = shipmentDetail.getKey(); stockShipmentItem(shipmentItem, shipmentQuantity); shipment.setProcessed(true); Map<String, Shipment> processedShipment = new HashMap<String, Shipment>(); processedShipment.put(shipment.getUuid(), shipment); this.getStoreShipments().put("processed", processedShipment); this.getStoreShipments().get("unprocessed").remove(shipment.getUuid()); } } } } }
private boolean shipmentsNeedProcessing() { boolean needsProcessing = false; Iterator<Entry<String, Shipment>> shipmentsIterator = this.getStoreShipments().get("unprocessed").entrySet().iterator(); while (shipmentsIterator.hasNext()) { Map.Entry<String, Shipment> pairs = (Entry<String, Shipment>) shipmentsIterator.next(); Shipment shipment = pairs.getValue(); if (!shipment.isProcessed()) needsProcessing = true; } return needsProcessing; }