diff options
Diffstat (limited to 'subprojects/store-query/src/main/java/tools/refinery/store/query/literal/AssumeLiteral.java')
-rw-r--r-- | subprojects/store-query/src/main/java/tools/refinery/store/query/literal/AssumeLiteral.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/literal/AssumeLiteral.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/literal/AssumeLiteral.java index 59538831..61486e4c 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/literal/AssumeLiteral.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/literal/AssumeLiteral.java | |||
@@ -9,21 +9,31 @@ import tools.refinery.store.query.equality.LiteralEqualityHelper; | |||
9 | import tools.refinery.store.query.substitution.Substitution; | 9 | import tools.refinery.store.query.substitution.Substitution; |
10 | import tools.refinery.store.query.term.ConstantTerm; | 10 | import tools.refinery.store.query.term.ConstantTerm; |
11 | import tools.refinery.store.query.term.Term; | 11 | import tools.refinery.store.query.term.Term; |
12 | import tools.refinery.store.query.term.Variable; | ||
13 | 12 | ||
14 | import java.util.Set; | 13 | import java.util.Objects; |
15 | 14 | ||
16 | public record AssumeLiteral(Term<Boolean> term) implements Literal { | 15 | public final class AssumeLiteral implements Literal { |
17 | public AssumeLiteral { | 16 | private final Term<Boolean> term; |
17 | private final VariableBinder variableBinder; | ||
18 | |||
19 | public AssumeLiteral(Term<Boolean> term) { | ||
18 | if (!term.getType().equals(Boolean.class)) { | 20 | if (!term.getType().equals(Boolean.class)) { |
19 | throw new IllegalArgumentException("Term %s must be of type %s, got %s instead".formatted( | 21 | throw new IllegalArgumentException("Term %s must be of type %s, got %s instead".formatted( |
20 | term, Boolean.class.getName(), term.getType().getName())); | 22 | term, Boolean.class.getName(), term.getType().getName())); |
21 | } | 23 | } |
24 | this.term = term; | ||
25 | variableBinder = VariableBinder.builder() | ||
26 | .variables(term.getInputVariables(), VariableDirection.IN) | ||
27 | .build(); | ||
28 | } | ||
29 | |||
30 | public Term<Boolean> getTerm() { | ||
31 | return term; | ||
22 | } | 32 | } |
23 | 33 | ||
24 | @Override | 34 | @Override |
25 | public Set<Variable> getBoundVariables() { | 35 | public VariableBinder getVariableBinder() { |
26 | return Set.of(); | 36 | return variableBinder; |
27 | } | 37 | } |
28 | 38 | ||
29 | @Override | 39 | @Override |
@@ -54,4 +64,17 @@ public record AssumeLiteral(Term<Boolean> term) implements Literal { | |||
54 | public String toString() { | 64 | public String toString() { |
55 | return "(%s)".formatted(term); | 65 | return "(%s)".formatted(term); |
56 | } | 66 | } |
67 | |||
68 | @Override | ||
69 | public boolean equals(Object obj) { | ||
70 | if (obj == this) return true; | ||
71 | if (obj == null || obj.getClass() != this.getClass()) return false; | ||
72 | var that = (AssumeLiteral) obj; | ||
73 | return Objects.equals(this.term, that.term); | ||
74 | } | ||
75 | |||
76 | @Override | ||
77 | public int hashCode() { | ||
78 | return Objects.hash(getClass(), term); | ||
79 | } | ||
57 | } | 80 | } |