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

import tools.refinery.store.query.Variable;
import tools.refinery.store.query.equality.LiteralEqualityHelper;
import tools.refinery.store.query.substitution.Substitution;

import java.util.Set;

public enum BooleanLiteral implements PolarLiteral<BooleanLiteral> {
	TRUE(true),
	FALSE(false);

	private final boolean value;

	BooleanLiteral(boolean value) {
		this.value = value;
	}

	@Override
	public void collectAllVariables(Set<Variable> variables) {
		// No variables to collect.
	}

	@Override
	public Literal substitute(Substitution substitution) {
		// No variables to substitute.
		return this;
	}

	@Override
	public LiteralReduction getReduction() {
		return value ? LiteralReduction.ALWAYS_TRUE : LiteralReduction.ALWAYS_FALSE;
	}

	@Override
	public BooleanLiteral negate() {
		return fromBoolean(!value);
	}

	@Override
	public boolean equalsWithSubstitution(LiteralEqualityHelper helper, Literal other) {
		return equals(other);
	}

	@Override
	public String toString() {
		return Boolean.toString(value);
	}

	public static BooleanLiteral fromBoolean(boolean value) {
		return value ? TRUE : FALSE;
	}
}