aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/DiscriminatorBucketNode.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/DiscriminatorBucketNode.java')
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/DiscriminatorBucketNode.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/DiscriminatorBucketNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/DiscriminatorBucketNode.java
new file mode 100644
index 00000000..803bab20
--- /dev/null
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/DiscriminatorBucketNode.java
@@ -0,0 +1,85 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2016, Gabor Bergmann, IncQueryLabs 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 *******************************************************************************/
9package tools.refinery.viatra.runtime.rete.single;
10
11import java.util.Collection;
12import java.util.Map;
13
14import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext;
15import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
16import tools.refinery.viatra.runtime.matchers.util.Direction;
17import tools.refinery.viatra.runtime.matchers.util.timeline.Timeline;
18import tools.refinery.viatra.runtime.rete.network.ReteContainer;
19import tools.refinery.viatra.runtime.rete.network.Supplier;
20import tools.refinery.viatra.runtime.rete.network.communication.Timestamp;
21
22/**
23 * A bucket holds a filtered set of tuples of its parent {@link DiscriminatorDispatcherNode}.
24 * Exactly those that have the given bucket key at their discrimination column.
25 *
26 * <p> During operation, tuple contents and bucket keys have already been wrapped using {@link IQueryRuntimeContext#wrapElement(Object)}
27 *
28 * @author Gabor Bergmann
29 * @since 1.5
30 */
31public class DiscriminatorBucketNode extends SingleInputNode {
32
33 private Object bucketKey;
34
35 /**
36 * @param bucketKey will be wrapped using {@link IQueryRuntimeContext#wrapElement(Object)}
37
38 */
39 public DiscriminatorBucketNode(ReteContainer reteContainer, Object bucketKey) {
40 super(reteContainer);
41 this.bucketKey = reteContainer.getNetwork().getEngine().getRuntimeContext().wrapElement(bucketKey);
42 }
43
44 @Override
45 public void pullInto(final Collection<Tuple> collector, final boolean flush) {
46 if (parent != null) {
47 getDispatcher().pullIntoFiltered(collector, bucketKey, flush);
48 }
49 }
50
51 @Override
52 public void pullIntoWithTimeline(final Map<Tuple, Timeline<Timestamp>> collector, final boolean flush) {
53 if (parent != null) {
54 getDispatcher().pullIntoWithTimestampFiltered(collector, bucketKey, flush);
55 }
56 }
57
58 @Override
59 public void update(Direction direction, Tuple updateElement, Timestamp timestamp) {
60 propagateUpdate(direction, updateElement, timestamp);
61 }
62
63 public Object getBucketKey() {
64 return bucketKey;
65 }
66
67 @Override
68 public void appendParent(Supplier supplier) {
69 if (! (supplier instanceof DiscriminatorDispatcherNode))
70 throw new IllegalArgumentException();
71 super.appendParent(supplier);
72 }
73
74 public DiscriminatorDispatcherNode getDispatcher() {
75 return (DiscriminatorDispatcherNode) parent;
76 }
77
78 @Override
79 protected String toStringCore() {
80 return String.format("%s<%s=='%s'>",
81 super.toStringCore(),
82 (getDispatcher() == null) ? "?" : getDispatcher().getDiscriminationColumnIndex(),
83 bucketKey);
84 }
85}