Make RegexFilter implement Predicate<String>.
@@ -22,6 +22,7 @@ import com.google.devtools.common.options.OptionsParsingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.annotation.Nullable;
@@ -35,7 +36,7 @@ import javax.annotation.Nullable;
*/
@AutoCodec
@Immutable
-public final class RegexFilter {
+public final class RegexFilter implements Predicate<String> {
// Null inclusion or exclusion pattern means those patterns are not used.
@Nullable private final Pattern inclusionPattern;
@Nullable private final Pattern exclusionPattern;
@@ -130,6 +131,11 @@ public final class RegexFilter {
return inclusionPattern.matcher(value).find();
}
+ @Override
+ public boolean test(String value) {
+ return isIncluded(value);
+ }
+
@Nullable
public String getInclusionRegex() {
return inclusionPattern == null ? null : inclusionPattern.pattern();
