Skip to content

Commit 7345f50

Browse files
anidotnetclaude
andcommitted
Style: one declaration and one statement per line in the range parser
Codacy's quality gate flagged five new issues on this branch. The switch arms packed an assignment, a flag and a break onto one line, the bounds were declared two to a line, and ArrayDeque was written out fully qualified. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 86173b0 commit 7345f50

3 files changed

Lines changed: 25 additions & 17 deletions

File tree

‎nitrite/src/main/java/org/dizitart/no2/common/streams/IndexedStream.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
import org.dizitart.no2.store.NitriteMap;
2525

2626
import java.util.Iterator;
27-
<<<<<<< HEAD
2827
import java.util.NoSuchElementException;
29-
import java.util.Set;
30-
=======
31-
>>>>>>> a09dd45e (perf: stream equality and range index scans instead of materializing every id)
3228

3329
/**
3430
* @author Anindya Chatterjee

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@
3030
import org.dizitart.no2.common.RecordStream;
3131
import org.dizitart.no2.filters.EqualsFilter;
3232
import org.dizitart.no2.filters.SortingAwareFilter;
33+
import org.dizitart.no2.filters.SortingAwareFilter.ComparisonMode;
3334
import org.dizitart.no2.store.NitriteMap;
3435
import org.dizitart.no2.store.NitriteStore;
3536

37+
import java.util.ArrayDeque;
3638
import java.util.ArrayList;
3739
import java.util.HashSet;
40+
import java.util.Iterator;
3841
import java.util.LinkedHashSet;
3942
import java.util.List;
4043
import java.util.NoSuchElementException;
41-
import java.util.Iterator;
4244
import java.util.Set;
4345

4446
import static org.dizitart.no2.common.util.IndexUtils.deriveCompositeIndexMapName;
@@ -208,8 +210,10 @@ static Range of(List<ComparableFilter> filters) {
208210

209211
// a two-sided range on one field, the same shape IndexScanner.scanBoundedRange takes
210212
String field = filters.get(0).getField();
211-
DBValue lower = null, upper = null;
212-
boolean lowerInclusive = false, upperInclusive = false;
213+
DBValue lower = null;
214+
DBValue upper = null;
215+
boolean lowerInclusive = false;
216+
boolean upperInclusive = false;
213217
for (ComparableFilter filter : filters) {
214218
if (!(filter instanceof SortingAwareFilter) || field == null || !field.equals(filter.getField())) {
215219
return null;
@@ -219,19 +223,24 @@ static Range of(List<ComparableFilter> filters) {
219223
return null;
220224
}
221225
DBValue key = new DBValue((Comparable<?>) value);
222-
switch (((SortingAwareFilter) filter).getComparisonMode()) {
226+
ComparisonMode mode = ((SortingAwareFilter) filter).getComparisonMode();
227+
switch (mode) {
223228
case GreaterEqual:
224-
if (lower != null) return null;
225-
lower = key; lowerInclusive = true; break;
226229
case Greater:
227-
if (lower != null) return null;
228-
lower = key; lowerInclusive = false; break;
230+
if (lower != null) {
231+
return null;
232+
}
233+
lower = key;
234+
lowerInclusive = mode == ComparisonMode.GreaterEqual;
235+
break;
229236
case LesserEqual:
230-
if (upper != null) return null;
231-
upper = key; upperInclusive = true; break;
232237
case Lesser:
233-
if (upper != null) return null;
234-
upper = key; upperInclusive = false; break;
238+
if (upper != null) {
239+
return null;
240+
}
241+
upper = key;
242+
upperInclusive = mode == ComparisonMode.LesserEqual;
243+
break;
235244
default:
236245
return null;
237246
}
@@ -252,7 +261,7 @@ private static final class CompositeRangeIterator implements Iterator<NitriteId>
252261
private final Range range;
253262
private final boolean reverse;
254263
private final Set<NitriteId> seen = new HashSet<>();
255-
private final java.util.ArrayDeque<NitriteId> group = new java.util.ArrayDeque<>();
264+
private final ArrayDeque<NitriteId> group = new ArrayDeque<>();
256265
private IndexEntryKey key;
257266
private NitriteId next;
258267
private boolean started;

‎nitrite/src/test/java/org/dizitart/no2/index/SingleFieldIndexTest.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ public void testReadSortKeysOfUniqueIndex() {
201201
assertEquals(Arrays.asList(NitriteId.createId(1L), NitriteId.createId(2L), NitriteId.createId(3L)),
202202
keys.stream().map(Pair::getSecond).collect(java.util.stream.Collectors.toList()));
203203
assertNull("an index that does not cover every document cannot stand in for it", index.readSortKeys(4));
204+
}
205+
206+
@Test
204207
public void testLazyStreamMatchesMaterializedScanForEqualityAndRange() {
205208
InMemoryStore store = new InMemoryStore();
206209
IndexDescriptor desc = new IndexDescriptor(IndexType.NON_UNIQUE, Fields.withNames("k"), "c");

0 commit comments

Comments
 (0)