public PathFilteringDiffConsumer(List<String> pathFilters, PreOrderDiffWalk.Consumer delegate) { super(delegate); this.filter = new DiffPathFilter(pathFilters); }
/** * @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 parent, final String node) { List<String> path = toPath(parent, node); boolean applies = pathFilter.applies(path); return applies; } }
@Override public boolean tree(NodeRef left, NodeRef right) { String path = left == null ? right.path() : left.path(); if (filter.treeApplies(path)) { return super.tree(left, right); } return false; }
@Override public boolean feature(NodeRef left, NodeRef right) { String featurePath = left == null ? right.path() : left.path(); if (filter.featureApplies(featurePath)) { return super.feature(left, right); } return true; }
@Override public boolean bucket(NodeRef lparent, NodeRef rparent, BucketIndex bucketIndex, Bucket left, Bucket right) { String treePath = lparent == null ? rparent.path() : lparent.path(); if (filter.bucketApplies(treePath, bucketIndex)) { return super.bucket(lparent, rparent, bucketIndex, left, right); } return false; }
@Override public void endTree(NodeRef left, NodeRef right) { String path = left == null ? right.path() : left.path(); if (filter.treeApplies(path)) { super.endTree(left, right); } }
@Override public boolean feature(NodeRef left, NodeRef right) { String parent = left == null ? right.getParentPath() : left.getParentPath(); String node = left == null ? right.name() : left.name(); if (filter.featureApplies(parent, node)) { return super.feature(left, right); } return true; }
@Override public boolean bucket(NodeRef lparent, NodeRef rparent, BucketIndex bucketIndex, Bucket left, Bucket right) { String treePath = lparent == null ? rparent.path() : lparent.path(); if (filter.bucketApplies(treePath, bucketIndex)) { return super.bucket(lparent, rparent, bucketIndex, left, right); } return false; }
@Override public boolean tree(NodeRef left, NodeRef right) { String path = left == null ? right.path() : left.path(); if (filter.treeApplies(path)) { return super.tree(left, right); } return false; }
/** * Tests whether the given tree path applies to one of the path filters. * <p> * Given a path filer {@code roads/highway}, the following {@code treePaths}: * <ul> * <li>{@code roads]} applies * <li>{@code roads/highway]} applies * <li>{@code roads/secondary} does not apply * <li>{@code roads/highway/principal} applies * <li>{@code buildings[/**]} does not apply * </ul> * * @param treePath * @return {@code true} if {@code treePath} is a parent of, or equals to, one of the path * filters */ public boolean treeApplies(final String treePath) { boolean applies = pathFilter.applies(toPath(treePath, null)); return applies; }
public PathFilteringDiffConsumer(List<String> pathFilters, PreOrderDiffWalk.Consumer delegate) { super(delegate); this.filter = new DiffPathFilter(pathFilters); }
@Override public void endTree(NodeRef left, NodeRef right) { String path = left == null ? right.path() : left.path(); if (filter.treeApplies(path)) { super.endTree(left, right); } }
/** * If this method is called then {@link #treeApplies(String)} returned {@code true} for the pair * of trees the buckets belong to, meaning that {@code treePath} either matches exactly one of * the filters, or is a filter children. If the former, all tree buckets apply. If the later, * only the ones whose simple name * <ul> * <li>a filter refers to exactly the same tree than {@code treePath}, in which case all buckets * apply * <li>a filter is a child of {@code treePath}, in which case the bucket applies * </ul> * * @param treePath the path of the tree the bucket belong to * @param bucketIndex * @return */ public boolean bucketApplies(final String treePath, final BucketIndex bucketIndex) { // if we got here, then tree applies final PathFilter treeFilter = this.pathFilter.find(toPath(treePath, null)); if (treeFilter.children == null) { return true; } Map<String, PathFilter> childFilters = treeFilter.children; for (PathFilter childFilter : childFilters.values()) { if (childFilter.bucketApplies(bucketIndex)) { return true; } } return false; }