aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/query/MultiRangeItem.java
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2022-03-23 15:33:04 +0100
committerjonmv <venstad@gmail.com>2022-10-26 12:07:17 +0200
commitd92c5a98abe7f05efed896a93d47695ea76215f3 (patch)
tree938ca88a4d559a8da5f9dee57b54dce3ef0bd2b5 /container-search/src/main/java/com/yahoo/prelude/query/MultiRangeItem.java
parent2e727510f09094faf433172f060b4f4d0f6a4cb2 (diff)
Add test that fails now
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/query/MultiRangeItem.java')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/MultiRangeItem.java25
1 files changed, 22 insertions, 3 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/MultiRangeItem.java b/container-search/src/main/java/com/yahoo/prelude/query/MultiRangeItem.java
index fb77f010df2..24d4623b2b8 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/MultiRangeItem.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/MultiRangeItem.java
@@ -46,6 +46,8 @@ import static java.util.Objects.requireNonNull;
* Adding ranges in ascending order is much faster than not; ascending order here has the rather lax
* requirement that each added interval is not completely before the current last interval.
*
+ * todo: cover all three cases of single index + ranges, dual index + ranges, dual index + points
+ *
* @author jonmv
*/
public class MultiRangeItem extends MultiTermItem {
@@ -80,9 +82,17 @@ public class MultiRangeItem extends MultiTermItem {
return Objects.hash(start, end);
}
+ @Override
+ public String toString() {
+ return "(" + start + ", " + end + ")";
+ }
+
}
- private static final Comparator<Number> comparator = comparingDouble(Number::doubleValue);
+ static final Comparator<Number> comparator = (a, b) -> {
+ double u = a.doubleValue(), v = b.doubleValue();
+ return u < v ? -1 : u > v ? 1 : 0;
+ };
private final String startIndex;
private final String endIndex;
@@ -113,8 +123,17 @@ public class MultiRangeItem extends MultiTermItem {
return overRanges(index, startInclusive, index, endInclusive);
}
+ /** Adds the given point to this item. More efficient when each added point is not completely before the current last one. */
+ public MultiRangeItem addPoint(Number point) {
+ return addRange(point, point);
+ }
+
/** Adds the given range to this item. More efficient when each added range is not completely before the current last one. */
- public MultiRangeItem add(Number start, Number end) {
+ public MultiRangeItem addRange(Number start, Number end) {
+ if (Double.isNaN(start.doubleValue()))
+ throw new IllegalArgumentException("range start cannot be NaN");
+ if (Double.isNaN(end.doubleValue()))
+ throw new IllegalArgumentException("range end cannot be NaN");
if (comparator.compare(start, end) > 0)
throw new IllegalArgumentException("ranges must satisfy start <= end, but got " + start + " > " + end);
@@ -154,7 +173,7 @@ public class MultiRangeItem extends MultiTermItem {
return comparator.compare(a, b) >= 0 ? a : b;
}
- private List<Range> sortedRanges() {
+ List<Range> sortedRanges() {
if (sorted)
return ranges;