private boolean filterMatchesOrIsParent(final String treePath) { if (pathFilters.isEmpty()) { return true; } for (String filter : pathFilters) { if (filter.equals(treePath)) { return true; } boolean treeIsChildOfFilter = NodeRef.isChild(filter, treePath); if (treeIsChildOfFilter) { return true; } } return false; }
private boolean filterMatchesOrIsParent(final String treePath) { if (pathFilters.isEmpty()) { return true; } for (String filter : pathFilters) { if (filter.equals(treePath)) { return true; } boolean treeIsChildOfFilter = NodeRef.isChild(filter, treePath); if (treeIsChildOfFilter) { return true; } } return false; }
/** * @return a new list out of the filters in pathFilters that apply to the given path (are equal * or a parent of), with their own parents stripped to that they apply directly to the * node names in the tree */ private Set<String> stripParentAndFiltersThatDontApply(Set<String> pathFilters, final String treePath) { Set<String> parentsStripped = new TreeSet<>(); for (String filter : pathFilters) { if (filter.equals(treePath)) { continue;// include all diffs in the tree addressed by treePath } boolean pathIsChildOfFilter = NodeRef.isChild(filter, treePath); if (pathIsChildOfFilter) { continue;// include all diffs in this path } boolean filterIsChildOfTree = NodeRef.isChild(treePath, filter); if (filterIsChildOfTree) { String filterFromPath = NodeRef.removeParent(treePath, filter); parentsStripped.add(filterFromPath); } } return parentsStripped; }
/** * @return a new list out of the filters in pathFilters that apply to the given path (are equal * or a parent of), with their own parents stripped to that they apply directly to the * node names in the tree */ private Set<String> stripParentAndFiltersThatDontApply(Set<String> pathFilters, final String treePath) { Set<String> parentsStripped = new TreeSet<>(); for (String filter : pathFilters) { if (filter.equals(treePath)) { continue;// include all diffs in the tree addressed by treePath } boolean pathIsChildOfFilter = NodeRef.isChild(filter, treePath); if (pathIsChildOfFilter) { continue;// include all diffs in this path } boolean filterIsChildOfTree = NodeRef.isChild(treePath, filter); if (filterIsChildOfTree) { String filterFromPath = NodeRef.removeParent(treePath, filter); parentsStripped.add(filterFromPath); } } return parentsStripped; }
/** * @param featurePath path o a feature node (e.g. {@code 'roads/road1'} * @return {@code true} if {@code featurePath} is a child of, or equals to, one of the path * filters. */ public boolean featureApplies(final String featurePath) { String filter; boolean applies = false; for (int i = 0; i < pathFilters.size(); i++) { filter = pathFilters.get(i); if (filter.equals(featurePath)) { applies = true; } else if (NodeRef.isChild(filter, featurePath)) { applies = true; } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Filter: '{}', feature: '{}', applies: {}", filter, featurePath, applies); } if (applies) { return true; } } return false; } }
applies = true; } else { boolean filterIsChildOfTree = NodeRef.isChild(treePath, filter); if (filterIsChildOfTree) { applies = true;
/** * Remove the parent path from the given child path. * * @param parentPath the parent path to remove * @param childPath the child path to remove from * @return the stripped child path */ public static String removeParent(final String parentPath, final String childPath) { checkArgument(isChild(parentPath, childPath)); List<String> parent = split(parentPath); List<String> child = split(childPath); child = child.subList(parent.size(), child.size()); String strippedChildPath = child.get(0); for (int i = 1; i < child.size(); i++) { strippedChildPath = appendChild(strippedChildPath, child.get(i)); } return strippedChildPath; }
/** * Remove the parent path from the given child path. * * @param parentPath the parent path to remove * @param childPath the child path to remove from * @return the stripped child path */ public static String removeParent(final String parentPath, final String childPath) { checkArgument(isChild(parentPath, childPath)); ImmutableList<String> parent = split(parentPath); ImmutableList<String> child = split(childPath); child = child.subList(parent.size(), child.size()); String strippedChildPath = child.get(0); for (int i = 1; i < child.size(); i++) { strippedChildPath = appendChild(strippedChildPath, child.get(i)); } return strippedChildPath; }
boolean filterIsChildOfTree = NodeRef.isChild(treePath, filter); if (filterIsChildOfTree) { ImmutableList<String> filterSteps = NodeRef.split(filter);
/** * Test method for {@link org.locationtech.geogig.model.Node#isChild(String, String)} */ @Test public void testIsChild() { assertFalse(isChild("", "")); assertTrue(isChild("", "path")); assertTrue(isChild("", "path/to")); assertFalse(isChild("path", "path")); assertFalse(isChild("path", "")); assertTrue(isChild("path", "path/to")); assertTrue(isChild("path", "path/to/node")); assertFalse(isChild("path/to", "")); assertFalse(isChild("path/to", "path")); assertFalse(isChild("path/to", "path/to")); assertFalse(isChild("path/to", "path2/to")); assertTrue(isChild("path/to", "path/to/node")); }
@Override public int compare(DiffEntry left, DiffEntry right) { final NodeRef nodeRef1 = left.oldObject().or(left.newObject()).get(); final NodeRef nodeRef2 = right.oldObject().or(right.newObject()).get(); if (nodeRef1.getType().equals(nodeRef2.getType())) { return CanonicalNodeOrder.INSTANCE.compare(nodeRef1.getNode(), nodeRef2.getNode()); } // one is a tree, the other a feature. // the tree comes first if it's a feature's parent boolean leftIsRightsParent = NodeRef.isChild(nodeRef1.path()/* parent */, nodeRef2.path()/* child */); if (leftIsRightsParent) { return -1; } boolean rightIsLeftsParent = NodeRef.isDirectChild(nodeRef2.path()/* parent */, nodeRef1.path()/* child */); if (rightIsLeftsParent) { return 1; } // feature wins (got a new tree on one end while all features of the previous tree // haven't been consumed) return nodeRef1.getType() == TYPE.FEATURE ? -1 : 1; } };
@Override public int compare(DiffEntry left, DiffEntry right) { final NodeRef nodeRef1 = left.oldObject().or(left.newObject()).get(); final NodeRef nodeRef2 = right.oldObject().or(right.newObject()).get(); if (nodeRef1.getType().equals(nodeRef2.getType())) { return CanonicalNodeOrder.INSTANCE.compare(nodeRef1.getNode(), nodeRef2.getNode()); } // one is a tree, the other a feature. // the tree comes first if it's a feature's parent boolean leftIsRightsParent = NodeRef.isChild(nodeRef1.path()/* parent */, nodeRef2.path()/* child */); if (leftIsRightsParent) { return -1; } boolean rightIsLeftsParent = NodeRef.isDirectChild(nodeRef2.path()/* parent */, nodeRef1.path()/* child */); if (rightIsLeftsParent) { return 1; } // feature wins (got a new tree on one end while all features of the previous tree // haven't been consumed) return nodeRef1.getType() == TYPE.FEATURE ? -1 : 1; } };