Module jakarta.data

Interface LessThan<V extends Comparable<?>>

Type Parameters:
V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
All Superinterfaces:
Constraint<V>

public interface LessThan<V extends Comparable<?>> extends Constraint<V>

A constraint that requires being below an upper bound.

A parameter-based repository method can impose a constraint on an entity attribute by defining a method parameter that is of type LessThan or is annotated @Is(LessThan.class) and is of the same type or a subtype of the entity attribute. For example,

 @Find
 List<Car> withPriceBelow(@By(_Car.PRICE) LessThan<Integer> bound);

 @Find
 List<Car> pricedBelow(@By(_Car.PRICE) @Is(LessThan.class) int bound,
                        Order<Car> sorts);

 ...

 found = cars.withPriceBelow(LessThan.bound(40000));

 found = cars.pricedBelow(36000,
                          Order.by(_Car.price.desc()));
 

Repository methods can also accept LessThan constraints at run time in the form of a Restriction on a ComparableExpression. For example,

 @Find
 List<Car> searchAll(Restriction<Car> restrict, Order<Car> sorts);

 ...

 found = cars.searchAll(_Car.price.lessThan(35000),
                        Order.by(_Car.price.desc(),
                                 _Car.vin.asc());
 

The entity and static metamodel for the code examples within this class are shown in the Attribute Javadoc.

Since:
1.1
  • Method Summary

    Modifier and Type
    Method
    Description
    An expression that evaluates to an upper bound.
    static <V extends Comparable<?>>
    LessThan<V>
    bound(ComparableExpression<?,V> upperBound)
    Requires that the constraint target evaluates to a value that is less than the value to which the the given upperBound expression evaluates.
    static <V extends Comparable<?>>
    LessThan<V>
    bound(V upperBound)
    Requires that the constraint target evaluates to a value that is less than or equal to the given upperBound.

    Methods inherited from interface jakarta.data.constraint.Constraint

    negate
  • Method Details

    • bound

      static <V extends Comparable<?>> LessThan<V> bound(V upperBound)

      Requires that the constraint target evaluates to a value that is less than or equal to the given upperBound. For example,

       found = cars.withPriceBelow(LessThan.bound(37000));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      upperBound - an exclusive maximum value.
      Returns:
      a LessThan constraint.
      Throws:
      NullPointerException - if the upper bound is null.
    • bound

      static <V extends Comparable<?>> LessThan<V> bound(ComparableExpression<?,V> upperBound)

      Requires that the constraint target evaluates to a value that is less than the value to which the the given upperBound expression evaluates. For example,

       found = cars.withFirstModelYearBefore(LessThan.bound(_Car.year.minus(1)));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      upperBound - an expression that evaluates to an exclusive maximum value.
      Returns:
      a LessThan constraint.
      Throws:
      NullPointerException - if the upper bound is null.
    • bound

      An expression that evaluates to an upper bound. The constraint target must evaluate to a value less than this bound.

      Returns:
      an expression representing the upper bound.