diff options
Diffstat (limited to 'subprojects/logic/src/main/java/tools/refinery/logic/term/NodeVariable.java')
-rw-r--r-- | subprojects/logic/src/main/java/tools/refinery/logic/term/NodeVariable.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/subprojects/logic/src/main/java/tools/refinery/logic/term/NodeVariable.java b/subprojects/logic/src/main/java/tools/refinery/logic/term/NodeVariable.java new file mode 100644 index 00000000..1a5f2657 --- /dev/null +++ b/subprojects/logic/src/main/java/tools/refinery/logic/term/NodeVariable.java | |||
@@ -0,0 +1,71 @@ | |||
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.term; | ||
7 | |||
8 | import org.jetbrains.annotations.Nullable; | ||
9 | import tools.refinery.logic.InvalidQueryException; | ||
10 | import tools.refinery.logic.literal.ConstantLiteral; | ||
11 | import tools.refinery.logic.literal.EquivalenceLiteral; | ||
12 | |||
13 | import java.util.Optional; | ||
14 | |||
15 | public final class NodeVariable extends Variable { | ||
16 | NodeVariable(@Nullable String name) { | ||
17 | super(name); | ||
18 | } | ||
19 | |||
20 | @Override | ||
21 | public Optional<Class<?>> tryGetType() { | ||
22 | return Optional.empty(); | ||
23 | } | ||
24 | |||
25 | @Override | ||
26 | public NodeVariable renew(@Nullable String name) { | ||
27 | return of(name); | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | public NodeVariable renew() { | ||
32 | return renew(getExplicitName()); | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public boolean isNodeVariable() { | ||
37 | return true; | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public boolean isDataVariable() { | ||
42 | return false; | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public NodeVariable asNodeVariable() { | ||
47 | return this; | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public <T> DataVariable<T> asDataVariable(Class<T> type) { | ||
52 | throw new InvalidQueryException("%s is a node variable".formatted(this)); | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public int hashCodeWithSubstitution(int sequenceNumber) { | ||
57 | return sequenceNumber; | ||
58 | } | ||
59 | |||
60 | public ConstantLiteral isConstant(int value) { | ||
61 | return new ConstantLiteral(this, value); | ||
62 | } | ||
63 | |||
64 | public EquivalenceLiteral isEquivalent(NodeVariable other) { | ||
65 | return new EquivalenceLiteral(true, this, other); | ||
66 | } | ||
67 | |||
68 | public EquivalenceLiteral notEquivalent(NodeVariable other) { | ||
69 | return new EquivalenceLiteral(false, this, other); | ||
70 | } | ||
71 | } | ||