diff options
author | 2023-06-18 14:31:05 +0200 | |
---|---|---|
committer | 2023-06-18 16:44:15 +0200 | |
commit | cd4d5aecd2c1ceedc49657f315d3a543b48779c5 (patch) | |
tree | 820b1ab5087474b7ca74cda611d33128ccf1fde7 /subprojects/store-query/src/main/java | |
parent | refactor: clean up Symbol constructor (diff) | |
download | refinery-cd4d5aecd2c1ceedc49657f315d3a543b48779c5.tar.gz refinery-cd4d5aecd2c1ceedc49657f315d3a543b48779c5.tar.zst refinery-cd4d5aecd2c1ceedc49657f315d3a543b48779c5.zip |
refactor: prefer Query.of over Dnf.of
Diffstat (limited to 'subprojects/store-query/src/main/java')
3 files changed, 24 insertions, 8 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/Constraint.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/Constraint.java index c0995e53..916fb35c 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/Constraint.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/Constraint.java | |||
@@ -60,13 +60,13 @@ public interface Constraint { | |||
60 | return count(List.of(arguments)); | 60 | return count(List.of(arguments)); |
61 | } | 61 | } |
62 | 62 | ||
63 | default <R, T> AssignedValue<R> aggregate(DataVariable<T> inputVariable, Aggregator<R, T> aggregator, | 63 | default <R, T> AssignedValue<R> aggregateBy(DataVariable<T> inputVariable, Aggregator<R, T> aggregator, |
64 | List<Variable> arguments) { | 64 | List<Variable> arguments) { |
65 | return targetVariable -> new AggregationLiteral<>(targetVariable, aggregator, inputVariable, this, arguments); | 65 | return targetVariable -> new AggregationLiteral<>(targetVariable, aggregator, inputVariable, this, arguments); |
66 | } | 66 | } |
67 | 67 | ||
68 | default <R, T> AssignedValue<R> aggregate(DataVariable<T> inputVariable, Aggregator<R, T> aggregator, | 68 | default <R, T> AssignedValue<R> aggregateBy(DataVariable<T> inputVariable, Aggregator<R, T> aggregator, |
69 | Variable... arguments) { | 69 | Variable... arguments) { |
70 | return aggregate(inputVariable, aggregator, List.of(arguments)); | 70 | return aggregateBy(inputVariable, aggregator, List.of(arguments)); |
71 | } | 71 | } |
72 | } | 72 | } |
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/FunctionalQuery.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/FunctionalQuery.java index 6f253012..5a32b1ba 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/FunctionalQuery.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/FunctionalQuery.java | |||
@@ -74,7 +74,7 @@ public final class FunctionalQuery<T> extends Query<T> { | |||
74 | argumentsWithPlaceholder.addAll(arguments); | 74 | argumentsWithPlaceholder.addAll(arguments); |
75 | argumentsWithPlaceholder.add(placeholderVariable); | 75 | argumentsWithPlaceholder.add(placeholderVariable); |
76 | return getDnf() | 76 | return getDnf() |
77 | .aggregate(placeholderVariable, aggregator, argumentsWithPlaceholder) | 77 | .aggregateBy(placeholderVariable, aggregator, argumentsWithPlaceholder) |
78 | .toLiteral(targetVariable); | 78 | .toLiteral(targetVariable); |
79 | }; | 79 | }; |
80 | } | 80 | } |
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/view/FunctionView.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/view/FunctionView.java index 1b89e77c..74a5be07 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/view/FunctionView.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/view/FunctionView.java | |||
@@ -5,10 +5,12 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.query.view; | 6 | package tools.refinery.store.query.view; |
7 | 7 | ||
8 | import tools.refinery.store.query.term.Parameter; | 8 | import tools.refinery.store.query.term.*; |
9 | import tools.refinery.store.query.term.ParameterDirection; | ||
10 | import tools.refinery.store.representation.Symbol; | 9 | import tools.refinery.store.representation.Symbol; |
11 | 10 | ||
11 | import java.util.ArrayList; | ||
12 | import java.util.List; | ||
13 | |||
12 | public final class FunctionView<T> extends AbstractFunctionView<T> { | 14 | public final class FunctionView<T> extends AbstractFunctionView<T> { |
13 | public FunctionView(Symbol<T> symbol, String name) { | 15 | public FunctionView(Symbol<T> symbol, String name) { |
14 | super(symbol, name, new Parameter(symbol.valueType(), ParameterDirection.OUT)); | 16 | super(symbol, name, new Parameter(symbol.valueType(), ParameterDirection.OUT)); |
@@ -17,4 +19,18 @@ public final class FunctionView<T> extends AbstractFunctionView<T> { | |||
17 | public FunctionView(Symbol<T> symbol) { | 19 | public FunctionView(Symbol<T> symbol) { |
18 | this(symbol, "function"); | 20 | this(symbol, "function"); |
19 | } | 21 | } |
22 | |||
23 | public <R> AssignedValue<R> aggregate(Aggregator<R, T> aggregator, List<NodeVariable> arguments) { | ||
24 | return targetVariable -> { | ||
25 | var placeholderVariable = Variable.of(getSymbol().valueType()); | ||
26 | var argumentsWithPlaceholder = new ArrayList<Variable>(arguments.size() + 1); | ||
27 | argumentsWithPlaceholder.addAll(arguments); | ||
28 | argumentsWithPlaceholder.add(placeholderVariable); | ||
29 | return aggregateBy(placeholderVariable, aggregator, argumentsWithPlaceholder).toLiteral(targetVariable); | ||
30 | }; | ||
31 | } | ||
32 | |||
33 | public <R> AssignedValue<R> aggregate(Aggregator<R, T> aggregator, NodeVariable... arguments) { | ||
34 | return aggregate(aggregator, List.of(arguments)); | ||
35 | } | ||
20 | } | 36 | } |