Module jakarta.data

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

A constraint that imposes minimum and maximum values.

A parameter-based repository method can impose a constraint on an entity attribute by defining a method parameter that is of type Between and is of the same type or a subtype of the entity attribute. For example,


 @Find
 List<Car> byModelYear(@By(_Car.YEAR) Between<Integer> yearRange,
                       Order<Car> sorts);

 ...

 found = cars.byModelYear(Between.bounds(2021, 2024));
 

Repository methods can also accept Between 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.between(25000, 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
    static <V extends Comparable<?>>
    Between<V>
    bounds(ComparableExpression<?,V> minimum, ComparableExpression<?,V> maximum)
    Requires that the constraint target evaluates to a value that is greater than or equal to the value to which the given minimum expression evaluates and less than or equal to the value to which the given maximum expression evaluates.
    static <V extends Comparable<?>>
    Between<V>
    bounds(ComparableExpression<?,V> minimum, V maximum)
    Requires that the constraint target evaluates to a value that is greater than or equal to the value to which the given minimum expression evaluates and less than or equal to the given maximum.
    static <V extends Comparable<?>>
    Between<V>
    bounds(V minimum, ComparableExpression<?,V> maximum)
    Requires that the constraint target evaluates to a value that is greater than or equal to the given minimum and less than or equal to the value to which the given maximum expression evaluates.
    static <V extends Comparable<?>>
    Between<V>
    bounds(V minimum, V maximum)
    Requires that the constraint target evaluates to a value that is greater than or equal to the given minimum and less than or equals to the given maximum.
    An expression that evaluates to the minimum value allowed for the constraint target.
    An expression that evaluates to the maximum value allowed for the constraint target.

    Methods inherited from interface jakarta.data.constraint.Constraint

    negate
  • Method Details

    • bounds

      static <V extends Comparable<?>> Between<V> bounds(V minimum, V maximum)

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

      
           found = cars.byPrice(Between.bounds(27000, 37000),
                                Order.by(_Car.price.desc()));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      minimum - the minimum value.
      maximum - the maximum value.
      Returns:
      a Between constraint.
      Throws:
      NullPointerException - if the minimum or maximum is null.
    • bounds

      static <V extends Comparable<?>> Between<V> bounds(V minimum, ComparableExpression<?,V> maximum)

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

      
           found = cars.byModelYear(Between.bounds(2020, _Car.firstModelYear.plus(5)),
                                    Order.by(_Car.price.desc()));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      minimum - a minimum value.
      maximum - an expression that evaluates to a maximum value.
      Returns:
      a Between constraint.
      Throws:
      NullPointerException - if the minimum or maximum is null.
    • bounds

      static <V extends Comparable<?>> Between<V> bounds(ComparableExpression<?,V> minimum, V maximum)

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

      
           found = cars.byModelYear(Between.bounds(_Car.firstModelYear.plus(2), 2024),
                                    Order.by(_Car.year.desc()));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      minimum - an expression that evaluates to a minimum value.
      maximum - a maximum value.
      Returns:
      a Between constraint.
      Throws:
      NullPointerException - if the minimum or maximum is null.
    • bounds

      static <V extends Comparable<?>> Between<V> bounds(ComparableExpression<?,V> minimum, ComparableExpression<?,V> maximum)

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

      
           found = cars.byModelYear(Between.bounds(_Car.firstModelYear.plus(1),
                                                   _Car.firstModelYear.plus(4)),
                                    Order.by(_Car.price.desc(),
                                             _Car.year.desc(),
                                             _Car.vin.asc()));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      minimum - an expression that evaluates to a minimum value.
      maximum - an expression that evaluates to a maximum value.
      Returns:
      a Between constraint.
      Throws:
      NullPointerException - if the minimum or maximum is null.
    • lowerBound

      ComparableExpression<?,V> lowerBound()

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

      Returns:
      an expression representing the minimum value.
    • upperBound

      ComparableExpression<?,V> upperBound()

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

      Returns:
      an expression representing the maximum value.