Interface PredicateSpecification<T>
- All Superinterfaces:
Serializable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Specification in the sense of Domain Driven Design.
Specifications can be composed into higher order functions from other specifications using
and(PredicateSpecification), or(PredicateSpecification) or factory methods such as
allOf(Iterable). Composition considers whether one or more specifications contribute to the overall
predicate by returning a Predicate or null. Specifications returning null are
considered to not contribute to the overall predicate and their result is not considered in the final predicate.
- Since:
- 4.0
- Author:
- Mark Paluch
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> PredicateSpecification<T>allOf(Iterable<PredicateSpecification<T>> specifications) Applies an AND operation to all the givenPredicateSpecifications.static <T> PredicateSpecification<T>allOf(PredicateSpecification<T>... specifications) Applies an AND operation to all the givenPredicateSpecifications.default PredicateSpecification<T>and(PredicateSpecification<T> other) ANDs the given PredicateSpecification to the current one.static <T> PredicateSpecification<T>anyOf(Iterable<PredicateSpecification<T>> specifications) Applies an OR operation to all the givenPredicateSpecifications.static <T> PredicateSpecification<T>anyOf(PredicateSpecification<T>... specifications) Applies an OR operation to all the givenPredicateSpecifications.static <T> PredicateSpecification<T>not(PredicateSpecification<T> spec) Negates the givenPredicateSpecification.default PredicateSpecification<T>or(PredicateSpecification<T> other) ORs the given specification to the current one.@Nullable jakarta.persistence.criteria.PredicatetoPredicate(jakarta.persistence.criteria.Root<T> root, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder) Creates a WHERE clause for a query of the referenced entity in form of aPredicatefor the givenRootandCriteriaBuilder.static <T> PredicateSpecification<T>Simple static factory method to create a specification matching all objects.static <T> PredicateSpecification<T>where(PredicateSpecification<T> spec) Simple static factory method to add some syntactic sugar around a PredicateSpecification.
-
Method Details
-
unrestricted
Simple static factory method to create a specification matching all objects.- Type Parameters:
T- the type of theRootthe resulting PredicateSpecification operates on.- Returns:
- guaranteed to be not null.
-
where
Simple static factory method to add some syntactic sugar around a PredicateSpecification.- Type Parameters:
T- the type of theRootthe resulting PredicateSpecification operates on.- Parameters:
spec- must not be null.- Returns:
- guaranteed to be not null.
- Since:
- 2.0
-
and
@Contract("_ -> new") @CheckReturnValue default PredicateSpecification<T> and(PredicateSpecification<T> other) ANDs the given PredicateSpecification to the current one.- Parameters:
other- the otherPredicateSpecification.- Returns:
- the conjunction of the specifications.
-
or
@Contract("_ -> new") @CheckReturnValue default PredicateSpecification<T> or(PredicateSpecification<T> other) ORs the given specification to the current one.- Parameters:
other- the otherPredicateSpecification.- Returns:
- the disjunction of the specifications.
-
not
Negates the givenPredicateSpecification.- Type Parameters:
T- the type of theRootthe resulting PredicateSpecification operates on.- Parameters:
spec- can be null.- Returns:
- guaranteed to be not null.
-
allOf
@SafeVarargs static <T> PredicateSpecification<T> allOf(PredicateSpecification<T>... specifications) Applies an AND operation to all the givenPredicateSpecifications. Ifspecificationsis empty, the resultingPredicateSpecificationwill be unrestricted applying to all objects.- Parameters:
specifications- thePredicateSpecifications to compose.- Returns:
- the conjunction of the specifications.
- See Also:
-
allOf
Applies an AND operation to all the givenPredicateSpecifications. Ifspecificationsis empty, the resultingPredicateSpecificationwill be unrestricted applying to all objects.- Parameters:
specifications- thePredicateSpecifications to compose.- Returns:
- the conjunction of the specifications.
- See Also:
-
anyOf
@SafeVarargs static <T> PredicateSpecification<T> anyOf(PredicateSpecification<T>... specifications) Applies an OR operation to all the givenPredicateSpecifications. Ifspecificationsis empty, the resultingPredicateSpecificationwill be unrestricted applying to all objects.- Parameters:
specifications- thePredicateSpecifications to compose.- Returns:
- the disjunction of the specifications.
- See Also:
-
anyOf
Applies an OR operation to all the givenPredicateSpecifications. Ifspecificationsis empty, the resultingPredicateSpecificationwill be unrestricted applying to all objects.- Parameters:
specifications- thePredicateSpecifications to compose.- Returns:
- the disjunction of the specifications.
- See Also:
-
toPredicate
@Nullable jakarta.persistence.criteria.Predicate toPredicate(jakarta.persistence.criteria.Root<T> root, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder) Creates a WHERE clause for a query of the referenced entity in form of aPredicatefor the givenRootandCriteriaBuilder.- Parameters:
root- must not be null.criteriaBuilder- must not be null.- Returns:
- a
Predicate, may be null.
-