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

import tools.refinery.store.query.literal.ConstantLiteral;
import tools.refinery.store.query.literal.EquivalenceLiteral;

import java.util.Objects;

public class Variable {
	private final String name;
	private final String uniqueName;

	public Variable() {
		this(null);
	}

	public Variable(String name) {
		super();
		this.name = name;
		this.uniqueName = DnfUtils.generateUniqueName(name);

	}
	public String getName() {
		return name == null ? uniqueName : name;
	}

	public boolean isExplicitlyNamed() {
		return name != null;
	}

	public String getUniqueName() {
		return uniqueName;
	}

	public ConstantLiteral isConstant(int value) {
		return new ConstantLiteral(this, value);
	}

	public EquivalenceLiteral isEquivalent(Variable other) {
		return new EquivalenceLiteral(true, this, other);
	}

	public EquivalenceLiteral notEquivalent(Variable other) {
		return new EquivalenceLiteral(false, this, other);
	}

	@Override
	public String toString() {
		return getName();
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Variable variable = (Variable) o;
		return Objects.equals(uniqueName, variable.uniqueName);
	}

	@Override
	public int hashCode() {
		return Objects.hash(uniqueName);
	}
}