aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query/src/main/java/tools/refinery/store/query/term/ArithmeticUnaryTerm.java
blob: bdc8754529a7873a198ce4aa0e61a4afb1312eee (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
/*
 * 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 ArithmeticUnaryTerm<T> extends UnaryTerm<T, T> {
	private final ArithmeticUnaryOperator operator;

	protected ArithmeticUnaryTerm(ArithmeticUnaryOperator operator, Term<T> body) {
		super(body);
		this.operator = operator;
	}

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

	public ArithmeticUnaryOperator getOperator() {
		return operator;
	}

	@Override
	public boolean equalsWithSubstitution(LiteralEqualityHelper helper, AnyTerm other) {
		if (!super.equalsWithSubstitution(helper, other)) {
			return false;
		}
		var otherArithmeticUnaryTerm = (ArithmeticUnaryTerm<?>) other;
		return operator == otherArithmeticUnaryTerm.operator;
	}

	@Override
	public String toString() {
		return operator.formatString(getBody().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;
		ArithmeticUnaryTerm<?> that = (ArithmeticUnaryTerm<?>) o;
		return operator == that.operator;
	}

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