### Question:
Util { public static List<String> filterMatches(@Nullable List<String> candidates, @Nullable Pattern[] positivePatterns, @Nullable Pattern[] negativePatterns) { if (candidates == null || candidates.isEmpty()) { return Collections.emptyList(); } final Pattern[] positive = (positivePatterns == null || positivePatterns.length == 0) ? MATCH_ALL_PATTERN : positivePatterns; final Pattern[] negative = negativePatterns == null ? EMPTY_PATTERN : negativePatterns; return candidates.stream() .filter(c -> Arrays.stream(positive).anyMatch(p -> p.matcher(c).matches())) .filter(c -> Arrays.stream(negative).noneMatch(p -> p.matcher(c).matches())) .collect(Collectors.toList()); } private  Util(); static T throwingSupplierWrapper(ThrowingSupplier<T, Exception> throwingSupplier); static List<FieldSchema> createSchema(@Nullable List<String> params); static @Nullable URI getServerUri(@Nullable String host, @Nullable String portString); static List<String> filterMatches(@Nullable List<String> candidates,
                                           @Nullable Pattern[] positivePatterns,
                                           @Nullable Pattern[] negativePatterns);  }### Answer:
@Test public void filterMatchesEmpty() { List<String> candidates = ImmutableList.of("foo", "bar"); assertThat(filterMatches(candidates, null, null), is(candidates)); assertThat(filterMatches(null, null, null), is(Collections.emptyList())); }
@Test public void filterMatchesPositive() { List<String> candidates = ImmutableList.of("foo", "bar"); List<String> expected = ImmutableList.of("foo"); assertThat(filterMatches(candidates, new Pattern[]{Pattern.compile("f.*")}, null), is(expected)); }
@Test public void filterMatchesNegative() { List<String> candidates = ImmutableList.of("a", "b"); List<String> expected = ImmutableList.of("a"); assertThat(filterMatches(candidates, null, new Pattern[]{Pattern.compile("b")}), is(expected)); }
@Test public void filterMatchesMultiple() { List<String> candidates = ImmutableList.of("a", "b", "any", "boom", "hello"); List<String> patterns = ImmutableList.of("^a", "!y$"); List<String> expected = ImmutableList.of("a"); assertThat(filterMatches(candidates, new Pattern[]{Pattern.compile("^a")}, new Pattern[]{Pattern.compile("y$")}), is(expected)); }