Class OptionalPredicate

java.lang.Object
io.github.torand.fastersql.predicate.OptionalPredicate

public class OptionalPredicate extends Object
Implements an optional predicate. The predicate is only executed if the wrapped predicate is present.
  • Method Details

    • of

      public static OptionalPredicate of(Predicate predicate)
      Creates an optional predicate wrapping specified non-null predicate.
      Parameters:
      predicate - the predicate.
      Returns:
      the optional predicate.
    • ofNullable

      public static OptionalPredicate ofNullable(Predicate predicate)
      Creates an optional predicate wrapping specified null or non-null predicate.
      Parameters:
      predicate - the predicate.
      Returns:
      the optional predicate.
    • empty

      public static OptionalPredicate empty()
      Creates an optional predicate with no wrapped predicate.
      Returns:
      the optional predicate.
    • isPresent

      public boolean isPresent()
      Indicates whether there is a wrapped predicate.
      Returns:
      true if there is wrapped predicate; else false.
    • get

      public Predicate get()
      Gets the wrapped predicate if present. Throws if not present.
      Returns:
      the wrapped predicate.
    • stream

      public Stream<Predicate> stream()
      Gets a stream containing the wrapped predicate, if any.
      Returns:
      the stream.
    • or

      public OptionalPredicate or(Predicate other)
      Creates an optional compound predicate of performing the boolean operator OR on this optional predicate and the specified predicate.
      Parameters:
      other - the other predicate.
      Returns:
      the optional compound predicate.
    • or

      Creates an optional compound predicate of performing the boolean operator OR on this optional predicate and the specified optional predicate.
      Parameters:
      other - the other optional predicate.
      Returns:
      the optional compound predicate.
    • and

      public OptionalPredicate and(Predicate other)
      Creates an optional compound predicate of performing the boolean operator AND on this optional predicate and the specified predicate.
      Parameters:
      other - the other predicate.
      Returns:
      the optional compound predicate.
    • and

      Creates an optional compound predicate of performing the boolean operator AND on this optional predicate and the specified optional predicate.
      Parameters:
      other - the other optional predicate.
      Returns:
      the optional compound predicate.
    • unwrap

      public static Collection<Predicate> unwrap(OptionalPredicate... optionalPredicates)
      Gets a list of present wrapped predicates from the specified array of optional predicates.
      Parameters:
      optionalPredicates - the optional predicates-
      Returns:
      the collection of present predicates.