Class Predicates


  • public class Predicates
    extends Object
    Utilities for constructing various predicates.
    Author:
    Randall Hauch
    • Field Detail

      • LITERAL_SEPARATOR_PATTERN

        private static final Pattern LITERAL_SEPARATOR_PATTERN
    • Constructor Detail

      • Predicates

        private Predicates()
    • Method Detail

      • includesUuids

        public static Predicate<String> includesUuids​(String uuidPatterns)
        Generate a predicate function that for any supplied UUID strings returns true if any of the comma-separated UUID literals or regular expressions matches the predicate parameter. This supplied strings can be a mixture of regular expressions and UUID literals, and the most efficient method will be used for each.
        Parameters:
        uuidPatterns - the comma-separated UUID literals or regular expression patterns; may not be null
        Returns:
        the predicate function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • excludesUuids

        public static Predicate<String> excludesUuids​(String uuidPatterns)
        Generate a predicate function that for any supplied string returns true if none of the regular expressions or literals in the supplied comma-separated list matches the predicate parameter. This supplied strings can be a mixture of regular expressions and UUID literals, and the most efficient method will be used for each.
        Parameters:
        uuidPatterns - the comma-separated regular expression pattern (or literal) strings; may not be null
        Returns:
        the predicate function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • includesLiteralsOrPatterns

        public static <T> Predicate<T> includesLiteralsOrPatterns​(String literalsOrPatterns,
                                                                  Predicate<String> isLiteral,
                                                                  Function<T,​String> conversion)
        Generate a predicate function that for any supplied string returns true if any of the regular expressions or literals in the supplied comma-separated list matches the predicate parameter. This supplied strings can be a mixture of regular expressions and literals, and the most efficient method will be used for each.
        Parameters:
        literalsOrPatterns - the comma-separated regular expression pattern (or literal) strings; may not be null
        isLiteral - function that determines if a given pattern is a literal string; may not be null
        conversion - the function that converts each predicate-supplied value to a string that can be matched against the regular expressions; may not be null
        Returns:
        the predicate function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • excludesLiteralsOrPatterns

        public static <T> Predicate<T> excludesLiteralsOrPatterns​(String patterns,
                                                                  Predicate<String> isLiteral,
                                                                  Function<T,​String> conversion)
        Generate a predicate function that for any supplied string returns true if none of the regular expressions or literals in the supplied comma-separated list matches the predicate parameter. This supplied strings can be a mixture of regular expressions and literals, and the most efficient method will be used for each.
        Parameters:
        patterns - the comma-separated regular expression pattern (or literal) strings; may not be null
        isLiteral - function that determines if a given pattern is a literal string; may not be null
        conversion - the function that converts each predicate-supplied value to a string that can be matched against the regular expressions; may not be null
        Returns:
        the predicate function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • includesLiterals

        public static Predicate<String> includesLiterals​(String literals)
        Generate a predicate function that for any supplied string returns true if any of the literals in the supplied comma-separated list case insensitively matches the predicate parameter.
        Parameters:
        literals - the comma-separated literal strings; may not be null
        Returns:
        the predicate function that performs the matching
      • excludesLiterals

        public static Predicate<String> excludesLiterals​(String literals)
        Generate a predicate function that for any supplied string returns true if none of the literals in the supplied comma-separated list case insensitively matches the predicate parameter.
        Parameters:
        literals - the comma-separated literal strings; may not be null
        Returns:
        the predicate function that performs the matching
      • includesLiterals

        public static <T> Predicate<T> includesLiterals​(String literals,
                                                        Function<T,​String> conversion)
        Generate a predicate function that for any supplied string returns true if any of the literals in the supplied comma-separated list case insensitively matches the predicate parameter.
        Parameters:
        literals - the comma-separated literal strings; may not be null
        conversion - the function that converts each predicate-supplied value to a string that can be matched against the regular expressions; may not be null
        Returns:
        the predicate function that performs the matching
      • excludesLiterals

        public static <T> Predicate<T> excludesLiterals​(String literals,
                                                        Function<T,​String> conversion)
        Generate a predicate function that for any supplied string returns true if none of the literals in the supplied comma-separated list case insensitively matches the predicate parameter.
        Parameters:
        literals - the comma-separated literal strings; may not be null
        conversion - the function that converts each predicate-supplied value to a string that can be matched against the regular expressions; may not be null
        Returns:
        the predicate function that performs the matching
      • includes

        public static Predicate<String> includes​(String regexPatterns)
        Generate a predicate function that for any supplied string returns true if any of the regular expressions in the supplied comma-separated list matches the predicate parameter.
        Parameters:
        regexPatterns - the comma-separated regular expression pattern (or literal) strings; may not be null
        Returns:
        the predicate function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • excludes

        public static Predicate<String> excludes​(String regexPatterns)
        Generate a predicate function that for any supplied string returns true if none of the regular expressions in the supplied comma-separated list matches the predicate parameter.
        Parameters:
        regexPatterns - the comma-separated regular expression pattern (or literal) strings; may not be null
        Returns:
        the predicate function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • includes

        public static <T> Predicate<T> includes​(String regexPatterns,
                                                Function<T,​String> conversion)
        Generate a predicate function that for any supplied parameter returns true if any of the regular expressions in the supplied comma-separated list matches the predicate parameter in a case-insensitive manner.
        Parameters:
        regexPatterns - the comma-separated regular expression pattern (or literal) strings; may not be null
        conversion - the function that converts each predicate-supplied value to a string that can be matched against the regular expressions; may not be null
        Returns:
        the predicate function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • matchedBy

        public static Function<String,​Optional<Pattern>> matchedBy​(String regexPatterns)
        Generate a predicate function that for any supplied string returns a Pattern representing the first regular expression in the supplied comma-separated list that matches the predicate parameter in a case-insensitive manner.
        Parameters:
        regexPatterns - the comma-separated regular expression pattern (or literal) strings; may not be null
        Returns:
        the function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • excludes

        public static <T> Predicate<T> excludes​(String regexPatterns,
                                                Function<T,​String> conversion)
        Generate a predicate function that for any supplied parameter returns true if none of the regular expressions in the supplied comma-separated list matches the predicate parameter.
        Parameters:
        regexPatterns - the comma-separated regular expression pattern (or literal) strings; may not be null
        conversion - the function that converts each predicate-supplied value to a string that can be matched against the regular expressions; may not be null
        Returns:
        the predicate function that performs the matching
        Throws:
        PatternSyntaxException - if the string includes an invalid regular expression
      • filter

        public static <T> Predicate<T> filter​(Predicate<T> allowed,
                                              Predicate<T> disallowed)
        Create a predicate function that allows only those values are allowed or not disallowed by the supplied predicates.
        Parameters:
        allowed - the predicate that defines the allowed values; may be null
        disallowed - the predicate that defines the disallowed values; may be null
        Returns:
        the predicate function; never null
      • notNull

        public static <T> Predicate<T> notNull()