예제 #1
0
 /**
  * Abstract Method, Checks to see if given productsName is unique among the list of ProductGroups.
  *
  * @pre container != null
  * @param groupName String name in question
  * @return True if all of the qualifications are met and false otherwise.
  */
 private boolean isUniqueProductGroupName(Container container) {
   assert container != null;
   if (container.getName() == null) {
     return false;
   }
   for (ProductGroup productGroup : container.getContainer().getProductGroups()) {
     if (container.getName().equals(productGroup.getName())) {
       return false;
     }
   }
   return true;
 }
예제 #2
0
 private void addToMap(
     ContainerDTO containerDTO, TreeMap<Integer, Set<ProductGroup>> parentToChild) {
   ProductGroup productGroup = new ProductGroup().productGroupConverter(containerDTO);
   if (parentToChild.containsKey(containerDTO.getContainerId())) {
     parentToChild.get(containerDTO.getContainerId()).add(productGroup);
   } else {
     Set<ProductGroup> productGroups = new TreeSet<ProductGroup>();
     productGroups.add(productGroup);
     parentToChild.put(containerDTO.getContainerId(), productGroups);
   }
   idToContainer.put(productGroup.getId(), productGroup);
 }
예제 #3
0
  /**
   * 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);
  }