Class PredicateUtil


  • public final class PredicateUtil
    extends Object
    Utility class for working with Predicate.
    • Method Detail

      • never

        public static <T> Predicate<T> never()
        A predicate that always returns false.
      • always

        public static <T> Predicate<T> always()
        A predicate that always returns true.
      • getFileExtensionFilter

        public static Predicate<String> getFileExtensionFilter​(String... extensions)
        Returns a case-insensitive predicate for files with the given extensions.
        Throws:
        NullPointerException - If the extensions array is null
      • toNormalizedFileFilter

        public static Predicate<String> toNormalizedFileFilter​(Predicate<? super String> filter)
        Returns a predicate that tests if the name of a file matches the given string filter. The returned predicate normalizes backslashes ('\') to '/' to be more easily cross-platform.
        Parameters:
        filter - A predicate on the file name
        Returns:
        A predicate on files
      • buildRegexFilterIncludeOverExclude

        public static Predicate<String> buildRegexFilterIncludeOverExclude​(@NonNull Collection<Pattern> includeRegexes,
                                                                           @NonNull Collection<Pattern> excludeRegexes)
        Builds a string filter using a set of include and exclude regular expressions. A string S matches the predicate if either
        • 1. no exclude regex matches S, or
        • 2. some include regex matches S
        In other words, include patterns override exclude patterns.
        Parameters:
        includeRegexes - Regular expressions overriding the excludes.
        excludeRegexes - Regular expressions filtering strings out.
        Returns:
        A predicate for strings.