Skip to content

Commit 9e5b4c9

Browse files
dfa1claude
andcommitted
feat(scan): add RowFilter.and(RowFilter) instance method for fluent chaining
Allows: RowFilter.gte("price", 100).and(RowFilter.lte("price", 500)) instead of the static: RowFilter.and(RowFilter.gte(...), RowFilter.lte(...)) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 37e263e commit 9e5b4c9

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

reader/src/main/java/io/github/dfa1/vortex/scan/RowFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ static RowFilter and(RowFilter... filters) {
1111
return new And(List.of(filters));
1212
}
1313

14+
default RowFilter and(RowFilter other) {
15+
return new And(List.of(this, other));
16+
}
17+
1418
static RowFilter gte(String col, Comparable<?> val) {
1519
return new Gte(col, val);
1620
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.github.dfa1.vortex.scan;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.List;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
class RowFilterTest {
10+
11+
@Test
12+
void and_instanceMethod_combinesTwoFilters() {
13+
// Given
14+
RowFilter left = RowFilter.gte("price", 100);
15+
RowFilter right = RowFilter.lte("price", 500);
16+
17+
// When
18+
RowFilter sut = left.and(right);
19+
20+
// Then
21+
assertThat(sut).isInstanceOf(RowFilter.And.class);
22+
assertThat(((RowFilter.And) sut).filters()).isEqualTo(List.of(left, right));
23+
}
24+
25+
@Test
26+
void and_instanceMethod_chainsMultiple() {
27+
// Given / When
28+
RowFilter sut = RowFilter.gte("price", 10)
29+
.and(RowFilter.lte("price", 500))
30+
.and(RowFilter.eq("active", true));
31+
32+
// Then — nested And(And(gte, lte), eq)
33+
assertThat(sut).isInstanceOf(RowFilter.And.class);
34+
RowFilter.And outer = (RowFilter.And) sut;
35+
assertThat(outer.filters()).hasSize(2);
36+
assertThat(outer.filters().get(0)).isInstanceOf(RowFilter.And.class);
37+
assertThat(outer.filters().get(1)).isInstanceOf(RowFilter.Eq.class);
38+
}
39+
}

0 commit comments

Comments
 (0)