diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/ExternalInputStatelessFilterNode.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/ExternalInputStatelessFilterNode.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/ExternalInputStatelessFilterNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/ExternalInputStatelessFilterNode.java new file mode 100644 index 00000000..57e06911 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/ExternalInputStatelessFilterNode.java | |||
@@ -0,0 +1,68 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, 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.boundary; | ||
10 | |||
11 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
12 | import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext; | ||
13 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
14 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
15 | import tools.refinery.viatra.runtime.rete.matcher.ReteEngine; | ||
16 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
17 | import tools.refinery.viatra.runtime.rete.single.FilterNode; | ||
18 | |||
19 | /** | ||
20 | * A filter node representing a (stateless, typically non-enumerable) extensional input relation. | ||
21 | * | ||
22 | * <p> Contains those tuples of its parents, that (when transformed by a mask, if given) are present in the extensional relation identified by the input key. | ||
23 | * | ||
24 | * @author Bergmann Gabor | ||
25 | * | ||
26 | */ | ||
27 | public class ExternalInputStatelessFilterNode extends FilterNode implements Disconnectable { | ||
28 | |||
29 | IQueryRuntimeContext context = null; | ||
30 | IInputKey inputKey; | ||
31 | private InputConnector inputConnector; | ||
32 | private TupleMask mask; | ||
33 | |||
34 | public ExternalInputStatelessFilterNode(ReteContainer reteContainer, TupleMask mask) { | ||
35 | super(reteContainer); | ||
36 | this.mask = mask; | ||
37 | this.inputConnector = reteContainer.getNetwork().getInputConnector(); | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public boolean check(Tuple ps) { | ||
42 | if (mask != null) | ||
43 | ps = mask.transform(ps); | ||
44 | return context.containsTuple(inputKey, ps); | ||
45 | } | ||
46 | |||
47 | |||
48 | public void connectThroughContext(ReteEngine engine, IInputKey inputKey) { | ||
49 | this.inputKey = inputKey; | ||
50 | setTag(inputKey); | ||
51 | |||
52 | final IQueryRuntimeContext context = engine.getRuntimeContext(); | ||
53 | if (!context.getMetaContext().isStateless(inputKey)) | ||
54 | throw new IllegalArgumentException( | ||
55 | this.getClass().getSimpleName() + | ||
56 | " only applicable for stateless input keys; received instead " + | ||
57 | inputKey); | ||
58 | |||
59 | this.context = context; | ||
60 | |||
61 | engine.addDisconnectable(this); | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | public void disconnect() { | ||
66 | this.context = null; | ||
67 | } | ||
68 | } | ||