diff options
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/CountOperation.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/CountOperation.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/CountOperation.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/CountOperation.java new file mode 100644 index 00000000..08ecc8d6 --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/CountOperation.java | |||
@@ -0,0 +1,88 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, 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.localsearch.operations.extend; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.List; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
17 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
18 | import tools.refinery.viatra.runtime.localsearch.operations.IPatternMatcherOperation; | ||
19 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.util.CallInformation; | ||
21 | import tools.refinery.viatra.runtime.matchers.backend.IQueryResultProvider; | ||
22 | import tools.refinery.viatra.runtime.matchers.tuple.VolatileModifiableMaskedTuple; | ||
23 | |||
24 | /** | ||
25 | * Calculates the count of matches for a called matcher | ||
26 | * | ||
27 | * @author Zoltan Ujhelyi | ||
28 | */ | ||
29 | public class CountOperation implements ISearchOperation, IPatternMatcherOperation{ | ||
30 | |||
31 | private class Executor extends SingleValueExtendOperationExecutor<Integer> { | ||
32 | private final VolatileModifiableMaskedTuple maskedTuple; | ||
33 | private IQueryResultProvider matcher; | ||
34 | |||
35 | public Executor(int position) { | ||
36 | super(position); | ||
37 | maskedTuple = new VolatileModifiableMaskedTuple(information.getThinFrameMask()); | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public Iterator<Integer> getIterator(MatchingFrame frame, ISearchContext context) { | ||
42 | matcher = context.getMatcher(information.getCallWithAdornment()); | ||
43 | maskedTuple.updateTuple(frame); | ||
44 | return Collections.singletonList(matcher.countMatches(information.getParameterMask(), maskedTuple)).iterator(); | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public ISearchOperation getOperation() { | ||
49 | return CountOperation.this; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | private final CallInformation information; | ||
54 | private final int position; | ||
55 | |||
56 | /** | ||
57 | * @since 1.7 | ||
58 | */ | ||
59 | public CountOperation(CallInformation information, int position) { | ||
60 | this.information = information; | ||
61 | this.position = position; | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | public ISearchOperationExecutor createExecutor() { | ||
66 | return new Executor(position); | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public List<Integer> getVariablePositions() { | ||
71 | return information.getVariablePositions(); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public String toString() { | ||
76 | return toString(Object::toString); | ||
77 | } | ||
78 | |||
79 | @Override | ||
80 | public String toString(Function<Integer, String> variableMapping) { | ||
81 | return "extend -"+variableMapping.apply(position)+" = count find " + information.toString(variableMapping); | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public CallInformation getCallInformation() { | ||
86 | return information; | ||
87 | } | ||
88 | } | ||