public PathFilter find(List<String> childPath) { Preconditions.checkState(children != null); Preconditions.checkArgument(!childPath.isEmpty()); final String root = childPath.get(0); Preconditions.checkArgument(name.equals(root)); if (1 == childPath.size()) { return this; } PathFilter childFilter = children.get(childPath.get(1)); Preconditions.checkArgument(childFilter != null); return childFilter.find(childPath.subList(1, childPath.size())); }
/** * 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; }