diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/eval/MemorylessEvaluatorNode.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/eval/MemorylessEvaluatorNode.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/eval/MemorylessEvaluatorNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/eval/MemorylessEvaluatorNode.java new file mode 100644 index 00000000..8928645c --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/eval/MemorylessEvaluatorNode.java | |||
@@ -0,0 +1,75 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, 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.eval; | ||
10 | |||
11 | import java.util.ArrayList; | ||
12 | import java.util.Collection; | ||
13 | import java.util.Iterator; | ||
14 | import java.util.Map; | ||
15 | import java.util.Map.Entry; | ||
16 | |||
17 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
18 | import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; | ||
19 | import tools.refinery.viatra.runtime.matchers.util.Direction; | ||
20 | import tools.refinery.viatra.runtime.matchers.util.timeline.Timeline; | ||
21 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
22 | import tools.refinery.viatra.runtime.rete.network.communication.Timestamp; | ||
23 | |||
24 | /** | ||
25 | * @author Bergmann Gabor | ||
26 | * | ||
27 | */ | ||
28 | public class MemorylessEvaluatorNode extends AbstractEvaluatorNode { | ||
29 | |||
30 | /** | ||
31 | * @since 1.5 | ||
32 | */ | ||
33 | public MemorylessEvaluatorNode(final ReteContainer reteContainer, final EvaluatorCore core) { | ||
34 | super(reteContainer, core); | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public void pullInto(final Collection<Tuple> collector, final boolean flush) { | ||
39 | final Collection<Tuple> parentTuples = new ArrayList<Tuple>(); | ||
40 | propagatePullInto(parentTuples, flush); | ||
41 | for (final Tuple parentTuple : parentTuples) { | ||
42 | final Iterable<Tuple> output = core.performEvaluation(parentTuple); | ||
43 | if (output != null) { | ||
44 | final Iterator<Tuple> itr = output.iterator(); | ||
45 | while (itr.hasNext()) { | ||
46 | collector.add(itr.next()); | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | @Override | ||
53 | public void pullIntoWithTimeline(final Map<Tuple, Timeline<Timestamp>> collector, final boolean flush) { | ||
54 | final Map<Tuple, Timeline<Timestamp>> parentTuples = CollectionsFactory.createMap(); | ||
55 | propagatePullIntoWithTimestamp(parentTuples, flush); | ||
56 | for (final Entry<Tuple, Timeline<Timestamp>> entry : parentTuples.entrySet()) { | ||
57 | final Iterable<Tuple> output = core.performEvaluation(entry.getKey()); | ||
58 | if (output != null) { | ||
59 | final Iterator<Tuple> itr = output.iterator(); | ||
60 | while (itr.hasNext()) { | ||
61 | collector.put(itr.next(), entry.getValue()); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | |||
67 | @Override | ||
68 | public void update(final Direction direction, final Tuple input, final Timestamp timestamp) { | ||
69 | final Iterable<Tuple> output = core.performEvaluation(input); | ||
70 | if (output != null) { | ||
71 | propagateIterableUpdate(direction, output, timestamp); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | } | ||