/** * Edits the container and all of the children containers. * * @pre parameters != null * @pre canEditContainer( newContainer ) == true * @post if( checkCanEdit(container) ) { edit(container); } * @param oldContainer The original container * @param newContainer The new container values * @throws IllegalArgumentException if oldContainer == null or newContainer == null or * newContainer.canEdit == false */ public void editContainer(Container oldContainer, Container newContainer) throws IllegalArgumentException { if (oldContainer == null || newContainer == null || !canEditContainer(newContainer)) { throw new IllegalArgumentException(); } System.out.println(" ------ Editing container --------"); System.out.println("Before: " + oldContainer + "\nAfter:" + newContainer + ""); if (oldContainer instanceof ProductGroup) { Container parent = oldContainer.getContainer(); // added for bug fix parent.getProductGroups().remove((ProductGroup) oldContainer); oldContainer.setName(newContainer.getName()); ((ProductGroup) oldContainer) .setThreeMonthSupply(((ProductGroup) newContainer).getThreeMonthSupply()); parent.getProductGroups().add((ProductGroup) oldContainer); } else { storageUnits.remove(oldContainer); oldContainer.setName(newContainer.getName()); storageUnits.add((StorageUnit) oldContainer); // added for bug fix } containerDAO.update(new ContainerDTO(oldContainer)); ChangeObject hint = getHintObject(oldContainer); setChanged(); notifyObservers(hint); }
/** * Recursively gets all of the productGroups from the given container. * * @pre none * @param container * @param pgList */ private void recursivelyGetDescendents(Container container, Set<Container> pgList) { assert true; Set<ProductGroup> productGroupList = container.getProductGroups(); pgList.addAll(productGroupList); if (productGroupList.isEmpty()) { return; } for (ProductGroup productGroup : productGroupList) { recursivelyGetDescendents(productGroup, pgList); } }
/** * Deletes the container and all of the children containers. * * @pre Container.items() == 0, recursively, see condition below ***(can't assert that items == 0, * have to trust)*** * @pre container.exists() == true * @post delete(container), recursively * @param container Current container to be deleted * @throws IllegalArgumentException if container.container == null && container instanceof * ProductGroup */ public void deleteContainer(Container container) throws IllegalArgumentException { Container parent = container.getContainer(); if (container instanceof ProductGroup) { if (parent == null) { throw new IllegalArgumentException(); } Set<ProductGroup> productGroupList = container.getContainer().getProductGroups(); productGroupList.remove(container); } else { storageUnits.remove(container); } ChangeObject hint; if (parent == null || parent.getProductGroups().isEmpty()) { hint = getHintObject(parent); } else { hint = getHintObject(parent.getProductGroups().iterator().next()); } containerDAO.delete(new ContainerDTO(container)); idToContainer.remove(container.getId()); setChanged(); notifyObservers(hint); }