diff options
Diffstat (limited to 'subprojects/store-query/src/main/java/tools/refinery/store/query/term/DataVariable.java')
-rw-r--r-- | subprojects/store-query/src/main/java/tools/refinery/store/query/term/DataVariable.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/term/DataVariable.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/term/DataVariable.java index 00950360..2206b522 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/term/DataVariable.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/term/DataVariable.java | |||
@@ -6,7 +6,10 @@ | |||
6 | package tools.refinery.store.query.term; | 6 | package tools.refinery.store.query.term; |
7 | 7 | ||
8 | import org.jetbrains.annotations.Nullable; | 8 | import org.jetbrains.annotations.Nullable; |
9 | import tools.refinery.store.query.InvalidQueryException; | ||
9 | import tools.refinery.store.query.equality.LiteralEqualityHelper; | 10 | import tools.refinery.store.query.equality.LiteralEqualityHelper; |
11 | import tools.refinery.store.query.equality.LiteralHashCodeHelper; | ||
12 | import tools.refinery.store.query.literal.EquivalenceLiteral; | ||
10 | import tools.refinery.store.query.literal.Literal; | 13 | import tools.refinery.store.query.literal.Literal; |
11 | import tools.refinery.store.query.substitution.Substitution; | 14 | import tools.refinery.store.query.substitution.Substitution; |
12 | import tools.refinery.store.query.valuation.Valuation; | 15 | import tools.refinery.store.query.valuation.Valuation; |
@@ -39,8 +42,8 @@ public final class DataVariable<T> extends AnyDataVariable implements Term<T> { | |||
39 | @Override | 42 | @Override |
40 | public <U> DataVariable<U> asDataVariable(Class<U> newType) { | 43 | public <U> DataVariable<U> asDataVariable(Class<U> newType) { |
41 | if (!getType().equals(newType)) { | 44 | if (!getType().equals(newType)) { |
42 | throw new IllegalStateException("%s is not of type %s but of type %s".formatted(this, newType.getName(), | 45 | throw new InvalidQueryException("%s is not of type %s but of type %s" |
43 | getType().getName())); | 46 | .formatted(this, newType.getName(), getType().getName())); |
44 | } | 47 | } |
45 | @SuppressWarnings("unchecked") | 48 | @SuppressWarnings("unchecked") |
46 | var result = (DataVariable<U>) this; | 49 | var result = (DataVariable<U>) this; |
@@ -62,6 +65,16 @@ public final class DataVariable<T> extends AnyDataVariable implements Term<T> { | |||
62 | return other instanceof DataVariable<?> dataVariable && helper.variableEqual(this, dataVariable); | 65 | return other instanceof DataVariable<?> dataVariable && helper.variableEqual(this, dataVariable); |
63 | } | 66 | } |
64 | 67 | ||
68 | @Override | ||
69 | public int hashCodeWithSubstitution(LiteralHashCodeHelper helper) { | ||
70 | return helper.getVariableHashCode(this); | ||
71 | } | ||
72 | |||
73 | @Override | ||
74 | public int hashCodeWithSubstitution(int sequenceNumber) { | ||
75 | return Objects.hash(type, sequenceNumber); | ||
76 | } | ||
77 | |||
65 | public Literal assign(AssignedValue<T> value) { | 78 | public Literal assign(AssignedValue<T> value) { |
66 | return value.toLiteral(this); | 79 | return value.toLiteral(this); |
67 | } | 80 | } |
@@ -79,4 +92,12 @@ public final class DataVariable<T> extends AnyDataVariable implements Term<T> { | |||
79 | public int hashCode() { | 92 | public int hashCode() { |
80 | return Objects.hash(super.hashCode(), type); | 93 | return Objects.hash(super.hashCode(), type); |
81 | } | 94 | } |
95 | |||
96 | public EquivalenceLiteral isEquivalent(DataVariable<T> other) { | ||
97 | return new EquivalenceLiteral(true, this, other); | ||
98 | } | ||
99 | |||
100 | public EquivalenceLiteral notEquivalent(DataVariable<T> other) { | ||
101 | return new EquivalenceLiteral(false, this, other); | ||
102 | } | ||
82 | } | 103 | } |