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());
  }
Filter candidates - find all that match positive matches and do not match
any negative matches.

@param candidates       list of candidate strings. If null, return an empty list.
@param positivePatterns list of regexp that should all match. If null, everything matches.
@param negativePatterns list of regexp, none of these should match. If null, everything matches.
@return list of filtered results.
standalone-metastore/metastore-tools/tools-common/src/main/java/org/apache/hadoop/hive/metastore/tools/Util.java