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); }
public void load() { Collection<ContainerDTO> productContainers = containerDAO.readAll(); TreeMap<Integer, Set<ProductGroup>> parentToChild = new TreeMap<Integer, Set<ProductGroup>>(); for (ContainerDTO containerDTO : productContainers) { if (containerDTO.getContainerId() == -1) { StorageUnit storageUnit = new StorageUnit().storageUnitConverter(containerDTO); storageUnits.add(storageUnit); idToContainer.put(storageUnit.getId(), storageUnit); } else { addToMap(containerDTO, parentToChild); } } setProductGroups(parentToChild, null); }
/** * Initializes container and adds it to the parent. Also adds container to list of ProductGroup if * instance of ProductGroup, otherwise parent is null. * * @pre container != null * @param parent * @param container */ private void addContainerToTree(Container parent, Container container) { assert container != null; container.setContainer(parent); // container.setId( uniqueId++ ); if (container instanceof ProductGroup) { parent.addProductGroup((ProductGroup) container); } else { storageUnits.add((StorageUnit) container); } ContainerDTO containerDTO = new ContainerDTO(container); containerDAO.create(containerDTO); container.setId(containerDTO.getId()); idToContainer.put(container.getId(), container); ChangeObject hint = getHintObject(container); setChanged(); notifyObservers(hint); }