blob: c043a2850eaa468c8ecce69080420fd31bc422cc (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.store.query.dnf;
import tools.refinery.store.query.literal.CallLiteral;
import tools.refinery.store.query.literal.CallPolarity;
import tools.refinery.store.query.term.AssignedValue;
import tools.refinery.store.query.term.NodeVariable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public final class RelationalQuery implements Query<Boolean> {
private final Dnf dnf;
RelationalQuery(Dnf dnf) {
for (var parameter : dnf.getSymbolicParameters()) {
var parameterType = parameter.tryGetType();
if (parameterType.isPresent()) {
throw new IllegalArgumentException("Expected parameter %s of %s to be a node variable, got %s instead"
.formatted(parameter, dnf, parameterType.get().getName()));
}
}
this.dnf = dnf;
}
@Override
public String name() {
return dnf.name();
}
@Override
public int arity() {
return dnf.arity();
}
@Override
public Class<Boolean> valueType() {
return Boolean.class;
}
@Override
public Boolean defaultValue() {
return false;
}
@Override
public Dnf getDnf() {
return dnf;
}
public CallLiteral call(CallPolarity polarity, List<NodeVariable> arguments) {
return dnf.call(polarity, Collections.unmodifiableList(arguments));
}
public CallLiteral call(CallPolarity polarity, NodeVariable... arguments) {
return dnf.call(polarity, arguments);
}
public CallLiteral call(NodeVariable... arguments) {
return dnf.call(arguments);
}
public CallLiteral callTransitive(NodeVariable left, NodeVariable right) {
return dnf.callTransitive(left, right);
}
public AssignedValue<Integer> count(List<NodeVariable> arguments) {
return dnf.count(Collections.unmodifiableList(arguments));
}
public AssignedValue<Integer> count(NodeVariable... arguments) {
return dnf.count(arguments);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RelationalQuery that = (RelationalQuery) o;
return dnf.equals(that.dnf);
}
@Override
public int hashCode() {
return Objects.hash(dnf);
}
@Override
public String toString() {
return dnf.toString();
}
}
|