public This removeAllChildren() { getChildrenPaths().forEach(this::removeChild); children.remove(myPath); return castThis(); }
public This removeAllChildren() { getChildrenPaths().forEach(this::removeChild); children.remove(myPath); return castThis(); }
@SuppressWarnings("unchecked") private InventoryStructure.Builder<B> mergeShallowTree(InventoryStructure<?> currentTree, RelativePath treePath, InventoryStructure.AbstractBuilder<?> newTree, Set<SegmentType> mergedTypes) { DBG.debugf("Starting to merge shallow tree. Loading children under [%s]", treePath); try (Stream<InventoryStructure.FullNode> currentChildren = currentTree.getAllChildNodes(treePath)) { DBG.debugf("Done loading the children under [%s]", treePath); Set<Path.Segment> newChildPaths = newTree.getChildrenPaths(); currentChildren.forEach(currentChild -> { SegmentType childType = Inventory.types().byBlueprint(currentChild.getEntity().getClass()).getSegmentType(); Path.Segment childPathSegment = new Path.Segment(childType, currentChild.getEntity().getId()); if (newChildPaths.contains(childPathSegment)) { mergeShallowTree(currentTree, treePath.modified().extend(childPathSegment).get(), newTree.getChild(childPathSegment), mergedTypes); } else if (!mergedTypes.contains(childType)) { newTree.addChild(currentChild.getEntity(), currentChild.getAttachment()); } }); DBG.debugf("Done merging shallow tree of [%s]", treePath); if (newTree instanceof InventoryStructure.Builder) { return (InventoryStructure.Builder<B>) newTree; } else { return null; } } }
@SuppressWarnings("unchecked") private InventoryStructure.Builder<B> mergeDeepTree(InventoryStructure<?> currentTree, RelativePath treePath, InventoryStructure.AbstractBuilder<?> newTree, Set<SegmentType> mergedTypes) { DBG.debugf("Starting to merge shallow tree. Loading children under [%s]", treePath); try (Stream<InventoryStructure.FullNode> currentChildren = currentTree.getAllChildNodes(treePath)) { DBG.debugf("Done loading the children under [%s]", treePath); Set<Path.Segment> newChildPaths = newTree.getChildrenPaths(); currentChildren.forEach(currentChild -> { SegmentType childType = Inventory.types().byBlueprint(currentChild.getEntity().getClass()).getSegmentType(); Path.Segment childPathSegment = new Path.Segment(childType, currentChild.getEntity().getId()); if (newChildPaths.contains(childPathSegment)) { mergeDeepTree(currentTree, treePath.modified().extend(childPathSegment).get(), newTree.getChild(childPathSegment), mergedTypes); } else if (!mergedTypes.contains(childType)) { newTree.addChild(currentChild.getEntity(), currentChild.getAttachment()); mergeDeepTree(currentTree, treePath.modified().extend(childPathSegment).get(), newTree.getChild(childPathSegment), mergedTypes); } }); DBG.debugf("Done merging shallow tree of [%s]", treePath); if (newTree instanceof InventoryStructure.Builder) { return (InventoryStructure.Builder<B>) newTree; } else { return null; } } }