aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query/src/main/java/tools/refinery/store/query/term/ConstantTerm.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-query/src/main/java/tools/refinery/store/query/term/ConstantTerm.java')
-rw-r--r--subprojects/store-query/src/main/java/tools/refinery/store/query/term/ConstantTerm.java24
1 files changed, 10 insertions, 14 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/term/ConstantTerm.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/term/ConstantTerm.java
index 2f6c56d1..415ae286 100644
--- a/subprojects/store-query/src/main/java/tools/refinery/store/query/term/ConstantTerm.java
+++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/term/ConstantTerm.java
@@ -5,20 +5,24 @@
5 */ 5 */
6package tools.refinery.store.query.term; 6package tools.refinery.store.query.term;
7 7
8import tools.refinery.store.query.InvalidQueryException;
8import tools.refinery.store.query.equality.LiteralEqualityHelper; 9import tools.refinery.store.query.equality.LiteralEqualityHelper;
10import tools.refinery.store.query.equality.LiteralHashCodeHelper;
9import tools.refinery.store.query.substitution.Substitution; 11import tools.refinery.store.query.substitution.Substitution;
10import tools.refinery.store.query.valuation.Valuation; 12import tools.refinery.store.query.valuation.Valuation;
11 13
12import java.util.Objects; 14import java.util.Objects;
13import java.util.Set; 15import java.util.Set;
14 16
17// {@link Object#equals(Object)} is implemented by {@link AbstractTerm}.
18@SuppressWarnings("squid:S2160")
15public final class ConstantTerm<T> extends AbstractTerm<T> { 19public final class ConstantTerm<T> extends AbstractTerm<T> {
16 private final T value; 20 private final T value;
17 21
18 public ConstantTerm(Class<T> type, T value) { 22 public ConstantTerm(Class<T> type, T value) {
19 super(type); 23 super(type);
20 if (value != null && !type.isInstance(value)) { 24 if (value != null && !type.isInstance(value)) {
21 throw new IllegalArgumentException("Value %s is not an instance of %s".formatted(value, type.getName())); 25 throw new InvalidQueryException("Value %s is not an instance of %s".formatted(value, type.getName()));
22 } 26 }
23 this.value = value; 27 this.value = value;
24 } 28 }
@@ -47,6 +51,11 @@ public final class ConstantTerm<T> extends AbstractTerm<T> {
47 } 51 }
48 52
49 @Override 53 @Override
54 public int hashCodeWithSubstitution(LiteralHashCodeHelper helper) {
55 return Objects.hash(super.hashCodeWithSubstitution(helper), Objects.hash(value));
56 }
57
58 @Override
50 public Set<AnyDataVariable> getInputVariables() { 59 public Set<AnyDataVariable> getInputVariables() {
51 return Set.of(); 60 return Set.of();
52 } 61 }
@@ -55,17 +64,4 @@ public final class ConstantTerm<T> extends AbstractTerm<T> {
55 public String toString() { 64 public String toString() {
56 return value.toString(); 65 return value.toString();
57 } 66 }
58
59 @Override
60 public boolean equals(Object o) {
61 if (this == o) return true;
62 if (o == null || getClass() != o.getClass()) return false;
63 ConstantTerm<?> that = (ConstantTerm<?>) o;
64 return Objects.equals(value, that.value);
65 }
66
67 @Override
68 public int hashCode() {
69 return Objects.hash(value);
70 }
71} 67}