diff options
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/PlanDescriptor.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/PlanDescriptor.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/PlanDescriptor.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/PlanDescriptor.java new file mode 100644 index 00000000..a5565546 --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/PlanDescriptor.java | |||
@@ -0,0 +1,84 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Grill Balázs, IncQuery Labs Ltd. | ||
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.localsearch.plan; | ||
10 | |||
11 | import java.util.ArrayList; | ||
12 | import java.util.Collection; | ||
13 | import java.util.Collections; | ||
14 | import java.util.HashSet; | ||
15 | import java.util.List; | ||
16 | import java.util.Set; | ||
17 | import java.util.stream.Collectors; | ||
18 | |||
19 | import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
21 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
22 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PParameter; | ||
23 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery; | ||
24 | |||
25 | /** | ||
26 | * @author Grill Balázs | ||
27 | * @since 1.4 | ||
28 | * | ||
29 | */ | ||
30 | public class PlanDescriptor implements IPlanDescriptor { | ||
31 | |||
32 | private final PQuery pquery; | ||
33 | private final List<SearchPlanForBody> plan; | ||
34 | private final Set<PParameter> adornment; | ||
35 | private Set<IInputKey> iteratedKeys = null; | ||
36 | |||
37 | public PlanDescriptor(PQuery pquery, Collection<SearchPlanForBody> plan, Set<PParameter> adornment) { | ||
38 | this.pquery = pquery; | ||
39 | this.plan = new ArrayList<>(plan); | ||
40 | this.adornment = adornment; | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public PQuery getQuery() { | ||
45 | return pquery; | ||
46 | } | ||
47 | |||
48 | @Override | ||
49 | public Collection<SearchPlanForBody> getPlan() { | ||
50 | return plan; | ||
51 | } | ||
52 | |||
53 | @Override | ||
54 | public Set<PParameter> getAdornment() { | ||
55 | return adornment; | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | public Set<IInputKey> getIteratedKeys() { | ||
60 | if (iteratedKeys == null){ | ||
61 | Set<IInputKey> keys = new HashSet<>(); | ||
62 | for(SearchPlanForBody bodyPlan : plan){ | ||
63 | for(ISearchOperation operation : bodyPlan.getCompiledOperations()){ | ||
64 | if (operation instanceof IIteratingSearchOperation){ | ||
65 | keys.add(((IIteratingSearchOperation) operation).getIteratedInputKey()); | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | iteratedKeys = Collections.unmodifiableSet(keys); | ||
70 | } | ||
71 | return iteratedKeys; | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public String toString() { | ||
76 | return new StringBuilder().append("Plan for ").append(pquery.getFullyQualifiedName()).append("(") | ||
77 | .append(adornment.stream().map(PParameter::getName).collect(Collectors.joining(","))) | ||
78 | .append("{") | ||
79 | .append(plan.stream().map(Object::toString).collect(Collectors.joining("}\n{"))) | ||
80 | .append("}") | ||
81 | .toString(); | ||
82 | } | ||
83 | |||
84 | } | ||