PathFilter { public Result filter(@NotNull String path) { for (String excludedPath : excludedPaths) { if (excludedPath.equals(path) || isAncestor(excludedPath, path)) { return Result.EXCLUDE; } } for (String includedPath : includedPaths) { if (includedPath.equals(path) || isAncestor(includedPath, path)) { return Result.INCLUDE; } } for (String includedPath : includedPaths) { if (isAncestor(path, includedPath)) { return Result.TRAVERSE; } } return Result.EXCLUDE; } PathFilter(Iterable<String> includes, Iterable<String> excludes); static PathFilter from(@NotNull NodeBuilder defn); Result filter(@NotNull String path); @Override String toString(); boolean areAllDescendantsIncluded(String path); static final String PROP_INCLUDED_PATHS; static final String PROP_EXCLUDED_PATHS; }
@Test public void exclude() throws Exception { PathFilter p = new PathFilter(of("/"), of("/etc")); assertEquals(PathFilter.Result.INCLUDE, p.filter("/")); assertEquals(PathFilter.Result.INCLUDE, p.filter("/a")); assertEquals(PathFilter.Result.EXCLUDE, p.filter("/etc")); assertEquals(PathFilter.Result.EXCLUDE, p.filter("/etc/workflow")); }
@Test public void include() throws Exception { PathFilter p = new PathFilter(of("/content", "/etc"), of("/etc/workflow/instance")); assertEquals(PathFilter.Result.TRAVERSE, p.filter("/")); assertEquals(PathFilter.Result.EXCLUDE, p.filter("/var")); assertEquals(PathFilter.Result.INCLUDE, p.filter("/content")); assertEquals(PathFilter.Result.INCLUDE, p.filter("/content/example")); assertEquals(PathFilter.Result.INCLUDE, p.filter("/etc")); assertEquals(PathFilter.Result.INCLUDE, p.filter("/etc/workflow")); assertEquals(PathFilter.Result.EXCLUDE, p.filter("/etc/workflow/instance")); assertEquals(PathFilter.Result.EXCLUDE, p.filter("/etc/workflow/instance/1")); assertEquals(PathFilter.Result.EXCLUDE, p.filter("/x")); assertEquals(PathFilter.Result.EXCLUDE, p.filter("/e")); assertEquals(PathFilter.Result.EXCLUDE, p.filter("/etcx")); }