RuleFilter { public Set<String> match(Iterable<String> rules, String filter) { Set<String> matches = new HashSet<>(); if (filter != null) { List<String> rulePatterns = asList(filter.split("\\s*,\\s*")); List<String> includePatterns = rulePatterns.stream().filter(pattern -> !pattern.startsWith("!")).collect(toList()); List<String> excludePatterns = rulePatterns.stream().filter(pattern -> pattern.startsWith("!")).map(pattern -> pattern.substring(1)) .collect(toList()); apply(rules, includePatterns, rule -> matches.add(rule)); apply(rules, excludePatterns, rule -> matches.remove(rule)); } return matches; } private  RuleFilter(); static RuleFilter getInstance(); Set<String> match(Iterable<String> rules, String filter); boolean matches(String rule, String pattern);  }
@Test public void negation() { Set<String> rules = new HashSet<>(); rules.add("foo"); rules.add("bar"); Set<String> result = ruleFilter.match(rules, "*, !b*r"); assertThat(result).containsExactly("foo"); }
@Test public void filter() { Set<String> rules = new HashSet<>(); rules.add("foo"); rules.add("bar"); rules.add("wildcard"); Set<String> result = ruleFilter.match(rules, "foo, w?ldc*d"); assertThat(result).containsOnly("foo", "wildcard"); }