aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/logic/src/main/java/tools/refinery/logic/literal/ConstantLiteral.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/logic/src/main/java/tools/refinery/logic/literal/ConstantLiteral.java')
-rw-r--r--subprojects/logic/src/main/java/tools/refinery/logic/literal/ConstantLiteral.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/subprojects/logic/src/main/java/tools/refinery/logic/literal/ConstantLiteral.java b/subprojects/logic/src/main/java/tools/refinery/logic/literal/ConstantLiteral.java
new file mode 100644
index 00000000..688ddfa0
--- /dev/null
+++ b/subprojects/logic/src/main/java/tools/refinery/logic/literal/ConstantLiteral.java
@@ -0,0 +1,73 @@
1/*
2 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.logic.literal;
7
8import tools.refinery.logic.equality.LiteralEqualityHelper;
9import tools.refinery.logic.equality.LiteralHashCodeHelper;
10import tools.refinery.logic.substitution.Substitution;
11import tools.refinery.logic.term.NodeVariable;
12import tools.refinery.logic.term.Variable;
13
14import java.util.Objects;
15import java.util.Set;
16
17public class ConstantLiteral extends AbstractLiteral {
18 private final NodeVariable variable;
19 private final int nodeId;
20
21 public ConstantLiteral(NodeVariable variable, int nodeId) {
22 this.variable = variable;
23 this.nodeId = nodeId;
24 }
25
26 public NodeVariable getVariable() {
27 return variable;
28 }
29
30 public int getNodeId() {
31 return nodeId;
32 }
33
34
35 @Override
36 public Set<Variable> getOutputVariables() {
37 return Set.of(variable);
38 }
39
40 @Override
41 public Set<Variable> getInputVariables(Set<? extends Variable> positiveVariablesInClause) {
42 return Set.of();
43 }
44
45 @Override
46 public Set<Variable> getPrivateVariables(Set<? extends Variable> positiveVariablesInClause) {
47 return Set.of();
48 }
49
50 @Override
51 public ConstantLiteral substitute(Substitution substitution) {
52 return new ConstantLiteral(substitution.getTypeSafeSubstitute(variable), nodeId);
53 }
54
55 @Override
56 public boolean equalsWithSubstitution(LiteralEqualityHelper helper, Literal other) {
57 if (other.getClass() != getClass()) {
58 return false;
59 }
60 var otherConstantLiteral = (ConstantLiteral) other;
61 return helper.variableEqual(variable, otherConstantLiteral.variable) && nodeId == otherConstantLiteral.nodeId;
62 }
63
64 @Override
65 public int hashCodeWithSubstitution(LiteralHashCodeHelper helper) {
66 return Objects.hash(super.hashCodeWithSubstitution(helper), helper.getVariableHashCode(variable), nodeId);
67 }
68
69 @Override
70 public String toString() {
71 return "%s === @Constant %d".formatted(variable, nodeId);
72 }
73}