Module jakarta.data

Interface AtMost<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 AtMost<V extends Comparable<?>> extends Constraint<V>

A constraint that imposes a maximum value.

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


 @Find
 List<Car> withMaximumPrice(@By(_Car.PRICE) AtMost<Integer> maxPrice);

 @Find
 List<Car> pricedAtMost(@By(_Car.PRICE) @Is(AtMost.class) int maximum,
                        Order<Car> sorts);

 ...

 found = cars.withMaximumPrice(AtMost.max(40000));

 found = cars.pricedAtMost(36000,
                           Order.by(_Car.price.desc(),
                                    _Car.vin.asc()));
 

Repository methods can also accept AtMost 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.lessThanEqual(35000),
                        Order.by(_Car.price.desc(),
                                 _Car.year.desc()));
 

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 the maximum value allowed for the constraint target.
    static <V extends Comparable<?>>
    AtMost<V>
    max(ComparableExpression<?,V> maximum)
    Requires that the constraint target evaluates to a value that is less than or equal the value to which the the given maximum expression evaluates.
    static <V extends Comparable<?>>
    AtMost<V>
    max(V maximum)
    Requires that the constraint target evaluates to a value that is less than or equal to the given maximum.

    Methods inherited from interface jakarta.data.constraint.Constraint

    negate
  • Method Details

    • max

      static <V extends Comparable<?>> AtMost<V> max(V maximum)

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

      
           found = cars.withMaximumPrice(AtMost.max(33000));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      maximum - the maximum value.
      Returns:
      an AtMost constraint.
      Throws:
      NullPointerException - if the maximum is null.
    • max

      static <V extends Comparable<?>> AtMost<V> max(ComparableExpression<?,V> maximum)

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

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

      An expression that evaluates to the maximum value allowed for the constraint target.

      Returns:
      an expression representing the maximum value.