summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2023-01-22 13:52:24 +0100
committerJon Bratseth <bratseth@gmail.com>2023-01-22 13:52:24 +0100
commit1f2865c97efe67f6f54151c26990226063c85d26 (patch)
tree6ba3d35da902a937ca3f033d238ef24046a4ffb4 /vespajlib
parent9628d47ea6bb4ea7481354320bc8ba78b0425c4a (diff)
Don't constrain groups to 1 if group-size is set
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/collections/IntRange.java7
1 files changed, 7 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/collections/IntRange.java b/vespajlib/src/main/java/com/yahoo/collections/IntRange.java
index e2a61688278..c1159357e08 100644
--- a/vespajlib/src/main/java/com/yahoo/collections/IntRange.java
+++ b/vespajlib/src/main/java/com/yahoo/collections/IntRange.java
@@ -38,6 +38,13 @@ public class IntRange {
return true;
}
+ /** Returns the given value adjusted minimally to fit within this range. */
+ public int fit(int value) {
+ if (from.isPresent() && value < from.getAsInt()) return from.getAsInt();
+ if (to.isPresent() && value > to.getAsInt()) return to.getAsInt();
+ return value;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;