diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/InequalityFilterNode.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/InequalityFilterNode.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/InequalityFilterNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/InequalityFilterNode.java new file mode 100644 index 00000000..8dd3e949 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/InequalityFilterNode.java | |||
@@ -0,0 +1,52 @@ | |||
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 tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
13 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
14 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
15 | |||
16 | /** | ||
17 | * This node filters patterns according to equalities and inequalities of elements. The 'subject' element is asserted to | ||
18 | * be different from the elements given by the inequalityMask. | ||
19 | * | ||
20 | * | ||
21 | * @author Gabor Bergmann | ||
22 | * | ||
23 | */ | ||
24 | public class InequalityFilterNode extends FilterNode { | ||
25 | |||
26 | int subjectIndex; | ||
27 | TupleMask inequalityMask; | ||
28 | |||
29 | /** | ||
30 | * @param reteContainer | ||
31 | * @param subject | ||
32 | * the index of the element that should be compared. | ||
33 | * @param inequalityMask | ||
34 | * the indices of elements that should be different from the subjectIndex. | ||
35 | */ | ||
36 | public InequalityFilterNode(ReteContainer reteContainer, int subject, TupleMask inequalityMask) { | ||
37 | super(reteContainer); | ||
38 | this.subjectIndex = subject; | ||
39 | this.inequalityMask = inequalityMask; | ||
40 | } | ||
41 | |||
42 | @Override | ||
43 | public boolean check(Tuple ps) { | ||
44 | Object subject = ps.get(subjectIndex); | ||
45 | for (int ineq : inequalityMask.indices) { | ||
46 | if (subject.equals(ps.get(ineq))) | ||
47 | return false; | ||
48 | } | ||
49 | return true; | ||
50 | } | ||
51 | |||
52 | } | ||