Class BetweenConstraint
java.lang.Object
io.fluxzero.common.api.search.constraints.PathConstraint
io.fluxzero.common.api.search.constraints.BetweenConstraint
- All Implemented Interfaces:
Constraint
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)
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");
Note: to speed up BetweenConstraint matching, it is recommended to annotate fields with Sortable.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BetweenConstraintCreates a constraint that matches values in the given path that are greater than or equal tomin.static BetweenConstraintCreates a constraint that matches values in the given path that are less thanmaxExclusive.static BetweenConstraintCreates a constraint that matches values in the given path that are greater than or equal tominand less thanmax.protected booleanDetermines whether path filtering should be performed before evaluating entry-level match criteria.protected booleanmatches(Document.Entry entry, Document document) Evaluates whether the specified document entry satisfies the condition defined by this method's implementation.Methods inherited from class PathConstraint
getPaths, hasPathConstraint, matches, withPathsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Constraint
and, decompose, or
-
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 tominand less thanmax.- Parameters:
min- the inclusive lower boundmaxExclusive- the exclusive upper boundpath- 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 tomin.- Parameters:
min- the inclusive lower boundpath- 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 thanmaxExclusive.- Parameters:
maxExclusive- the exclusive upper boundpath- the path in the document to compare
-
matches
Description copied from class:PathConstraintEvaluates whether the specified document entry satisfies the condition defined by this method's implementation.- Specified by:
matchesin classPathConstraint- Parameters:
entry- the document entry to evaluate- Returns:
trueif the entry satisfies the condition;falseotherwise
-
checkPathBeforeEntry
protected boolean checkPathBeforeEntry()Description copied from class:PathConstraintDetermines 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:
checkPathBeforeEntryin classPathConstraint- Returns:
trueif path filtering should be performed before evaluating entry-level criteria;falseif it should be applied after evaluating entry-level criteria.
-