@Override protected RevTree _call() { checkArgument(root != null, "root tree not provided"); if (childTreeRemoves.isEmpty() && childTreeUpdates.isEmpty()) { return root; } // all the current child trees of root final MutableTree mutableRoot = load(root); MutableTree updatedRoot = mutableRoot.clone(); this.childTreeRemoves.forEach((path) -> { updatedRoot.removeChild(path); }); this.childTreeUpdates.values().forEach((r) -> { updatedRoot.forceChild(r.getParentPath(), r.getNode()); }); ObjectDatabase db = objectDatabase(); RevTree newRoot = updatedRoot.build(db); return newRoot; }
@Override protected RevTree _call() { checkArgument(root != null, "root tree not provided"); if (childTreeRemoves.isEmpty() && childTreeUpdates.isEmpty()) { return root; } // all the current child trees of root final MutableTree mutableRoot = load(root); MutableTree updatedRoot = mutableRoot.clone(); this.childTreeRemoves.forEach((path) -> { updatedRoot.removeChild(path); }); this.childTreeUpdates.values().forEach((r) -> { updatedRoot.forceChild(r.getParentPath(), r.getNode()); }); ObjectDatabase db = objectDatabase(); RevTree newRoot = updatedRoot.build(db); return newRoot; }
/** * A renamed tree is recognized by checking if a tree on the right points to the same object * that a tree on the left that doesn't exist anymore on the right. * <p> * Left entries are the original ones, and right entries are the new ones. * </p> * * @param treeDifference * @param ignoreList */ private void handleRenames(TreeDifference treeDifference, Set<String> ignoreList) { final SortedMap<NodeRef, NodeRef> renames = treeDifference.findRenames(); for (Map.Entry<NodeRef, NodeRef> e : renames.entrySet()) { NodeRef oldValue = e.getKey(); NodeRef newValue = e.getValue(); String newPath = newValue.path(); if (ignoreList.contains(newPath)) { continue; } ignoreList.add(newPath); if (!filterMatchesOrIsParent(newPath)) { continue;// filter doesn't apply to the renamed tree as a whole } LOGGER.trace("Handling rename of {} as {}", oldValue.path(), newPath); MutableTree leftTree = treeDifference.getLeftTree(); leftTree.removeChild(oldValue.path()); leftTree.setChild(newValue.getParentPath(), newValue.getNode()); } }
/** * A renamed tree is recognized by checking if a tree on the right points to the same object * that a tree on the left that doesn't exist anymore on the right. * <p> * Left entries are the original ones, and right entries are the new ones. * </p> * * @param treeDifference * @param ignoreList */ private void handleRenames(TreeDifference treeDifference, Set<String> ignoreList) { final SortedMap<NodeRef, NodeRef> renames = treeDifference.findRenames(); for (Map.Entry<NodeRef, NodeRef> e : renames.entrySet()) { NodeRef oldValue = e.getKey(); NodeRef newValue = e.getValue(); String newPath = newValue.path(); if (ignoreList.contains(newPath)) { continue; } ignoreList.add(newPath); if (!filterMatchesOrIsParent(newPath)) { continue;// filter doesn't apply to the renamed tree as a whole } LOGGER.trace("Handling rename of {} as {}", oldValue.path(), newPath); MutableTree leftTree = treeDifference.getLeftTree(); leftTree.removeChild(oldValue.path()); leftTree.setChild(newValue.getParentPath(), newValue.getNode()); } }
@Test public void testRemoveLeafRoot() { assertNotNull(root.getChild("roads")); assertNull(root.removeChild("nonExistent")); assertNotNull(root.removeChild("roads")); ex.expect(IllegalArgumentException.class); ex.expectMessage("No child named roads exists"); root.getChild("roads"); }
@Test public void testRemoveLeafRoot() { assertNotNull(root.getChild("roads")); assertNull(root.removeChild("nonExistent")); assertNotNull(root.removeChild("roads")); ex.expect(IllegalArgumentException.class); ex.expectMessage("No child named roads exists"); root.getChild("roads"); }
private void handleDeletedTrees(TreeDifference treeDifference, Set<String> ignoreList) { SortedSet<NodeRef> deletes = treeDifference.findDeletes(); for (NodeRef ref : deletes) { String path = ref.path(); if (ignoreList.contains(path)) { continue; } ignoreList.add(path); if (!filterMatchesOrIsParent(path)) { if (filterApplies(path, treeDifference.getRightTree())) { // can't optimize RevTree newTree = applyChanges(ref, null); Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId()); MutableTree leftTree = treeDifference.getLeftTree(); leftTree.forceChild(ref.getParentPath(), newNode); } } else { MutableTree leftTree = treeDifference.getLeftTree(); leftTree.removeChild(path); } } }
private void handleDeletedTrees(TreeDifference treeDifference, Set<String> ignoreList) { SortedSet<NodeRef> deletes = treeDifference.findDeletes(); for (NodeRef ref : deletes) { String path = ref.path(); if (ignoreList.contains(path)) { continue; } ignoreList.add(path); if (!filterMatchesOrIsParent(path)) { if (filterApplies(path, treeDifference.getRightTree())) { // can't optimize RevTree newTree = applyChanges(ref, null); Node newNode = RevObjectFactory.defaultInstance().createNode(ref.name(), newTree.getId(), ref.getMetadataId(), TYPE.TREE, null, null); MutableTree leftTree = treeDifference.getLeftTree(); leftTree.forceChild(ref.getParentPath(), newNode); } } else { MutableTree leftTree = treeDifference.getLeftTree(); leftTree.removeChild(path); } } }
@Test public void testRemoveNested() { assertNotNull(root.getChild("roads/highways")); assertNotNull(root.getChild("roads/streets")); assertNull(root.removeChild("nonExistent")); assertNotNull(root.removeChild("roads/streets")); assertNotNull(root.getChild("roads")); assertNotNull(root.getChild("roads/highways")); ex.expect(IllegalArgumentException.class); ex.expectMessage("No child named streets exists"); root.getChild("roads/streets"); }
@Test public void testRemoveNested() { assertNotNull(root.getChild("roads/highways")); assertNotNull(root.getChild("roads/streets")); assertNull(root.removeChild("nonExistent")); assertNotNull(root.removeChild("roads/streets")); assertNotNull(root.getChild("roads")); assertNotNull(root.getChild("roads/highways")); ex.expect(IllegalArgumentException.class); ex.expectMessage("No child named streets exists"); root.getChild("roads/streets"); }