aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query/src/main/java/tools/refinery/store/query/term/ArithmeticBinaryTerm.java
blob: 887a1e6e9780ac11dbaeb7a7f49f69b573df90fd (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
package tools.refinery.store.query.term;

import tools.refinery.store.query.equality.LiteralEqualityHelper;

import java.util.Objects;

public abstract class ArithmeticBinaryTerm<T> extends BinaryTerm<T, T, T> {
	private final ArithmeticBinaryOperator operator;

	protected ArithmeticBinaryTerm(ArithmeticBinaryOperator operator, Term<T> left, Term<T> right) {
		super(left, right);
		this.operator = operator;
	}

	@Override
	public Class<T> getLeftType() {
		return getType();
	}

	@Override
	public Class<T> getRightType() {
		return getType();
	}

	public ArithmeticBinaryOperator getOperator() {
		return operator;
	}

	@Override
	public boolean equalsWithSubstitution(LiteralEqualityHelper helper, AnyTerm other) {
		if (!super.equalsWithSubstitution(helper, other)) {
			return false;
		}
		var otherArithmeticBinaryTerm = (ArithmeticBinaryTerm<?>) other;
		return operator == otherArithmeticBinaryTerm.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;
		ArithmeticBinaryTerm<?> that = (ArithmeticBinaryTerm<?>) o;
		return operator == that.operator;
	}

	@Override
	public int hashCode() {
		return Objects.hash(super.hashCode(), operator);
	}
}