Class BetweenConstraint

java.lang.Object
io.fluxcapacitor.common.api.search.constraints.PathConstraint
io.fluxcapacitor.common.api.search.constraints.BetweenConstraint
All Implemented Interfaces:
Constraint

public class BetweenConstraint extends PathConstraint
A Constraint that filters documents based on whether a value in a specific path lies between two bounds.

The range is defined as:

  • Inclusive of the lower bound (i.e. >= min)
  • Exclusive of the upper bound (i.e. < max)
Either bound may be omitted to create an open-ended constraint.

Values are compared lexically unless they are numeric (e.g. Number) or temporal (e.g. Instant), in which case they are normalized and compared accordingly.

Examples


 // Matches documents where "price" is between 100 (inclusive) and 200 (exclusive)
 Constraint c1 = BetweenConstraint.between(100, 200, "price");

 // Matches documents where "age" is at least 18
 Constraint c2 = BetweenConstraint.atLeast(18, "age");

 // Matches documents with timestamps before a certain date
 Constraint c3 = BetweenConstraint.below(Instant.now(), "createdAt");
 
  • Constructor Details

    • BetweenConstraint

      public BetweenConstraint()
  • Method Details

    • between

      public static BetweenConstraint between(Object min, Object maxExclusive, @NonNull @NonNull String path)
      Creates a constraint that matches values in the given path that are greater than or equal to min and less than max.
      Parameters:
      min - the inclusive lower bound
      maxExclusive - the exclusive upper bound
      path - the path in the document to compare
    • atLeast

      public static BetweenConstraint atLeast(@NonNull @NonNull Object min, @NonNull @NonNull String path)
      Creates a constraint that matches values in the given path that are greater than or equal to min.
      Parameters:
      min - the inclusive lower bound
      path - the path in the document to compare
    • below

      public static BetweenConstraint below(@NonNull @NonNull Object maxExclusive, @NonNull @NonNull String path)
      Creates a constraint that matches values in the given path that are less than maxExclusive.
      Parameters:
      maxExclusive - the exclusive upper bound
      path - the path in the document to compare
    • matches

      protected boolean matches(Document.Entry entry)
      Description copied from class: PathConstraint
      Evaluates whether the specified document entry satisfies the condition defined by this method's implementation.
      Specified by:
      matches in class PathConstraint
      Parameters:
      entry - the document entry to evaluate
      Returns:
      true if the entry satisfies the condition; false otherwise
    • checkPathBeforeEntry

      protected boolean checkPathBeforeEntry()
      Description copied from class: PathConstraint
      Determines whether path filtering should be performed before evaluating entry-level match criteria.

      By default, path filtering is applied after a document entry satisfies the primary match criteria (`false` return). Subclasses can override this method to change the behavior so that path filtering is applied first (`true` return).

      Overrides:
      checkPathBeforeEntry in class PathConstraint
      Returns:
      true if path filtering should be performed before evaluating entry-level criteria; false if it should be applied after evaluating entry-level criteria.