blob: 2c304aef78fc1844238460c0c10817fda28fb099 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*
* SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.store.query.term;
import tools.refinery.store.query.equality.LiteralEqualityHelper;
import java.util.Objects;
public abstract class ComparisonTerm<T> extends BinaryTerm<Boolean, T, T> {
private final ComparisonOperator operator;
protected ComparisonTerm(ComparisonOperator operator, Term<T> left, Term<T> right) {
super(left, right);
this.operator = operator;
}
@Override
public Class<Boolean> getType() {
return Boolean.class;
}
public abstract Class<T> getOperandType();
@Override
public Class<T> getLeftType() {
return getOperandType();
}
@Override
public Class<T> getRightType() {
return getOperandType();
}
public ComparisonOperator getOperator() {
return operator;
}
@Override
public boolean equalsWithSubstitution(LiteralEqualityHelper helper, AnyTerm other) {
if (!super.equalsWithSubstitution(helper, other)) {
return false;
}
var otherComparisonTerm = (ComparisonTerm<?>) other;
return operator == otherComparisonTerm.operator;
}
@Override
public String toString() {
return operator.formatString(getLeft().toString(), getRight().toString());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ComparisonTerm<?> that = (ComparisonTerm<?>) o;
return operator == that.operator;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), operator);
}
}
|