Skip to content

Commit 25f4626

Browse files
anidotnetclaude
andcommitted
Split Range.of into its equality and bounded-range halves
One method carried both plan shapes and every rejection path for each, which is where the remaining Codacy complexity findings sat. The two shapes have nothing in common but the return type. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent ee6aff4 commit 25f4626

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

‎nitrite/src/main/java/org/dizitart/no2/index/SingleFieldIndex.java‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,26 @@ static Range of(List<ComparableFilter> filters) {
197197
return null;
198198
}
199199
if (filters.size() == 1 && filters.get(0).getClass() == EqualsFilter.class) {
200-
Object value = filters.get(0).getValue();
201-
if (value == null) {
202-
return new Range(DBNull.getInstance(), true, DBNull.getInstance(), true);
203-
}
204-
if (!(value instanceof Comparable)) {
205-
return null;
206-
}
207-
DBValue key = new DBValue((Comparable<?>) value);
208-
return new Range(key, true, key, true);
200+
return ofEquality(filters.get(0));
209201
}
202+
return ofBoundedRange(filters);
203+
}
204+
205+
/** {@code field = value}, which is the degenerate range with both bounds on that value. */
206+
private static Range ofEquality(ComparableFilter filter) {
207+
Object value = filter.getValue();
208+
if (value == null) {
209+
return new Range(DBNull.getInstance(), true, DBNull.getInstance(), true);
210+
}
211+
if (!(value instanceof Comparable)) {
212+
return null;
213+
}
214+
DBValue key = new DBValue((Comparable<?>) value);
215+
return new Range(key, true, key, true);
216+
}
210217

211-
// a two-sided range on one field, the same shape IndexScanner.scanBoundedRange takes
218+
/** A two-sided range on one field, the same shape {@code IndexScanner.scanBoundedRange} takes. */
219+
private static Range ofBoundedRange(List<ComparableFilter> filters) {
212220
String field = filters.get(0).getField();
213221
DBValue lower = null;
214222
DBValue upper = null;

0 commit comments

Comments
 (0)