/** * Adds the specified item to a productContainer * * @param item The Item to add * @param container The ProductContainer to add the Item to * @pre item != null * @pre items.contains(item) * @pre productsToItems.get(item.getProduct()).contains(item) * @post removedItems.contains(item) * @post !items.contains(item) */ @Override public void unmanage(Item item) { undoManage(item); Set<Item> items = new TreeSet<Item>(); if (removedItems.containsKey(item.getProduct())) items = removedItems.get(item.getProduct()); items.add(item); removedItems.put(item.getProduct(), items); notifyObservers(new Action(item, ActionType.DELETE)); }
@Override public void editItem(Item item, Date newEntryDate) { items.remove(item); Set<Item> localItems = productsToItems.remove(item.getProduct()); localItems.remove(item); item.setEntryDate(newEntryDate); localItems.add(item); productsToItems.put(item.getProduct(), localItems); items.add(item); notifyObservers(new Action(item, ActionType.EDIT)); }
/** * @param item * @pre item != null * @pre removedItems.contains(item) * @post !removedItems.contains(item) * @post items.contains(item) * @post productsToItems.contains(item.getBarcode()) */ @Override public void remanage(Item item) { if (item == null) { throw new IllegalArgumentException("Null Item item"); } if (removedItems.get(item.getProduct()) == null || !removedItems.get(item.getProduct()).contains(item)) throw new IllegalStateException("removedItems does not contain this item"); removedItems.get(item.getProduct()).remove(item); manage(item); notifyObservers(new Action(item, ActionType.CREATE)); }
public String toString() { String result = ""; for (Item itm : item) { result += String.format("%2d %-20s %-20s\n", itm.getQty(), itm.getProduct(), itm.getNotes()); } return result; }
/** * Undo the management of an Item without adding it to the RemovedItems list. * * @param item the Item to unmanage * @pre true * @post !items.contains(item) && !removedItems.contains(item); */ @Override public void undoManage(Item item) { if (item == null) throw new IllegalArgumentException("Item to unmanage can't be null."); // System.out.println("Unmanaging item " + item.getBarcode() + " " // + item.getProduct().getDescription()); if (!items.contains(item) || !productsToItems.get(item.getProduct()).contains(item)) { throw new IllegalStateException("unmanage() being called before manage()"); } items.remove(item); Set<Item> found = productsToItems.get(item.getProduct()); found.remove(item); if (found.isEmpty()) productsToItems.remove(item.getProduct()); item.remove(); notifyObservers(new Action(item, ActionType.DELETE)); notifyObservers(new Action(item, ActionType.DEEP_DELETE)); }
/** * Adds the given item to this Manager's indexes * * @param item Item to manage * @pre item != null * @post items.contains(item) * @post productsToItems.get(item.getProduct()).contains(item) */ @Override public void manage(Item item) { if (item == null) { throw new IllegalArgumentException("Null Item item"); } // System.out.println("Managing item " + item.getBarcode() + " " // + item.getProduct().getDescription()); Set<Item> found = productsToItems.get(item.getProduct()); if (found != null) found.add(item); else { TreeSet<Item> prItems = new TreeSet<Item>(); prItems.add(item); productsToItems.put(item.getProduct(), prItems); } items.add(item); notifyObservers(new Action(item, ActionType.CREATE)); }