diff options
Diffstat (limited to 'subprojects/logic/src/main/java/tools/refinery/logic/literal/BooleanLiteral.java')
-rw-r--r-- | subprojects/logic/src/main/java/tools/refinery/logic/literal/BooleanLiteral.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/subprojects/logic/src/main/java/tools/refinery/logic/literal/BooleanLiteral.java b/subprojects/logic/src/main/java/tools/refinery/logic/literal/BooleanLiteral.java new file mode 100644 index 00000000..fd1dbf91 --- /dev/null +++ b/subprojects/logic/src/main/java/tools/refinery/logic/literal/BooleanLiteral.java | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.logic.literal; | ||
7 | |||
8 | import tools.refinery.logic.equality.LiteralEqualityHelper; | ||
9 | import tools.refinery.logic.equality.LiteralHashCodeHelper; | ||
10 | import tools.refinery.logic.substitution.Substitution; | ||
11 | import tools.refinery.logic.term.Variable; | ||
12 | |||
13 | import java.util.Set; | ||
14 | |||
15 | public enum BooleanLiteral implements CanNegate<BooleanLiteral> { | ||
16 | TRUE(true), | ||
17 | FALSE(false); | ||
18 | |||
19 | private final boolean value; | ||
20 | |||
21 | BooleanLiteral(boolean value) { | ||
22 | this.value = value; | ||
23 | } | ||
24 | |||
25 | @Override | ||
26 | public Set<Variable> getOutputVariables() { | ||
27 | return Set.of(); | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | public Set<Variable> getInputVariables(Set<? extends Variable> positiveVariablesInClause) { | ||
32 | return Set.of(); | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public Set<Variable> getPrivateVariables(Set<? extends Variable> positiveVariablesInClause) { | ||
37 | return Set.of(); | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public Literal substitute(Substitution substitution) { | ||
42 | // No variables to substitute. | ||
43 | return this; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public BooleanLiteral negate() { | ||
48 | return fromBoolean(!value); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public boolean equalsWithSubstitution(LiteralEqualityHelper helper, Literal other) { | ||
53 | return equals(other); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | public int hashCodeWithSubstitution(LiteralHashCodeHelper helper) { | ||
58 | return hashCode(); | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public String toString() { | ||
63 | return Boolean.toString(value); | ||
64 | } | ||
65 | |||
66 | public static BooleanLiteral fromBoolean(boolean value) { | ||
67 | return value ? TRUE : FALSE; | ||
68 | } | ||
69 | } | ||