aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-rete
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-rete')
-rw-r--r--subprojects/viatra-runtime-rete/build.gradle.kts4
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/matcher/RetePatternMatcher.java10
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ConnectionFactory.java21
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Network.java64
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java5
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationTracker.java35
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/util/OrderingCompareAgent.java19
7 files changed, 71 insertions, 87 deletions
diff --git a/subprojects/viatra-runtime-rete/build.gradle.kts b/subprojects/viatra-runtime-rete/build.gradle.kts
index 7e795a90..560e8854 100644
--- a/subprojects/viatra-runtime-rete/build.gradle.kts
+++ b/subprojects/viatra-runtime-rete/build.gradle.kts
@@ -6,6 +6,10 @@
6 6
7plugins { 7plugins {
8 id("tools.refinery.gradle.java-library") 8 id("tools.refinery.gradle.java-library")
9 // Vendor code from Eclipse VIATRA is maintained by the VIATRA project,
10 // so we don't need to keep track of coverage ourselves.
11 // Our own modifications are covered by tests in the `store-query-viatra` subproject.
12 id("tools.refinery.gradle.skip-coverage")
9} 13}
10 14
11dependencies { 15dependencies {
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/matcher/RetePatternMatcher.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/matcher/RetePatternMatcher.java
index 38fe7c2f..5f0f1892 100644
--- a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/matcher/RetePatternMatcher.java
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/matcher/RetePatternMatcher.java
@@ -31,10 +31,8 @@ import tools.refinery.viatra.runtime.rete.single.TransformerNode;
31import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo; 31import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo;
32 32
33import java.util.Collection; 33import java.util.Collection;
34import java.util.List;
35import java.util.Map; 34import java.util.Map;
36import java.util.Optional; 35import java.util.Optional;
37import java.util.stream.Collectors;
38import java.util.stream.Stream; 36import java.util.stream.Stream;
39 37
40/** 38/**
@@ -78,14 +76,6 @@ public class RetePatternMatcher extends TransformerNode implements IQueryResultP
78 return productionNode; 76 return productionNode;
79 } 77 }
80 78
81 public Tuple matchOneRandomly(Object[] inputMapping, boolean[] fixed) {
82 List<Tuple> allMatches = matchAll(inputMapping, fixed).collect(Collectors.toList());
83 if (allMatches == null || allMatches.isEmpty())
84 return null;
85 else
86 return allMatches.get((int) (Math.random() * allMatches.size()));
87 }
88
89 /** 79 /**
90 * @since 2.0 80 * @since 2.0
91 */ 81 */
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ConnectionFactory.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ConnectionFactory.java
index b261d19d..bd4d9bf2 100644
--- a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ConnectionFactory.java
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ConnectionFactory.java
@@ -132,17 +132,16 @@ class ConnectionFactory {
132 * @return a replacement for the secondary Indexers, if needed 132 * @return a replacement for the secondary Indexers, if needed
133 */ 133 */
134 private Slots avoidActiveNodeConflict(final RecipeTraceInfo primarySlot, final RecipeTraceInfo secondarySlot) { 134 private Slots avoidActiveNodeConflict(final RecipeTraceInfo primarySlot, final RecipeTraceInfo secondarySlot) {
135 Slots result = new Slots() { 135 Slots result = new Slots();
136 { 136 result.primary = (IterableIndexer) resolveIndexer((ProjectionIndexerRecipe) primarySlot.getRecipe());
137 primary = (IterableIndexer) resolveIndexer((ProjectionIndexerRecipe) primarySlot.getRecipe()); 137 result.secondary = resolveIndexer((IndexerRecipe) secondarySlot.getRecipe());
138 secondary = resolveIndexer((IndexerRecipe) secondarySlot.getRecipe()); 138 if (activeNodeConflict(result.primary, result.secondary)) {
139 } 139 if (result.secondary instanceof IterableIndexer) {
140 }; 140 result.secondary = resolveActiveIndexer(secondarySlot);
141 if (activeNodeConflict(result.primary, result.secondary)) 141 } else {
142 if (result.secondary instanceof IterableIndexer) 142 result.primary = (IterableIndexer) resolveActiveIndexer(primarySlot);
143 result.secondary = resolveActiveIndexer(secondarySlot); 143 }
144 else 144 }
145 result.primary = (IterableIndexer) resolveActiveIndexer(primarySlot);
146 return result; 145 return result;
147 } 146 }
148 147
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Network.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Network.java
index 64f59ff3..61030ff2 100644
--- a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Network.java
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Network.java
@@ -3,23 +3,12 @@
3 * This program and the accompanying materials are made available under the 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 4 * terms of the Eclipse Public License v. 2.0 which is available at
5 * http://www.eclipse.org/legal/epl-v20.html. 5 * http://www.eclipse.org/legal/epl-v20.html.
6 * 6 *
7 * SPDX-License-Identifier: EPL-2.0 7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/ 8 *******************************************************************************/
9 9
10package tools.refinery.viatra.runtime.rete.network; 10package tools.refinery.viatra.runtime.rete.network;
11 11
12import java.util.ArrayList;
13import java.util.Collection;
14import java.util.Collections;
15import java.util.List;
16import java.util.Map;
17import java.util.Map.Entry;
18import java.util.Set;
19import java.util.concurrent.locks.Lock;
20import java.util.concurrent.locks.ReadWriteLock;
21import java.util.concurrent.locks.ReentrantReadWriteLock;
22
23import tools.refinery.viatra.runtime.matchers.tuple.Tuple; 12import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
24import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; 13import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory;
25import tools.refinery.viatra.runtime.matchers.util.Direction; 14import tools.refinery.viatra.runtime.matchers.util.Direction;
@@ -30,9 +19,15 @@ import tools.refinery.viatra.runtime.rete.remote.Address;
30import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo; 19import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo;
31import tools.refinery.viatra.runtime.rete.util.Options; 20import tools.refinery.viatra.runtime.rete.util.Options;
32 21
22import java.util.*;
23import java.util.Map.Entry;
24import java.util.concurrent.locks.Lock;
25import java.util.concurrent.locks.ReadWriteLock;
26import java.util.concurrent.locks.ReentrantReadWriteLock;
27
33/** 28/**
34 * @author Gabor Bergmann 29 * @author Gabor Bergmann
35 * 30 *
36 */ 31 */
37public class Network { 32public class Network {
38 final int threads; 33 final int threads;
@@ -43,7 +38,7 @@ public class Network {
43 private int nextContainer = 0; 38 private int nextContainer = 0;
44 39
45 // the following fields exist only if threads > 0 40 // the following fields exist only if threads > 0
46 protected Map<ReteContainer, Long> globalTerminationCriteria = null; 41 protected final Map<ReteContainer, Long> globalTerminationCriteria;
47 protected Map<ReteContainer, Long> reportedClocks = null; 42 protected Map<ReteContainer, Long> reportedClocks = null;
48 protected Lock updateLock = null; // grab during normal update operations 43 protected Lock updateLock = null; // grab during normal update operations
49 protected Lock structuralChangeLock = null; // grab if the network structure 44 protected Lock structuralChangeLock = null; // grab if the network structure
@@ -104,9 +99,10 @@ public class Network {
104 structuralChangeLock = rwl.writeLock(); 99 structuralChangeLock = rwl.writeLock();
105 for (int i = 0; i < threads; ++i) 100 for (int i = 0; i < threads; ++i)
106 containers.add(new ReteContainer(this, true)); 101 containers.add(new ReteContainer(this, true));
107 } else 102 } else {
108 containers.add(new ReteContainer(this, false)); 103 containers.add(new ReteContainer(this, false));
109 104 globalTerminationCriteria = null;
105 }
110 headContainer = containers.get(0); 106 headContainer = containers.get(0);
111 } 107 }
112 108
@@ -138,7 +134,7 @@ public class Network {
138 134
139 /** 135 /**
140 * Internal message delivery method. 136 * Internal message delivery method.
141 * 137 *
142 * @pre threads > 0 138 * @pre threads > 0
143 */ 139 */
144 private void sendUpdate(Address<? extends Receiver> receiver, Direction direction, Tuple updateElement) { 140 private void sendUpdate(Address<? extends Receiver> receiver, Direction direction, Tuple updateElement) {
@@ -151,7 +147,7 @@ public class Network {
151 147
152 /** 148 /**
153 * Internal message delivery method for single-threaded operation 149 * Internal message delivery method for single-threaded operation
154 * 150 *
155 * @pre threads == 0 151 * @pre threads == 0
156 */ 152 */
157 private void sendUpdateSingleThreaded(Address<? extends Receiver> receiver, Direction direction, 153 private void sendUpdateSingleThreaded(Address<? extends Receiver> receiver, Direction direction,
@@ -162,7 +158,7 @@ public class Network {
162 158
163 /** 159 /**
164 * Internal message delivery method. 160 * Internal message delivery method.
165 * 161 *
166 * @pre threads > 0 162 * @pre threads > 0
167 */ 163 */
168 private void sendUpdates(Address<? extends Receiver> receiver, Direction direction, 164 private void sendUpdates(Address<? extends Receiver> receiver, Direction direction,
@@ -180,7 +176,7 @@ public class Network {
180 * Sends an update message to the receiver node, indicating a newly found or lost partial matching. The node may 176 * Sends an update message to the receiver node, indicating a newly found or lost partial matching. The node may
181 * reside in any of the containers associated with this network. To be called from a user thread during normal 177 * reside in any of the containers associated with this network. To be called from a user thread during normal
182 * operation, NOT during construction. 178 * operation, NOT during construction.
183 * 179 *
184 * @since 2.4 180 * @since 2.4
185 */ 181 */
186 public void sendExternalUpdate(Address<? extends Receiver> receiver, Direction direction, Tuple updateElement) { 182 public void sendExternalUpdate(Address<? extends Receiver> receiver, Direction direction, Tuple updateElement) {
@@ -201,10 +197,10 @@ public class Network {
201 * Sends an update message to the receiver node, indicating a newly found or lost partial matching. The node may 197 * Sends an update message to the receiver node, indicating a newly found or lost partial matching. The node may
202 * reside in any of the containers associated with this network. To be called from a user thread during 198 * reside in any of the containers associated with this network. To be called from a user thread during
203 * construction. 199 * construction.
204 * 200 *
205 * @pre: structuralChangeLock MUST be grabbed by the sequence (but not necessarily this thread, as the sequence may 201 * @pre: structuralChangeLock MUST be grabbed by the sequence (but not necessarily this thread, as the sequence may
206 * span through network calls, that's why it's not enforced here ) 202 * span through network calls, that's why it's not enforced here )
207 * 203 *
208 * @return the value of the target container's clock at the time when the message was accepted into its message 204 * @return the value of the target container's clock at the time when the message was accepted into its message
209 * queue 205 * queue
210 * @since 2.4 206 * @since 2.4
@@ -222,10 +218,10 @@ public class Network {
222 * Sends multiple update messages atomically to the receiver node, indicating a newly found or lost partial 218 * Sends multiple update messages atomically to the receiver node, indicating a newly found or lost partial
223 * matching. The node may reside in any of the containers associated with this network. To be called from a user 219 * matching. The node may reside in any of the containers associated with this network. To be called from a user
224 * thread during construction. 220 * thread during construction.
225 * 221 *
226 * @pre: structuralChangeLock MUST be grabbed by the sequence (but not necessarily this thread, as the sequence may 222 * @pre: structuralChangeLock MUST be grabbed by the sequence (but not necessarily this thread, as the sequence may
227 * span through network calls, that's why it's not enforced here ) 223 * span through network calls, that's why it's not enforced here )
228 * 224 *
229 * @since 2.4 225 * @since 2.4
230 */ 226 */
231 public void sendConstructionUpdates(Address<? extends Receiver> receiver, Direction direction, 227 public void sendConstructionUpdates(Address<? extends Receiver> receiver, Direction direction,
@@ -241,7 +237,7 @@ public class Network {
241 /** 237 /**
242 * Establishes connection between a supplier and a receiver node, regardless which container they are in. Not to be 238 * Establishes connection between a supplier and a receiver node, regardless which container they are in. Not to be
243 * called remotely, because this method enforces the structural lock. 239 * called remotely, because this method enforces the structural lock.
244 * 240 *
245 * @param supplier 241 * @param supplier
246 * @param receiver 242 * @param receiver
247 * @param synchronise 243 * @param synchronise
@@ -262,7 +258,7 @@ public class Network {
262 /** 258 /**
263 * Severs connection between a supplier and a receiver node, regardless which container they are in. Not to be 259 * Severs connection between a supplier and a receiver node, regardless which container they are in. Not to be
264 * called remotely, because this method enforces the structural lock. 260 * called remotely, because this method enforces the structural lock.
265 * 261 *
266 * @param supplier 262 * @param supplier
267 * @param receiver 263 * @param receiver
268 * @param desynchronise 264 * @param desynchronise
@@ -282,9 +278,9 @@ public class Network {
282 278
283 /** 279 /**
284 * Containers use this method to report whenever they run out of messages in their queue. 280 * Containers use this method to report whenever they run out of messages in their queue.
285 * 281 *
286 * To be called from the thread of the reporting container. 282 * To be called from the thread of the reporting container.
287 * 283 *
288 * @pre threads > 0. 284 * @pre threads > 0.
289 * @param reportingContainer 285 * @param reportingContainer
290 * the container reporting the emptiness of its message queue. 286 * the container reporting the emptiness of its message queue.
@@ -328,7 +324,7 @@ public class Network {
328 /** 324 /**
329 * Waits until all rete update operations are settled in all containers. Returns immediately, if no updates are 325 * Waits until all rete update operations are settled in all containers. Returns immediately, if no updates are
330 * pending. 326 * pending.
331 * 327 *
332 * To be called from any user thread. 328 * To be called from any user thread.
333 */ 329 */
334 public void waitForReteTermination() { 330 public void waitForReteTermination() {
@@ -338,7 +334,7 @@ public class Network {
338 try { 334 try {
339 globalTerminationCriteria.wait(); 335 globalTerminationCriteria.wait();
340 } catch (InterruptedException e) { 336 } catch (InterruptedException e) {
341 337 Thread.currentThread().interrupt();
342 } 338 }
343 } 339 }
344 } 340 }
@@ -350,10 +346,10 @@ public class Network {
350 * Waits to execute action until all rete update operations are settled in all containers. Runs action and returns 346 * Waits to execute action until all rete update operations are settled in all containers. Runs action and returns
351 * immediately, if no updates are pending. The given action is guaranteed to be run when the terminated state still 347 * immediately, if no updates are pending. The given action is guaranteed to be run when the terminated state still
352 * persists. 348 * persists.
353 * 349 *
354 * @param action 350 * @param action
355 * the action to be run when reaching the steady-state. 351 * the action to be run when reaching the steady-state.
356 * 352 *
357 * To be called from any user thread. 353 * To be called from any user thread.
358 */ 354 */
359 public void waitForReteTermination(Runnable action) { 355 public void waitForReteTermination(Runnable action) {
@@ -363,7 +359,7 @@ public class Network {
363 try { 359 try {
364 globalTerminationCriteria.wait(); 360 globalTerminationCriteria.wait();
365 } catch (InterruptedException e) { 361 } catch (InterruptedException e) {
366 362 Thread.currentThread().interrupt();
367 } 363 }
368 } 364 }
369 action.run(); 365 action.run();
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java
index 79e0526d..d058417f 100644
--- a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java
@@ -514,6 +514,7 @@ public final class ReteContainer {
514 try { 514 try {
515 externalMessageLock.wait(); 515 externalMessageLock.wait();
516 } catch (InterruptedException e) { 516 } catch (InterruptedException e) {
517 Thread.currentThread().interrupt();
517 if (killed) 518 if (killed)
518 return; 519 return;
519 } 520 }
@@ -565,7 +566,9 @@ public final class ReteContainer {
565 + group.getRepresentative() + " has already been processed!"); 566 + group.getRepresentative() + " has already been processed!");
566 } 567 }
567 568
568 group.deliverMessages(); 569 if (group != null) {
570 group.deliverMessages();
571 }
569 572
570 lastGroup = group; 573 lastGroup = group;
571 } 574 }
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationTracker.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationTracker.java
index d244e644..9c2fbb9a 100644
--- a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationTracker.java
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationTracker.java
@@ -8,33 +8,15 @@
8 *******************************************************************************/ 8 *******************************************************************************/
9package tools.refinery.viatra.runtime.rete.network.communication; 9package tools.refinery.viatra.runtime.rete.network.communication;
10 10
11import java.util.HashMap;
12import java.util.HashSet;
13import java.util.List;
14import java.util.Map;
15import java.util.PriorityQueue;
16import java.util.Queue;
17import java.util.Set;
18
19import tools.refinery.viatra.runtime.rete.itc.alg.incscc.IncSCCAlg;
20import tools.refinery.viatra.runtime.rete.itc.alg.misc.topsort.TopologicalSorting;
21import tools.refinery.viatra.runtime.rete.itc.graphimpl.Graph;
22import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; 11import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
23import tools.refinery.viatra.runtime.rete.aggregation.IAggregatorNode; 12import tools.refinery.viatra.runtime.rete.aggregation.IAggregatorNode;
24import tools.refinery.viatra.runtime.rete.boundary.ExternalInputEnumeratorNode; 13import tools.refinery.viatra.runtime.rete.boundary.ExternalInputEnumeratorNode;
25import tools.refinery.viatra.runtime.rete.eval.RelationEvaluatorNode; 14import tools.refinery.viatra.runtime.rete.eval.RelationEvaluatorNode;
26import tools.refinery.viatra.runtime.rete.index.DualInputNode; 15import tools.refinery.viatra.runtime.rete.index.*;
27import tools.refinery.viatra.runtime.rete.index.ExistenceNode; 16import tools.refinery.viatra.runtime.rete.itc.alg.incscc.IncSCCAlg;
28import tools.refinery.viatra.runtime.rete.index.Indexer; 17import tools.refinery.viatra.runtime.rete.itc.alg.misc.topsort.TopologicalSorting;
29import tools.refinery.viatra.runtime.rete.index.IndexerListener; 18import tools.refinery.viatra.runtime.rete.itc.graphimpl.Graph;
30import tools.refinery.viatra.runtime.rete.index.IterableIndexer; 19import tools.refinery.viatra.runtime.rete.network.*;
31import tools.refinery.viatra.runtime.rete.index.SpecializedProjectionIndexer;
32import tools.refinery.viatra.runtime.rete.network.IGroupable;
33import tools.refinery.viatra.runtime.rete.network.NetworkStructureChangeSensitiveNode;
34import tools.refinery.viatra.runtime.rete.network.Node;
35import tools.refinery.viatra.runtime.rete.network.ProductionNode;
36import tools.refinery.viatra.runtime.rete.network.Receiver;
37import tools.refinery.viatra.runtime.rete.network.ReteContainer;
38import tools.refinery.viatra.runtime.rete.network.communication.timely.TimelyIndexerListenerProxy; 20import tools.refinery.viatra.runtime.rete.network.communication.timely.TimelyIndexerListenerProxy;
39import tools.refinery.viatra.runtime.rete.network.communication.timely.TimelyMailboxProxy; 21import tools.refinery.viatra.runtime.rete.network.communication.timely.TimelyMailboxProxy;
40import tools.refinery.viatra.runtime.rete.network.mailbox.FallThroughCapableMailbox; 22import tools.refinery.viatra.runtime.rete.network.mailbox.FallThroughCapableMailbox;
@@ -43,6 +25,8 @@ import tools.refinery.viatra.runtime.rete.network.mailbox.timeless.BehaviorChang
43import tools.refinery.viatra.runtime.rete.single.TransitiveClosureNode; 25import tools.refinery.viatra.runtime.rete.single.TransitiveClosureNode;
44import tools.refinery.viatra.runtime.rete.single.TrimmerNode; 26import tools.refinery.viatra.runtime.rete.single.TrimmerNode;
45 27
28import java.util.*;
29
46/** 30/**
47 * An instance of this class is associated with every {@link ReteContainer}. The tracker serves two purposes: <br> 31 * An instance of this class is associated with every {@link ReteContainer}. The tracker serves two purposes: <br>
48 * (1) It allows RETE nodes to register their communication dependencies on-the-fly. These dependencies can be 32 * (1) It allows RETE nodes to register their communication dependencies on-the-fly. These dependencies can be
@@ -263,7 +247,10 @@ public abstract class CommunicationTracker {
263 247
264 public CommunicationGroup getAndRemoveFirstGroup() { 248 public CommunicationGroup getAndRemoveFirstGroup() {
265 final CommunicationGroup group = groupQueue.poll(); 249 final CommunicationGroup group = groupQueue.poll();
266 group.isEnqueued = false; 250 if (group == null) {
251 throw new IllegalStateException("Group queue must not be empty");
252 }
253 group.isEnqueued = false;
267 return group; 254 return group;
268 } 255 }
269 256
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/util/OrderingCompareAgent.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/util/OrderingCompareAgent.java
index 8b147cf6..6d0d813a 100644
--- a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/util/OrderingCompareAgent.java
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/util/OrderingCompareAgent.java
@@ -3,7 +3,7 @@
3 * This program and the accompanying materials are made available under the 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 4 * terms of the Eclipse Public License v. 2.0 which is available at
5 * http://www.eclipse.org/legal/epl-v20.html. 5 * http://www.eclipse.org/legal/epl-v20.html.
6 * 6 *
7 * SPDX-License-Identifier: EPL-2.0 7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/ 8 *******************************************************************************/
9 9
@@ -13,9 +13,9 @@ import java.util.Comparator;
13 13
14/** 14/**
15 * Comparing agent for an ordering. Terminology: the "preferred" item will register as LESS. 15 * Comparing agent for an ordering. Terminology: the "preferred" item will register as LESS.
16 * 16 *
17 * @author Gabor Bergmann 17 * @author Gabor Bergmann
18 * 18 *
19 */ 19 */
20public abstract class OrderingCompareAgent<T> { 20public abstract class OrderingCompareAgent<T> {
21 protected T a; 21 protected T a;
@@ -25,7 +25,7 @@ public abstract class OrderingCompareAgent<T> {
25 * @param a 25 * @param a
26 * @param b 26 * @param b
27 */ 27 */
28 public OrderingCompareAgent(T a, T b) { 28 protected OrderingCompareAgent(T a, T b) {
29 super(); 29 super();
30 this.a = a; 30 this.a = a;
31 this.b = b; 31 this.b = b;
@@ -77,16 +77,21 @@ public abstract class OrderingCompareAgent<T> {
77 protected static <U> int preferLess(Comparable<U> c1, U c2) { 77 protected static <U> int preferLess(Comparable<U> c1, U c2) {
78 return c1.compareTo(c2); 78 return c1.compareTo(c2);
79 } 79 }
80 80
81 protected static <U> int preferLess(U c1, U c2, Comparator<U> comp) { 81 protected static <U> int preferLess(U c1, U c2, Comparator<U> comp) {
82 return comp.compare(c1, c2); 82 return comp.compare(c1, c2);
83 } 83 }
84 84
85 protected static <U> int preferMore(Comparable<U> c1, U c2) { 85 protected static <U> int preferMore(Comparable<U> c1, U c2) {
86 return -c1.compareTo(c2); 86 return reverse(c1.compareTo(c2));
87 } 87 }
88
88 protected static <U> int preferMore(U c1, U c2, Comparator<U> comp) { 89 protected static <U> int preferMore(U c1, U c2, Comparator<U> comp) {
89 return -comp.compare(c1, c2); 90 return reverse(comp.compare(c1, c2));
90 } 91 }
91 92
93 private static int reverse(int value) {
94 return Integer.compare(0, value);
95 }
96
92} 97}