aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/SymbolicParameter.java
blob: e0d3ba1face64f825c7c5387f6b668704344f573 (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
/*
 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.store.query.dnf;

import tools.refinery.store.query.term.Parameter;
import tools.refinery.store.query.term.ParameterDirection;
import tools.refinery.store.query.term.Variable;

import java.util.Objects;

public final class SymbolicParameter extends Parameter {
	private final Variable variable;

	public SymbolicParameter(Variable variable, ParameterDirection direction) {
		super(variable.tryGetType().orElse(null), direction);
		this.variable = variable;
	}

	public Variable getVariable() {
		return variable;
	}

	public boolean isUnifiable() {
		return variable.isUnifiable();
	}

	@Override
	public String toString() {
		var direction = getDirection();
		if (direction == ParameterDirection.OUT) {
			return variable.toString();
		}
		return "%s %s".formatted(getDirection(), variable);
	}

	@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;
		SymbolicParameter that = (SymbolicParameter) o;
		return Objects.equals(variable, that.variable);
	}

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