diff options
Diffstat (limited to 'subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/Query.java')
-rw-r--r-- | subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/Query.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/Query.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/Query.java index aaa52ce6..83fe6ccd 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/Query.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/Query.java | |||
@@ -43,6 +43,29 @@ public abstract sealed class Query<T> implements AnyQuery permits FunctionalQuer | |||
43 | 43 | ||
44 | public abstract T defaultValue(); | 44 | public abstract T defaultValue(); |
45 | 45 | ||
46 | public Query<T> withDnf(Dnf newDnf) { | ||
47 | if (dnf.equals(newDnf)) { | ||
48 | return this; | ||
49 | } | ||
50 | int arity = dnf.arity(); | ||
51 | if (newDnf.arity() != arity) { | ||
52 | throw new IllegalArgumentException("Arity of %s and %s do not match".formatted(dnf, newDnf)); | ||
53 | } | ||
54 | var parameters = dnf.getParameters(); | ||
55 | var newParameters = newDnf.getParameters(); | ||
56 | for (int i = 0; i < arity; i++) { | ||
57 | var parameter = parameters.get(i); | ||
58 | var newParameter = newParameters.get(i); | ||
59 | if (!parameter.matches(newParameter)) { | ||
60 | throw new IllegalArgumentException("Parameter #%d mismatch: %s does not match %s" | ||
61 | .formatted(i, parameter, newParameter)); | ||
62 | } | ||
63 | } | ||
64 | return withDnfInternal(newDnf); | ||
65 | } | ||
66 | |||
67 | protected abstract Query<T> withDnfInternal(Dnf newDnf); | ||
68 | |||
46 | @Override | 69 | @Override |
47 | public boolean equals(Object o) { | 70 | public boolean equals(Object o) { |
48 | if (this == o) return true; | 71 | if (this == o) return true; |