diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/CompiledSubPlan.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/CompiledSubPlan.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/CompiledSubPlan.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/CompiledSubPlan.java new file mode 100644 index 00000000..572e943c --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/CompiledSubPlan.java | |||
@@ -0,0 +1,51 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2014, Bergmann Gabor, Istvan Rath and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.rete.traceability; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.Collection; | ||
13 | import java.util.HashSet; | ||
14 | import java.util.List; | ||
15 | import java.util.Set; | ||
16 | import java.util.stream.Collectors; | ||
17 | |||
18 | import tools.refinery.viatra.runtime.matchers.planning.SubPlan; | ||
19 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; | ||
20 | import tools.refinery.viatra.runtime.matchers.util.Preconditions; | ||
21 | import tools.refinery.viatra.runtime.rete.recipes.ReteNodeRecipe; | ||
22 | |||
23 | /** | ||
24 | * A trace marker associating a Rete recipe with a query SubPlan. | ||
25 | * | ||
26 | * <p> The Rete node represented by the recipe is equivalent to the SubPlan. | ||
27 | * <p> Invariant: each variable has at most one index associated with it in the tuple, i.e. no duplicates. | ||
28 | */ | ||
29 | public class CompiledSubPlan extends PlanningTrace { | ||
30 | |||
31 | public CompiledSubPlan(SubPlan subPlan, List<PVariable> variablesTuple, | ||
32 | ReteNodeRecipe recipe, | ||
33 | Collection<? extends RecipeTraceInfo> parentRecipeTraces) { | ||
34 | super(subPlan, variablesTuple, recipe, parentRecipeTraces); | ||
35 | |||
36 | // Make sure that each variable occurs only once | ||
37 | Set<PVariable> variablesSet = new HashSet<PVariable>(variablesTuple); | ||
38 | Preconditions.checkState(variablesSet.size() == variablesTuple.size(), | ||
39 | () -> String.format( | ||
40 | "Illegal column duplication (%s) while the query plan %s was compiled into a Rete Recipe %s", | ||
41 | variablesTuple.stream().map(PVariable::getName).collect(Collectors.joining(",")), | ||
42 | subPlan.toShortString(), recipe)); | ||
43 | } | ||
44 | |||
45 | public CompiledSubPlan(SubPlan subPlan, List<PVariable> variablesTuple, | ||
46 | ReteNodeRecipe recipe, | ||
47 | RecipeTraceInfo... parentRecipeTraces) { | ||
48 | this(subPlan, variablesTuple, recipe, Arrays.asList(parentRecipeTraces)); | ||
49 | } | ||
50 | |||
51 | } | ||