@Test public void testBasic() { FileFilter filter1 = new FileFilter(FileFilter.MATCH_ALL, FileFilter.INCLUDE, true); FileFilter filter2 = new FileFilter(FileFilter.MATCH_ALL, FileFilter.INCLUDE, true); FileFilter filter3 = new FileFilter(FileFilter.MATCH_ALL, FileFilter.INCLUDE, true); FileFilter filter4 = new FileFilter(FileFilter.MATCH_ALL, FileFilter.INCLUDE, true); Map<String, FileFilter> filters = new TreeMap<>(); filters.put("./a/c", filter1); filters.put("./b/e", filter2); filters.put("./a/c/d", filter3); filters.put("./a/c/d/g", filter4); FileFilterTree tree = new FileFilterTree(filters); assertNull(tree.getFilter("./a")); assertNull(tree.getFilter("./a/f")); assertNull(tree.getFilter("./a/c")); assertNull(tree.getFilter("./b/e")); assertNull(tree.getFilter("./b/e/")); assertEquals(filter1, tree.getFilter("./a/c/d")); assertEquals(filter3, tree.getFilter("./a/c/d/file.txt")); assertEquals(filter3, tree.getFilter("./a/c/d/subdir")); assertEquals(filter3, tree.getFilter("./a/c/d/g")); assertEquals(filter3, tree.getFilter("./a/c/d/g/")); assertEquals(filter4, tree.getFilter("./a/c/d/g/file.txt")); assertEquals(filter2, tree.getFilter("./b/e/subdir/file.txt")); }
public FileFilter getFilter(String key) { FileFilter filter = null; FileFilter parentFilter = null; StringTokenizer tokenizer = new StringTokenizer(key, FILE_SEPARATOR); FileFilterTreeItem item = root; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); parentFilter = filter; FileFilterTreeItem children = item.getChildren(token); if (null == children) { return parentFilter; } FileFilter childFilter = children.getFilter(); if (null != childFilter) { filter = childFilter; } item = children; } return parentFilter; }
FileFilterTree { public FileFilter getFilter(String key) { FileFilter filter = null; FileFilter parentFilter = null; StringTokenizer tokenizer = new StringTokenizer(key, FILE_SEPARATOR); FileFilterTreeItem item = root; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); parentFilter = filter; FileFilterTreeItem children = item.getChildren(token); if (null == children) { return parentFilter; } FileFilter childFilter = children.getFilter(); if (null != childFilter) { filter = childFilter; } item = children; } return parentFilter; } }
FileFilterTree { public FileFilter getFilter(String key) { FileFilter filter = null; FileFilter parentFilter = null; StringTokenizer tokenizer = new StringTokenizer(key, FILE_SEPARATOR); FileFilterTreeItem item = root; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); parentFilter = filter; FileFilterTreeItem children = item.getChildren(token); if (null == children) { return parentFilter; } FileFilter childFilter = children.getFilter(); if (null != childFilter) { filter = childFilter; } item = children; } return parentFilter; } FileFilterTree(Map<String, FileFilter> filters); }
FileFilterTree { public FileFilter getFilter(String key) { FileFilter filter = null; FileFilter parentFilter = null; StringTokenizer tokenizer = new StringTokenizer(key, FILE_SEPARATOR); FileFilterTreeItem item = root; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); parentFilter = filter; FileFilterTreeItem children = item.getChildren(token); if (null == children) { return parentFilter; } FileFilter childFilter = children.getFilter(); if (null != childFilter) { filter = childFilter; } item = children; } return parentFilter; } FileFilterTree(Map<String, FileFilter> filters); FileFilter getFilter(String key); Stream<Map.Entry<String, FileFilter>> stream(); @Override String toString(); }
FileFilterTree { public FileFilter getFilter(String key) { FileFilter filter = null; FileFilter parentFilter = null; StringTokenizer tokenizer = new StringTokenizer(key, FILE_SEPARATOR); FileFilterTreeItem item = root; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); parentFilter = filter; FileFilterTreeItem children = item.getChildren(token); if (null == children) { return parentFilter; } FileFilter childFilter = children.getFilter(); if (null != childFilter) { filter = childFilter; } item = children; } return parentFilter; } FileFilterTree(Map<String, FileFilter> filters); FileFilter getFilter(String key); Stream<Map.Entry<String, FileFilter>> stream(); @Override String toString();  }