Skip to content

Commit 59d909b

Browse files
cursoragentsimbo1905
andcommitted
Issue #121 Split JsonPath expression AST into dedicated files
Co-authored-by: simbo1905 <simbo1905@60hertz.com>
1 parent c5fca6b commit 59d909b

File tree

3 files changed

+59
-51
lines changed

3 files changed

+59
-51
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package json.java21.jsonpath;
2+
3+
import java.util.Objects;
4+
5+
sealed interface BoolExpr permits BoolExpr.Exists, BoolExpr.Compare {
6+
record Exists(ValueExpr.Path path) implements BoolExpr {
7+
public Exists {
8+
Objects.requireNonNull(path, "path must not be null");
9+
}
10+
}
11+
12+
enum CmpOp {
13+
LT, LE, GT, GE, EQ, NE
14+
}
15+
16+
record Compare(CmpOp op, ValueExpr left, ValueExpr right) implements BoolExpr {
17+
public Compare {
18+
Objects.requireNonNull(op, "op must not be null");
19+
Objects.requireNonNull(left, "left must not be null");
20+
Objects.requireNonNull(right, "right must not be null");
21+
}
22+
}
23+
}
24+

json-java21-jsonpath/src/main/java/json/java21/jsonpath/JsonPathAst.java

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -77,54 +77,3 @@ record ScriptIndex(ValueExpr expr) implements Step {
7777
}
7878
}
7979
}
80-
81-
sealed interface BoolExpr permits BoolExpr.Exists, BoolExpr.Compare {
82-
record Exists(ValueExpr.Path path) implements BoolExpr {
83-
public Exists {
84-
Objects.requireNonNull(path, "path must not be null");
85-
}
86-
}
87-
88-
enum CmpOp {
89-
LT, LE, GT, GE, EQ, NE
90-
}
91-
92-
record Compare(CmpOp op, ValueExpr left, ValueExpr right) implements BoolExpr {
93-
public Compare {
94-
Objects.requireNonNull(op, "op must not be null");
95-
Objects.requireNonNull(left, "left must not be null");
96-
Objects.requireNonNull(right, "right must not be null");
97-
}
98-
}
99-
}
100-
101-
sealed interface ValueExpr permits ValueExpr.Path, ValueExpr.Num, ValueExpr.Str, ValueExpr.Arith {
102-
103-
record Path(List<String> parts) implements ValueExpr {
104-
public Path {
105-
Objects.requireNonNull(parts, "parts must not be null");
106-
parts.forEach(p -> Objects.requireNonNull(p, "path part must not be null"));
107-
}
108-
}
109-
110-
record Num(double value) implements ValueExpr {}
111-
112-
record Str(String value) implements ValueExpr {
113-
public Str {
114-
Objects.requireNonNull(value, "value must not be null");
115-
}
116-
}
117-
118-
enum ArithOp {
119-
ADD, SUB
120-
}
121-
122-
record Arith(ArithOp op, ValueExpr left, ValueExpr right) implements ValueExpr {
123-
public Arith {
124-
Objects.requireNonNull(op, "op must not be null");
125-
Objects.requireNonNull(left, "left must not be null");
126-
Objects.requireNonNull(right, "right must not be null");
127-
}
128-
}
129-
}
130-
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package json.java21.jsonpath;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
6+
sealed interface ValueExpr permits ValueExpr.Path, ValueExpr.Num, ValueExpr.Str, ValueExpr.Arith {
7+
8+
record Path(List<String> parts) implements ValueExpr {
9+
public Path {
10+
Objects.requireNonNull(parts, "parts must not be null");
11+
parts.forEach(p -> Objects.requireNonNull(p, "path part must not be null"));
12+
}
13+
}
14+
15+
record Num(double value) implements ValueExpr {}
16+
17+
record Str(String value) implements ValueExpr {
18+
public Str {
19+
Objects.requireNonNull(value, "value must not be null");
20+
}
21+
}
22+
23+
enum ArithOp {
24+
ADD, SUB
25+
}
26+
27+
record Arith(ArithOp op, ValueExpr left, ValueExpr right) implements ValueExpr {
28+
public Arith {
29+
Objects.requireNonNull(op, "op must not be null");
30+
Objects.requireNonNull(left, "left must not be null");
31+
Objects.requireNonNull(right, "right must not be null");
32+
}
33+
}
34+
}
35+

0 commit comments

Comments
 (0)