diff options
Diffstat (limited to 'subprojects/store-query/src/main/java/tools/refinery/store/query/term/UnaryTerm.java')
-rw-r--r-- | subprojects/store-query/src/main/java/tools/refinery/store/query/term/UnaryTerm.java | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/term/UnaryTerm.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/term/UnaryTerm.java index 069e0d95..a46ebe31 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/term/UnaryTerm.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/term/UnaryTerm.java | |||
@@ -12,18 +12,23 @@ import tools.refinery.store.query.valuation.Valuation; | |||
12 | import java.util.Objects; | 12 | import java.util.Objects; |
13 | import java.util.Set; | 13 | import java.util.Set; |
14 | 14 | ||
15 | public abstract class UnaryTerm<R, T> implements Term<R> { | 15 | public abstract class UnaryTerm<R, T> extends AbstractTerm<R> { |
16 | private final Class<T> bodyType; | ||
16 | private final Term<T> body; | 17 | private final Term<T> body; |
17 | 18 | ||
18 | protected UnaryTerm(Term<T> body) { | 19 | protected UnaryTerm(Class<R> type, Class<T> bodyType, Term<T> body) { |
19 | if (!body.getType().equals(getBodyType())) { | 20 | super(type); |
21 | if (!body.getType().equals(bodyType)) { | ||
20 | throw new IllegalArgumentException("Expected body %s to be of type %s, got %s instead".formatted(body, | 22 | throw new IllegalArgumentException("Expected body %s to be of type %s, got %s instead".formatted(body, |
21 | getBodyType().getName(), body.getType().getName())); | 23 | bodyType.getName(), body.getType().getName())); |
22 | } | 24 | } |
25 | this.bodyType = bodyType; | ||
23 | this.body = body; | 26 | this.body = body; |
24 | } | 27 | } |
25 | 28 | ||
26 | public abstract Class<T> getBodyType(); | 29 | public Class<T> getBodyType() { |
30 | return bodyType; | ||
31 | } | ||
27 | 32 | ||
28 | public Term<T> getBody() { | 33 | public Term<T> getBody() { |
29 | return body; | 34 | return body; |
@@ -39,11 +44,11 @@ public abstract class UnaryTerm<R, T> implements Term<R> { | |||
39 | 44 | ||
40 | @Override | 45 | @Override |
41 | public boolean equalsWithSubstitution(LiteralEqualityHelper helper, AnyTerm other) { | 46 | public boolean equalsWithSubstitution(LiteralEqualityHelper helper, AnyTerm other) { |
42 | if (getClass() != other.getClass()) { | 47 | if (!super.equalsWithSubstitution(helper, other)) { |
43 | return false; | 48 | return false; |
44 | } | 49 | } |
45 | var otherUnaryTerm = (UnaryTerm<?, ?>) other; | 50 | var otherUnaryTerm = (UnaryTerm<?, ?>) other; |
46 | return body.equalsWithSubstitution(helper, otherUnaryTerm.body); | 51 | return bodyType.equals(otherUnaryTerm.bodyType) && body.equalsWithSubstitution(helper, otherUnaryTerm.body); |
47 | } | 52 | } |
48 | 53 | ||
49 | @Override | 54 | @Override |
@@ -62,12 +67,13 @@ public abstract class UnaryTerm<R, T> implements Term<R> { | |||
62 | public boolean equals(Object o) { | 67 | public boolean equals(Object o) { |
63 | if (this == o) return true; | 68 | if (this == o) return true; |
64 | if (o == null || getClass() != o.getClass()) return false; | 69 | if (o == null || getClass() != o.getClass()) return false; |
70 | if (!super.equals(o)) return false; | ||
65 | UnaryTerm<?, ?> unaryTerm = (UnaryTerm<?, ?>) o; | 71 | UnaryTerm<?, ?> unaryTerm = (UnaryTerm<?, ?>) o; |
66 | return body.equals(unaryTerm.body); | 72 | return Objects.equals(bodyType, unaryTerm.bodyType) && Objects.equals(body, unaryTerm.body); |
67 | } | 73 | } |
68 | 74 | ||
69 | @Override | 75 | @Override |
70 | public int hashCode() { | 76 | public int hashCode() { |
71 | return Objects.hash(getClass(), body); | 77 | return Objects.hash(super.hashCode(), bodyType, body); |
72 | } | 78 | } |
73 | } | 79 | } |