Class PredicateSupport

java.lang.Object
net.shibboleth.utilities.java.support.logic.PredicateSupport

public final class PredicateSupport
extends Object
Helper class for constructing predicates. Especially useful for creating internal DSLs via Java's static method import mechanism.
  • Constructor Details

    • PredicateSupport

      private PredicateSupport()
      Constructor.
  • Method Details

    • allMatch

      @Nonnull public static <T> Predicate<Iterable<T>> allMatch​(@Nonnull Predicate<T> target)
      Creates a predicate that checks that all elements of an Iterable matches a given target predicate.
      Type Parameters:
      T - type of objects in the iterable and that the target operates upon
      Parameters:
      target - predicate used to check each element in the iterable
      Returns:
      the constructed predicate
    • anyMatch

      @Nonnull public static <T> Predicate<Iterable<T>> anyMatch​(@Nonnull Predicate<T> target)
      Creates a predicate that checks that any element in an Iterable matches a given target predicate.
      Type Parameters:
      T - type of objects in the iterable and that the target operates upon
      Parameters:
      target - predicate used to check each element in the iterable
      Returns:
      the constructed predicate
    • caseInsensitiveMatch

      @Nonnull public static Predicate<CharSequence> caseInsensitiveMatch​(@Nonnull String target)
      Creates a predicate that checks if a given CharSequence matches a target string while ignoring case.
      Parameters:
      target - the target string to match against
      Returns:
      the constructed predicate
    • fromFunction

      @Nonnull public static <T> Predicate<T> fromFunction​(@Nonnull Function<T,​Boolean> function, @Nonnull Predicate<? super T> defValue)
      Creates a predicate that applies a function to an input and returns its result, or a default value if null.
      Type Parameters:
      T - type of function input
      Parameters:
      function - function to apply to input
      defValue - default predicate to apply if function returns null
      Returns:
      a predicate adapter
      Since:
      7.4.0
    • not

      @Nonnull public static <T> Predicate<T> not​(@Nonnull Predicate<? super T> predicate)
      Returns a predicate that evaluates to true if the given predicate evaluates to false.
      Type Parameters:
      T - predicate input type
      Parameters:
      predicate - the predicate to negate
      Returns:
      the negated predicate
    • and

      @Nonnull public static <T> Predicate<T> and​(@Nonnull Iterable<? extends Predicate<? super T>> components)
      Returns a predicate that evaluates to true if each of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to true.
      Type Parameters:
      T - predicate input type
      Parameters:
      components - the predicates to combine
      Returns:
      the composite predicate
    • and

      @SafeVarargs @Nonnull public static <T> Predicate<T> and​(@Nonnull Predicate<? super T>... components)
      Returns a predicate that evaluates to true if each of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to true.
      Type Parameters:
      T - predicate input type
      Parameters:
      components - the predicates to combine
      Returns:
      the composite predicate
    • and

      @Nonnull public static <T> Predicate<T> and​(@Nonnull Predicate<? super T> first, @Nonnull Predicate<? super T> second)
      Returns a predicate that evaluates to true if each of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to true.
      Type Parameters:
      T - predicate input type
      Parameters:
      first - the first predicate
      second - the second predicate
      Returns:
      the composite predicate
    • or

      @Nonnull public static <T> Predicate<T> or​(@Nonnull Iterable<? extends Predicate<? super T>> components)
      Returns a predicate that evaluates to true if any one of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to false.
      Type Parameters:
      T - predicate input type
      Parameters:
      components - the predicates to combine
      Returns:
      the composite predicate
    • or

      @SafeVarargs @Nonnull public static <T> Predicate<T> or​(@Nonnull Predicate<? super T>... components)
      Returns a predicate that evaluates to true if any one of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to false.
      Type Parameters:
      T - predicate input type
      Parameters:
      components - the predicates to combine
      Returns:
      the composite predicate
    • or

      @Nonnull public static <T> Predicate<T> or​(@Nonnull Predicate<? super T> first, @Nonnull Predicate<? super T> second)
      Returns a predicate that evaluates to true if any one of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to false.
      Type Parameters:
      T - predicate input type
      Parameters:
      first - the first predicate
      second - the second predicate
      Returns:
      the composite predicate