diff options
Diffstat (limited to 'subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/RelationalQuery.java')
-rw-r--r-- | subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/RelationalQuery.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/RelationalQuery.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/RelationalQuery.java new file mode 100644 index 00000000..5307e509 --- /dev/null +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/RelationalQuery.java | |||
@@ -0,0 +1,93 @@ | |||
1 | package tools.refinery.store.query.dnf; | ||
2 | |||
3 | import tools.refinery.store.query.literal.CallLiteral; | ||
4 | import tools.refinery.store.query.literal.CallPolarity; | ||
5 | import tools.refinery.store.query.term.AssignedValue; | ||
6 | import tools.refinery.store.query.term.NodeSort; | ||
7 | import tools.refinery.store.query.term.NodeVariable; | ||
8 | |||
9 | import java.util.Collections; | ||
10 | import java.util.List; | ||
11 | import java.util.Objects; | ||
12 | |||
13 | public final class RelationalQuery implements Query<Boolean> { | ||
14 | private final Dnf dnf; | ||
15 | |||
16 | RelationalQuery(Dnf dnf) { | ||
17 | for (var parameter : dnf.getParameters()) { | ||
18 | if (!(parameter instanceof NodeVariable)) { | ||
19 | throw new IllegalArgumentException("Expected parameter %s of %s to be of sort %s, but got %s instead" | ||
20 | .formatted(parameter, dnf, NodeSort.INSTANCE, parameter.getSort())); | ||
21 | } | ||
22 | } | ||
23 | this.dnf = dnf; | ||
24 | } | ||
25 | |||
26 | @Override | ||
27 | public String name() { | ||
28 | return dnf.name(); | ||
29 | } | ||
30 | |||
31 | @Override | ||
32 | public int arity() { | ||
33 | return dnf.arity(); | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | public Class<Boolean> valueType() { | ||
38 | return Boolean.class; | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public Boolean defaultValue() { | ||
43 | return false; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public Dnf getDnf() { | ||
48 | return dnf; | ||
49 | } | ||
50 | |||
51 | public CallLiteral call(CallPolarity polarity, List<NodeVariable> arguments) { | ||
52 | return dnf.call(polarity, Collections.unmodifiableList(arguments)); | ||
53 | } | ||
54 | |||
55 | public CallLiteral call(CallPolarity polarity, NodeVariable... arguments) { | ||
56 | return dnf.call(polarity, arguments); | ||
57 | } | ||
58 | |||
59 | public CallLiteral call(NodeVariable... arguments) { | ||
60 | return dnf.call(arguments); | ||
61 | } | ||
62 | |||
63 | public CallLiteral callTransitive(NodeVariable left, NodeVariable right) { | ||
64 | return dnf.callTransitive(left, right); | ||
65 | } | ||
66 | |||
67 | public AssignedValue<Integer> count(List<NodeVariable> arguments) { | ||
68 | return dnf.count(Collections.unmodifiableList(arguments)); | ||
69 | } | ||
70 | |||
71 | public AssignedValue<Integer> count(NodeVariable... arguments) { | ||
72 | return dnf.count(arguments); | ||
73 | } | ||
74 | |||
75 | |||
76 | @Override | ||
77 | public boolean equals(Object o) { | ||
78 | if (this == o) return true; | ||
79 | if (o == null || getClass() != o.getClass()) return false; | ||
80 | RelationalQuery that = (RelationalQuery) o; | ||
81 | return dnf.equals(that.dnf); | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public int hashCode() { | ||
86 | return Objects.hash(dnf); | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public String toString() { | ||
91 | return dnf.toString(); | ||
92 | } | ||
93 | } | ||