diff options
Diffstat (limited to 'subprojects/logic/src/main/java/tools/refinery/logic/term/AbstractTerm.java')
-rw-r--r-- | subprojects/logic/src/main/java/tools/refinery/logic/term/AbstractTerm.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/subprojects/logic/src/main/java/tools/refinery/logic/term/AbstractTerm.java b/subprojects/logic/src/main/java/tools/refinery/logic/term/AbstractTerm.java new file mode 100644 index 00000000..293f7e9e --- /dev/null +++ b/subprojects/logic/src/main/java/tools/refinery/logic/term/AbstractTerm.java | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.logic.term; | ||
7 | |||
8 | import tools.refinery.logic.equality.LiteralEqualityHelper; | ||
9 | import tools.refinery.logic.equality.LiteralHashCodeHelper; | ||
10 | |||
11 | import java.util.Objects; | ||
12 | |||
13 | public abstract class AbstractTerm<T> implements Term<T> { | ||
14 | private final Class<T> type; | ||
15 | |||
16 | protected AbstractTerm(Class<T> type) { | ||
17 | this.type = type; | ||
18 | } | ||
19 | |||
20 | @Override | ||
21 | public Class<T> getType() { | ||
22 | return type; | ||
23 | } | ||
24 | |||
25 | @Override | ||
26 | public boolean equalsWithSubstitution(LiteralEqualityHelper helper, AnyTerm other) { | ||
27 | return other != null && getClass() == other.getClass() && type.equals(other.getType()); | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | public int hashCodeWithSubstitution(LiteralHashCodeHelper helper) { | ||
32 | return Objects.hash(getClass(), type); | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public boolean equals(Object o) { | ||
37 | if (this == o) return true; | ||
38 | if (o == null || getClass() != o.getClass()) return false; | ||
39 | AbstractTerm<?> that = (AbstractTerm<?>) o; | ||
40 | return equalsWithSubstitution(LiteralEqualityHelper.DEFAULT, that); | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public int hashCode() { | ||
45 | return hashCodeWithSubstitution(LiteralHashCodeHelper.DEFAULT); | ||
46 | } | ||
47 | } | ||