Creates composite restrictions.
Composite restrictions are created by combining multiple restrictions,
which might themselves be composite restrictions or can be obtained from
static metamodel Attribute subtypes.
For example, the following constructs a composite restriction (from a basic restriction and another composite restriction) that matches cars that either cost less than $35000 or have newer model years than 2023 and cost less than $40000.
List<Car> found =
cars.search(make,
model,
Restrict.any(_Car.price.lessThan(35000),
Restrict.all(_Car.year.greaterThan(2023),
_Car.price.lessThan(40000))),
Order.by(_Car.year.desc(),
_Car.price.desc()));
- Since:
- 1.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Restriction<T> all(Restriction<? super T>... restrictions) Returns a composite restriction that is satisfied when all of the supplied restrictions are satisfied.static <T> Restriction<T> all(List<? extends Restriction<? super T>> restrictions) Returns a composite restriction that is satisfied when all of the supplied restrictions are satisfied.static <T> Restriction<T> any(Restriction<? super T>... restrictions) Returns a composite restriction that is satisfied when at least one of the supplied restrictions is satisfied.static <T> Restriction<T> any(List<? extends Restriction<? super T>> restrictions) Returns a composite restriction that is satisfied when at least one of the supplied restrictions is satisfied.static <T> Restriction<T> not(Restriction<T> restriction) Returns the negation of the specified restriction.static <T> Restriction<T> Returns a restriction that always evaluates to satisfied.
-
Method Details
-
all
Returns a composite restriction that is satisfied when all of the supplied restrictions are satisfied. The order of the restrictions is preserved in the composite restriction.
For example,
List<Book> jakartaEEBooksByAuthor = books.writtenBy(author, Restrict.all(_Book.title.notNull(), _Book.title.upper().contains("JAKARTA EE")), Order.by(_Book.title.asc()));- Type Parameters:
T- entity type.- Parameters:
restrictions- one or more restrictions obtained from a method ofRestrictor from a static metamodelAttributesubtype.- Returns:
- Throws:
IllegalArgumentException- if the supplied restrictions array is empty ornull.NullPointerException- if the supplied restrictions array includes anullvalue.
-
all
Returns a composite restriction that is satisfied when all of the supplied restrictions are satisfied. The order of the restrictions is preserved in the composite restriction, which keeps a
copyof the suppliedListrather than the original if the list is modifiable.For example,
List<Restriction<Book>> restrictions = new ArrayList<>(); restrictions.add(_Book.price.lessThanEqual(10.0f)); restrictions.add(_Book.numPages.greaterThanEqual(200)); List<Sort<Book>> sorts = new ArrayList<>(); sorts.add(_Book.price.desc()); sorts.add(_Book.title.asc()); List<Book> inexpensiveLongBooks = books.search(Restrict.all(restrictions), Order.by(sorts));- Type Parameters:
T- entity type.- Parameters:
restrictions- one or more restrictions obtained from a method ofRestrictor from a static metamodelAttributesubtype.- Returns:
- Throws:
IllegalArgumentException- if the supplied restrictions list is empty ornull.NullPointerException- if the supplied restrictions list includes anullvalue.
-
any
Returns a composite restriction that is satisfied when at least one of the supplied restrictions is satisfied. The order of the restrictions is preserved in the composite restriction.
For example,
List<Product> found = products.search(productName, Restrict.any(_Product.color.equalTo(Color.BLUE), _Product.color.equalTo(Color.GREEN)));- Type Parameters:
T- entity type.- Parameters:
restrictions- one or more restrictions obtained from a method ofRestrictor from a static metamodelAttributesubtype.- Returns:
- Throws:
IllegalArgumentException- if the supplied restrictions array is empty ornull.NullPointerException- if the supplied restrictions array includes anullvalue.
-
any
Returns a composite restriction that is satisfied when at least one of the supplied restrictions is satisfied. The order of the restrictions is preserved in the composite restriction The order of the restrictions is preserved in the composite restriction, which keeps a
copyof the suppliedListrather than the original if the list is modifiable.For example,
List<Restriction<Book>> restrictions = new ArrayList<>(); restrictions.add(_Book.price.lessThan(15.0f)); restrictions.add(_Book.hardcovered.isEqualTo(true)); List<Sort<Book>> sorts = new ArrayList<>(); sorts.add(_Book.price.desc()); sorts.add(_Book.isbn.asc()); List<Book> found = books.titled(title, Restrict.any(restrictions), Order.by(sorts));The example method above requires the book's title to always match and the book to either be priced under $15 or have a hard cover.
- Type Parameters:
T- entity type.- Parameters:
restrictions- one or more restrictions obtained from a method ofRestrictor from a static metamodelAttributesubtype.- Returns:
- Throws:
IllegalArgumentException- if the supplied restrictions array is empty ornull.NullPointerException- if the supplied restrictions array includes anullvalue.
-
not
Returns the negation of the specified restriction.
This restriction returned by this method is obtained by invoking
Restriction.negate()on the supplied restriction.- Returns:
- the negated restriction.
- Throws:
NullPointerException- if the supplied restriction isnull.
-
unrestricted
Returns a restriction that always evaluates to satisfied. This can be used to avoid imposing additional restrictions in places where a
Restrictionvalue is required.- Type Parameters:
T- entity type.- Returns:
- a restriction that is always considered to be satisfied.
-