Interface OptionalPredicate<T>

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface OptionalPredicate<T>
A predicate that can return success, failure, or undetermined.
  • Method Summary

    Modifier and Type
    Method
    Description
    default @NotNull OptionalPredicate<T>
    and(@NotNull OptionalPredicate<T> other)
    Performs the logical AND on two optional predicates, such that: - if both sides are empty, the result is empty - if one side is empty, the result is the other side - if both sides are non-empty, the result is the logical AND - if the left side is false, the right side is not evaluated (short circuit)
    default @NotNull OptionalPredicate<T>
    combine(@NotNull OptionalPredicate<T> other)
    If this predicate fails to produce a result, tries the next one instead.
    static <X> Optional<X>
    combine(@NotNull Optional<X> a, @NotNull Supplier<Optional<X>> b)
    Combines two optional values, with short-circuiting.
    static <T> @NotNull OptionalPredicate<T>
    A predicate that always returns empty.
    static <T> @NotNull OptionalPredicate<T>
    failIf(@NotNull Predicate<T> predicate)
    Convert the given predicate into an optional failure.
    default @NotNull OptionalPredicate<T>
    Negates the predicate -- where the original returns true, this returns false, and vice versa.
    static <T> @NotNull OptionalPredicate<T>
    of(@NotNull Predicate<T> predicate)
    Creates a non-empty optional predicate.
    default @NotNull OptionalPredicate<T>
    or(@NotNull OptionalPredicate<T> other)
    Performs the logical OR on two optional predicates, such that: - if both sides are empty, the result is empty - if one side is empty, the result is the other side - if both sides are non-empty, the result is the logical OR - if the left side is true, the right side is not evaluated (short circuit)
    default @NotNull Predicate<T>
    orElse(boolean fallback)
    Turns an OptionalPredicate into a regular Predicate by providing a default value returned when empty.
    static <T> @NotNull OptionalPredicate<T>
    passIf(@NotNull Predicate<T> predicate)
    Convert the given predicate into an optional success.
    @NotNull Optional<Boolean>
    test(T t)
    Evaluates this predicate on the given argument.
  • Method Details

    • test

      @NotNull @NotNull Optional<Boolean> test(T t)
      Evaluates this predicate on the given argument.
      Parameters:
      t - the input argument
      Returns:
      true, false, or empty
    • empty

      @NotNull static <T> @NotNull OptionalPredicate<T> empty()
      A predicate that always returns empty.
      Type Parameters:
      T - the input type
      Returns:
      empty
    • of

      @NotNull static <T> @NotNull OptionalPredicate<T> of(@NotNull @NotNull Predicate<T> predicate)
      Creates a non-empty optional predicate.
      Type Parameters:
      T - the input type
      Parameters:
      predicate - the input predicate
      Returns:
      a non-empty optional predicate
    • passIf

      @NotNull static <T> @NotNull OptionalPredicate<T> passIf(@NotNull @NotNull Predicate<T> predicate)
      Convert the given predicate into an optional success.
      Type Parameters:
      T - the input type
      Parameters:
      predicate - the input predicate
      Returns:
      a predicate which returns true if the input predicate returns true, or empty if the input predicate returns false.
    • failIf

      @NotNull static <T> @NotNull OptionalPredicate<T> failIf(@NotNull @NotNull Predicate<T> predicate)
      Convert the given predicate into an optional failure.
      Type Parameters:
      T - the input type
      Parameters:
      predicate - the input predicate
      Returns:
      a predicate which returns false if the input predicate returns true, or empty if the input predicate returns false.
    • orElse

      @NotNull default @NotNull Predicate<T> orElse(boolean fallback)
      Turns an OptionalPredicate into a regular Predicate by providing a default value returned when empty.
      Parameters:
      fallback - the value to return when empty
      Returns:
      a predicate that returns the original or fallback result
    • combine

      @NotNull default @NotNull OptionalPredicate<T> combine(@NotNull @NotNull OptionalPredicate<T> other)
      If this predicate fails to produce a result, tries the next one instead.
      Parameters:
      other - the other predicate to try
      Returns:
      the result from this predicate, or the result of the other if this returns empty
    • combine

      static <X> Optional<X> combine(@NotNull @NotNull Optional<X> a, @NotNull @NotNull Supplier<Optional<X>> b)
      Combines two optional values, with short-circuiting. Similar to Optional.orElseGet(Supplier) except that the final result may still be empty.
      Type Parameters:
      X - the value type
      Parameters:
      a - the first optional value
      b - a supplier to calculate the second optional value
      Returns:
      the first value, if present; otherwise calculates and returns the second value
    • negate

      @NotNull default @NotNull OptionalPredicate<T> negate()
      Negates the predicate -- where the original returns true, this returns false, and vice versa. The empty result does not change.
      Returns:
      the negated predicate.
    • and

      @NotNull default @NotNull OptionalPredicate<T> and(@NotNull @NotNull OptionalPredicate<T> other)
      Performs the logical AND on two optional predicates, such that: - if both sides are empty, the result is empty - if one side is empty, the result is the other side - if both sides are non-empty, the result is the logical AND - if the left side is false, the right side is not evaluated (short circuit)
      Parameters:
      other - the other optional predicate
      Returns:
      the logical AND of both predicates
    • or

      @NotNull default @NotNull OptionalPredicate<T> or(@NotNull @NotNull OptionalPredicate<T> other)
      Performs the logical OR on two optional predicates, such that: - if both sides are empty, the result is empty - if one side is empty, the result is the other side - if both sides are non-empty, the result is the logical OR - if the left side is true, the right side is not evaluated (short circuit)
      Parameters:
      other - the other optional predicate
      Returns:
      the logical OR of both predicates