public void setChild(String parentPath, Node node) { List<String> parentSteps = split(parentPath); setChild(parentSteps, node); }
public void setChild(String parentPath, Node node) { List<String> parentSteps = split(parentPath); setChild(parentSteps, node); }
private void handlePureMetadataChanges(TreeDifference treeDifference, Set<String> ignoreList) { Map<NodeRef, NodeRef> pureMetadataChanges = treeDifference.findPureMetadataChanges(); for (Map.Entry<NodeRef, NodeRef> e : pureMetadataChanges.entrySet()) { NodeRef newValue = e.getValue(); String treePath = newValue.path(); if (ignoreList.contains(treePath)) { continue; } ignoreList.add(treePath); if (!filterMatchesOrIsParent(treePath)) { continue;// filter doesn't apply to the changed tree } MutableTree leftTree = treeDifference.getLeftTree(); leftTree.setChild(newValue.getParentPath(), newValue.getNode()); } }
private void handlePureMetadataChanges(TreeDifference treeDifference, Set<String> ignoreList) { Map<NodeRef, NodeRef> pureMetadataChanges = treeDifference.findPureMetadataChanges(); for (Map.Entry<NodeRef, NodeRef> e : pureMetadataChanges.entrySet()) { NodeRef newValue = e.getValue(); String treePath = newValue.path(); if (ignoreList.contains(treePath)) { continue; } ignoreList.add(treePath); if (!filterMatchesOrIsParent(treePath)) { continue;// filter doesn't apply to the changed tree } MutableTree leftTree = treeDifference.getLeftTree(); 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()); } }
/** * 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()); } }
public static MutableTree createFromPaths(final ObjectId rootId, final Map<String, NodeRef> entries) { List<NodeRef> refsByDepth = Lists.newArrayList(entries.values()); Collections.sort(refsByDepth, DEEPEST_LAST_COMPARATOR); Node rootNode = Node.create(ROOT, rootId, ObjectId.NULL, TYPE.TREE, null); MutableTree root = new MutableTree(rootNode); Envelope bounds = new Envelope(); for (NodeRef entry : refsByDepth) { Node node = entry.getNode(); node.expand(bounds); String parentPath = entry.getParentPath(); root.setChild(parentPath, node); } // recreate root node with the appropriate bounds rootNode = Node.create(ROOT, rootId, ObjectId.NULL, TYPE.TREE, bounds); root.setNode(rootNode); return root; }
public static MutableTree createFromPaths(final ObjectId rootId, final Map<String, NodeRef> entries) { List<NodeRef> refsByDepth = Lists.newArrayList(entries.values()); Collections.sort(refsByDepth, DEEPEST_LAST_COMPARATOR); Node rootNode = RevObjectFactory.defaultInstance().createNode(ROOT, rootId, ObjectId.NULL, TYPE.TREE, null, null); MutableTree root = new MutableTree(rootNode); Envelope bounds = new Envelope(); for (NodeRef entry : refsByDepth) { Node node = entry.getNode(); node.expand(bounds); String parentPath = entry.getParentPath(); root.setChild(parentPath, node); } // recreate root node with the appropriate bounds rootNode = RevObjectFactory.defaultInstance().createNode(ROOT, rootId, ObjectId.NULL, TYPE.TREE, bounds, null); root.setNode(rootNode); return root; }
private void handleRemainingDifferences(TreeDifference treeDifference, Set<String> ignoreList) { // old/new refs to trees that have changed and apply to the pathFilters, deepest paths first final SortedMap<NodeRef, NodeRef> changedTrees = treeDifference.findChanges(); final SortedMap<NodeRef, NodeRef> filteredChangedTrees = changedTrees;// filterChanges(changedTrees); for (Map.Entry<NodeRef, NodeRef> changedTreeRefs : filteredChangedTrees.entrySet()) { NodeRef leftTreeRef = changedTreeRefs.getKey(); NodeRef rightTreeRef = changedTreeRefs.getValue(); String newPath = rightTreeRef.path(); if (ignoreList.contains(newPath)) { continue; } if (!filterApplies(newPath, treeDifference.getRightTree())) { continue; } ignoreList.add(newPath); RevTree tree = applyChanges(leftTreeRef, rightTreeRef); Envelope bounds = SpatialOps.boundsOf(tree); Node newTreeNode = RevObjectFactory.defaultInstance().createNode(rightTreeRef.name(), tree.getId(), rightTreeRef.getMetadataId(), TYPE.TREE, bounds, null); MutableTree leftRoot = treeDifference.getLeftTree(); String parentPath = rightTreeRef.getParentPath(); leftRoot.setChild(parentPath, newTreeNode); } }
private void handleRemainingDifferences(TreeDifference treeDifference, Set<String> ignoreList) { // old/new refs to trees that have changed and apply to the pathFilters, deepest paths first final SortedMap<NodeRef, NodeRef> changedTrees = treeDifference.findChanges(); final SortedMap<NodeRef, NodeRef> filteredChangedTrees = changedTrees;// filterChanges(changedTrees); for (Map.Entry<NodeRef, NodeRef> changedTreeRefs : filteredChangedTrees.entrySet()) { NodeRef leftTreeRef = changedTreeRefs.getKey(); NodeRef rightTreeRef = changedTreeRefs.getValue(); String newPath = rightTreeRef.path(); if (ignoreList.contains(newPath)) { continue; } if (!filterApplies(newPath, treeDifference.getRightTree())) { continue; } ignoreList.add(newPath); RevTree tree = applyChanges(leftTreeRef, rightTreeRef); Envelope bounds = SpatialOps.boundsOf(tree); Node newTreeNode = Node.create(rightTreeRef.name(), tree.getId(), rightTreeRef.getMetadataId(), TYPE.TREE, bounds); MutableTree leftRoot = treeDifference.getLeftTree(); String parentPath = rightTreeRef.getParentPath(); leftRoot.setChild(parentPath, newTreeNode); } }
private void handleNewTrees(TreeDifference treeDifference, Set<String> ignoreList) { SortedSet<NodeRef> newTrees = treeDifference.findNewTrees(); for (NodeRef ref : newTrees) { final String path = ref.path(); if (ignoreList.contains(path)) { continue; } ignoreList.add(path); if (!filterMatchesOrIsParent(path)) { MutableTree rightTree = treeDifference.getRightTree(); if (filterApplies(path, rightTree)) { // can't optimize RevTree newTree = applyChanges(null, ref); Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId()); MutableTree leftTree = treeDifference.getLeftTree(); leftTree.forceChild(ref.getParentPath(), newNode); } } else { LOGGER.trace("Creating new tree {}", path); MutableTree leftTree = treeDifference.getLeftTree(); String parentPath = ref.getParentPath(); Node node = ref.getNode(); leftTree.setChild(parentPath, node); } } }
private void handleNewTrees(TreeDifference treeDifference, Set<String> ignoreList) { SortedSet<NodeRef> newTrees = treeDifference.findNewTrees(); for (NodeRef ref : newTrees) { final String path = ref.path(); if (ignoreList.contains(path)) { continue; } ignoreList.add(path); if (!filterMatchesOrIsParent(path)) { MutableTree rightTree = treeDifference.getRightTree(); if (filterApplies(path, rightTree)) { // can't optimize RevTree newTree = applyChanges(null, ref); 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 { LOGGER.trace("Creating new tree {}", path); MutableTree leftTree = treeDifference.getLeftTree(); String parentPath = ref.getParentPath(); Node node = ref.getNode(); leftTree.setChild(parentPath, node); } } }
@Test public void testSet() { Node node = treeNode("roads", id("a11"), id("d1")); root.setChild("", node); assertEquals(node, root.getChild("roads").getNode()); node = treeNode("stores", id("a51"), id("d3")); root.setChild("buildings", node); assertEquals(node, root.getChild("buildings/stores").getNode()); }
@Test public void testSet() { Node node = treeNode("roads", id("a11"), id("d1")); root.setChild("", node); assertEquals(node, root.getChild("roads").getNode()); node = treeNode("stores", id("a51"), id("d3")); root.setChild("buildings", node); assertEquals(node, root.getChild("buildings/stores").getNode()); }