diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/TransformerNode.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/TransformerNode.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/TransformerNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/TransformerNode.java new file mode 100644 index 00000000..24750656 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/TransformerNode.java | |||
@@ -0,0 +1,49 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2004-2008 Gabor Bergmann 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 | |||
10 | package tools.refinery.viatra.runtime.rete.single; | ||
11 | |||
12 | import java.util.Collection; | ||
13 | import java.util.Map; | ||
14 | import java.util.Map.Entry; | ||
15 | |||
16 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
17 | import tools.refinery.viatra.runtime.matchers.util.Direction; | ||
18 | import tools.refinery.viatra.runtime.matchers.util.timeline.Timeline; | ||
19 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
20 | import tools.refinery.viatra.runtime.rete.network.communication.Timestamp; | ||
21 | |||
22 | public abstract class TransformerNode extends SingleInputNode { | ||
23 | |||
24 | public TransformerNode(final ReteContainer reteContainer) { | ||
25 | super(reteContainer); | ||
26 | } | ||
27 | |||
28 | protected abstract Tuple transform(final Tuple input); | ||
29 | |||
30 | @Override | ||
31 | public void pullInto(final Collection<Tuple> collector, final boolean flush) { | ||
32 | for (Tuple ps : reteContainer.pullPropagatedContents(this, flush)) { | ||
33 | collector.add(transform(ps)); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public void pullIntoWithTimeline(final Map<Tuple, Timeline<Timestamp>> collector, final boolean flush) { | ||
39 | for (final Entry<Tuple, Timeline<Timestamp>> entry : reteContainer.pullPropagatedContentsWithTimestamp(this, flush).entrySet()) { | ||
40 | collector.put(transform(entry.getKey()), entry.getValue()); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public void update(final Direction direction, final Tuple updateElement, final Timestamp timestamp) { | ||
46 | propagateUpdate(direction, transform(updateElement), timestamp); | ||
47 | } | ||
48 | |||
49 | } | ||