Exemplo n.º 1
0
  public static void removeDuplicates(@NotNull CompositePackagingElement<?> parent) {
    List<PackagingElement<?>> prevChildren = new ArrayList<PackagingElement<?>>();

    List<PackagingElement<?>> toRemove = new ArrayList<PackagingElement<?>>();
    for (PackagingElement<?> child : parent.getChildren()) {
      if (child instanceof CompositePackagingElement<?>) {
        removeDuplicates((CompositePackagingElement<?>) child);
      }
      boolean merged = false;
      for (PackagingElement<?> prevChild : prevChildren) {
        if (child.isEqualTo(prevChild)) {
          if (child instanceof CompositePackagingElement<?>) {
            for (PackagingElement<?> childElement :
                ((CompositePackagingElement<?>) child).getChildren()) {
              ((CompositePackagingElement<?>) prevChild).addOrFindChild(childElement);
            }
          }
          merged = true;
          break;
        }
      }
      if (merged) {
        toRemove.add(child);
      } else {
        prevChildren.add(child);
      }
    }

    for (PackagingElement<?> child : toRemove) {
      parent.removeChild(child);
    }
  }
 public void removeNodes(final List<PackagingElementNode<?>> nodes) {
   Set<PackagingElement<?>> parents = new HashSet<PackagingElement<?>>();
   for (PackagingElementNode<?> node : nodes) {
     final List<? extends PackagingElement<?>> toDelete = node.getPackagingElements();
     for (PackagingElement<?> element : toDelete) {
       final Collection<PackagingNodeSource> nodeSources = node.getNodeSource(element);
       if (nodeSources.isEmpty()) {
         final CompositePackagingElement<?> parent = node.getParentElement(element);
         if (parent != null) {
           parents.add(parent);
           parent.removeChild(element);
         }
       } else {
         Collection<PackagingNodeSource> rootSources = getRootNodeSources(nodeSources);
         for (PackagingNodeSource source : rootSources) {
           parents.add(source.getSourceParentElement());
           source.getSourceParentElement().removeChild(source.getSourceElement());
         }
       }
     }
   }
   final List<PackagingElementNode<?>> parentNodes = myTree.findNodes(parents);
   for (PackagingElementNode<?> parentNode : parentNodes) {
     myTree.addSubtreeToUpdate(parentNode);
   }
 }