aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools')
-rw-r--r--subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/internal/apiimpl/ViatraQueryEngineImpl.java4
-rw-r--r--subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/common/JavaTransitiveInstancesKey.java53
-rw-r--r--subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/rewriters/VariableMappingExpressionEvaluatorWrapper.java20
-rw-r--r--subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsLongSetMemory.java38
4 files changed, 65 insertions, 50 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/internal/apiimpl/ViatraQueryEngineImpl.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/internal/apiimpl/ViatraQueryEngineImpl.java
index 5317a79e..84ac8f7d 100644
--- a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/internal/apiimpl/ViatraQueryEngineImpl.java
+++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/internal/apiimpl/ViatraQueryEngineImpl.java
@@ -74,7 +74,7 @@ public final class ViatraQueryEngineImpl extends AdvancedViatraQueryEngine
74 /** 74 /**
75 * The context of the engine, provided by the scope. 75 * The context of the engine, provided by the scope.
76 */ 76 */
77 private IEngineContext engineContext; 77 private final IEngineContext engineContext;
78 78
79 /** 79 /**
80 * Initialized matchers for each query 80 * Initialized matchers for each query
@@ -85,7 +85,7 @@ public final class ViatraQueryEngineImpl extends AdvancedViatraQueryEngine
85 /** 85 /**
86 * The RETE and other pattern matcher implementations of the VIATRA Query Engine. 86 * The RETE and other pattern matcher implementations of the VIATRA Query Engine.
87 */ 87 */
88 private volatile Map<IQueryBackendFactory, IQueryBackend> queryBackends = new HashMap<>(); 88 private final Map<IQueryBackendFactory, IQueryBackend> queryBackends = Collections.synchronizedMap(new HashMap<>());
89 89
90 /** 90 /**
91 * The current engine default hints 91 * The current engine default hints
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/common/JavaTransitiveInstancesKey.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/common/JavaTransitiveInstancesKey.java
index eb972c2d..400a6ab9 100644
--- a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/common/JavaTransitiveInstancesKey.java
+++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/common/JavaTransitiveInstancesKey.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 *******************************************************************************/
9package tools.refinery.viatra.runtime.matchers.context.common; 9package tools.refinery.viatra.runtime.matchers.context.common;
@@ -12,22 +12,22 @@ package tools.refinery.viatra.runtime.matchers.context.common;
12 12
13/** 13/**
14 * Instance tuples are of form (x), where object x is an instance of the given Java class or its subclasses. 14 * Instance tuples are of form (x), where object x is an instance of the given Java class or its subclasses.
15 * <p> Fine print 1: classes with the same name are considered equivalent. 15 * <p> Fine print 1: classes with the same name are considered equivalent.
16 * Can be instantiated with class name, even if the class itself is not loaded yet; but if the class is available, passing it in the constructor is beneficial to avoid classloading troubles. 16 * Can be instantiated with class name, even if the class itself is not loaded yet; but if the class is available, passing it in the constructor is beneficial to avoid classloading troubles.
17 * <p> Fine print 2: primitive types (char, etc.) are transparently treated as their wrapper class (Character, etc.). 17 * <p> Fine print 2: primitive types (char, etc.) are transparently treated as their wrapper class (Character, etc.).
18 * <p> Non-enumerable type, can only be checked. 18 * <p> Non-enumerable type, can only be checked.
19 * <p> Stateless type (objects can't change their type) 19 * <p> Stateless type (objects can't change their type)
20 * @author Bergmann Gabor 20 * @author Bergmann Gabor
21 * 21 *
22*/ 22*/
23public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> { 23public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> {
24 24
25 /** 25 /**
26 * The actual Class whose (transitive) instances this relation contains. Can be null at compile time, if only the name is available. 26 * The actual Class whose (transitive) instances this relation contains. Can be null at compile time, if only the name is available.
27 * Can be a primitive. 27 * Can be a primitive.
28 */ 28 */
29 private Class<?> cachedOriginalInstanceClass; 29 private Class<?> cachedOriginalInstanceClass;
30 30
31 /** 31 /**
32 * Same as {@link #cachedOriginalInstanceClass}, but primitive classes are replaced with their wrapper classes (e.g. int --> java.lang.Integer). 32 * Same as {@link #cachedOriginalInstanceClass}, but primitive classes are replaced with their wrapper classes (e.g. int --> java.lang.Integer).
33 */ 33 */
@@ -37,17 +37,17 @@ public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> {
37 * Preferred constructor. 37 * Preferred constructor.
38 */ 38 */
39 public JavaTransitiveInstancesKey(Class<?> instanceClass) { 39 public JavaTransitiveInstancesKey(Class<?> instanceClass) {
40 this(primitiveTypeToWrapperClass(instanceClass).getName()); 40 this(getName(instanceClass));
41 this.cachedOriginalInstanceClass = instanceClass; 41 this.cachedOriginalInstanceClass = instanceClass;
42 } 42 }
43 43
44 /** 44 /**
45 * Call this constructor only in contexts where the class itself is not available for loading, e.g. it has not yet been compiled. 45 * Call this constructor only in contexts where the class itself is not available for loading, e.g. it has not yet been compiled.
46 */ 46 */
47 public JavaTransitiveInstancesKey(String className) { 47 public JavaTransitiveInstancesKey(String className) {
48 super(className); 48 super(className);
49 } 49 }
50 50
51 51
52 /** 52 /**
53 * Returns null if class cannot be loaded. 53 * Returns null if class cannot be loaded.
@@ -66,7 +66,7 @@ public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> {
66 66
67 /** 67 /**
68 * @return non-null instance class 68 * @return non-null instance class
69 * @throws ClassNotFoundException 69 * @throws ClassNotFoundException
70 */ 70 */
71 private Class<?> forceGetOriginalInstanceClass() throws ClassNotFoundException { 71 private Class<?> forceGetOriginalInstanceClass() throws ClassNotFoundException {
72 if (cachedOriginalInstanceClass == null) { 72 if (cachedOriginalInstanceClass == null) {
@@ -74,10 +74,10 @@ public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> {
74 } 74 }
75 return cachedOriginalInstanceClass; 75 return cachedOriginalInstanceClass;
76 } 76 }
77 77
78 /** 78 /**
79 * @return non-null instance class, wrapped if primitive class 79 * @return non-null instance class, wrapped if primitive class
80 * @throws ClassNotFoundException 80 * @throws ClassNotFoundException
81 */ 81 */
82 public Class<?> forceGetWrapperInstanceClass() throws ClassNotFoundException { 82 public Class<?> forceGetWrapperInstanceClass() throws ClassNotFoundException {
83 forceGetOriginalInstanceClass(); 83 forceGetOriginalInstanceClass();
@@ -85,12 +85,12 @@ public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> {
85 } 85 }
86 /** 86 /**
87 * @return non-null instance class, wrapped if primitive class 87 * @return non-null instance class, wrapped if primitive class
88 * @throws ClassNotFoundException 88 * @throws ClassNotFoundException
89 */ 89 */
90 public Class<?> forceGetInstanceClass() throws ClassNotFoundException { 90 public Class<?> forceGetInstanceClass() throws ClassNotFoundException {
91 return forceGetWrapperInstanceClass(); 91 return forceGetWrapperInstanceClass();
92 } 92 }
93 93
94 /** 94 /**
95 * @return instance class, wrapped if primitive class, null if class cannot be loaded 95 * @return instance class, wrapped if primitive class, null if class cannot be loaded
96 */ 96 */
@@ -106,16 +106,19 @@ public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> {
106 public Class<?> getInstanceClass() { 106 public Class<?> getInstanceClass() {
107 return getWrapperInstanceClass(); 107 return getWrapperInstanceClass();
108 } 108 }
109 109
110 private void resolveClassInternal() throws ClassNotFoundException { 110 private void resolveClassInternal() throws ClassNotFoundException {
111 cachedOriginalInstanceClass = Class.forName(wrappedKey); 111 cachedOriginalInstanceClass = Class.forName(wrappedKey);
112 } 112 }
113 113
114 @Override 114 @Override
115 public String getPrettyPrintableName() { 115 public String getPrettyPrintableName() {
116 getWrapperInstanceClass(); 116 getWrapperInstanceClass();
117 return cachedWrapperInstanceClass == null ? wrappedKey == null ? "<null>" : wrappedKey : cachedWrapperInstanceClass.getName(); 117 if (cachedWrapperInstanceClass == null) {
118 } 118 return wrappedKey == null ? "<null>" : wrappedKey;
119 }
120 return cachedWrapperInstanceClass.getName();
121 }
119 122
120 @Override 123 @Override
121 public String getStringID() { 124 public String getStringID() {
@@ -126,12 +129,12 @@ public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> {
126 public int getArity() { 129 public int getArity() {
127 return 1; 130 return 1;
128 } 131 }
129 132
130 @Override 133 @Override
131 public boolean isEnumerable() { 134 public boolean isEnumerable() {
132 return false; 135 return false;
133 } 136 }
134 137
135 @Override 138 @Override
136 public String toString() { 139 public String toString() {
137 return this.getPrettyPrintableName(); 140 return this.getPrettyPrintableName();
@@ -161,5 +164,11 @@ public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> {
161 return instanceClass; 164 return instanceClass;
162 } 165 }
163 166
164 167 private static String getName(Class<?> instanceClass) {
168 Class<?> wrapperClass = primitiveTypeToWrapperClass(instanceClass);
169 if (wrapperClass == null) {
170 return "<null>";
171 }
172 return wrapperClass.getName();
173 }
165} 174}
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/rewriters/VariableMappingExpressionEvaluatorWrapper.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/rewriters/VariableMappingExpressionEvaluatorWrapper.java
index 10337979..e0e17b5e 100644
--- a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/rewriters/VariableMappingExpressionEvaluatorWrapper.java
+++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/rewriters/VariableMappingExpressionEvaluatorWrapper.java
@@ -3,24 +3,24 @@
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 *******************************************************************************/
9package tools.refinery.viatra.runtime.matchers.psystem.rewriters; 9package tools.refinery.viatra.runtime.matchers.psystem.rewriters;
10 10
11import java.util.HashMap;
12import java.util.LinkedHashMap;
13import java.util.Map;
14
15import tools.refinery.viatra.runtime.matchers.psystem.IExpressionEvaluator; 11import tools.refinery.viatra.runtime.matchers.psystem.IExpressionEvaluator;
16import tools.refinery.viatra.runtime.matchers.psystem.IValueProvider; 12import tools.refinery.viatra.runtime.matchers.psystem.IValueProvider;
17import tools.refinery.viatra.runtime.matchers.psystem.PVariable; 13import tools.refinery.viatra.runtime.matchers.psystem.PVariable;
18import tools.refinery.viatra.runtime.matchers.util.Preconditions; 14import tools.refinery.viatra.runtime.matchers.util.Preconditions;
19 15
16import java.util.HashMap;
17import java.util.LinkedHashMap;
18import java.util.Map;
19
20/** 20/**
21 * A wrapper for {@link IExpressionEvaluator} which is capable of correctly mapping variable names used by the 21 * A wrapper for {@link IExpressionEvaluator} which is capable of correctly mapping variable names used by the
22 * expression. 22 * expression.
23 * 23 *
24 * @author Grill Balázs 24 * @author Grill Balázs
25 * 25 *
26 */ 26 */
@@ -28,10 +28,10 @@ class VariableMappingExpressionEvaluatorWrapper implements IExpressionEvaluator
28 28
29 private final IExpressionEvaluator wrapped; 29 private final IExpressionEvaluator wrapped;
30 private final Map<String, String> variableMapping; 30 private final Map<String, String> variableMapping;
31 31
32 public VariableMappingExpressionEvaluatorWrapper(IExpressionEvaluator wrapped, 32 public VariableMappingExpressionEvaluatorWrapper(IExpressionEvaluator wrapped,
33 Map<PVariable, PVariable> variableMapping) { 33 Map<PVariable, PVariable> variableMapping) {
34 34
35 // Support to rewrap an already wrapped expression. 35 // Support to rewrap an already wrapped expression.
36 boolean rewrap = wrapped instanceof VariableMappingExpressionEvaluatorWrapper; 36 boolean rewrap = wrapped instanceof VariableMappingExpressionEvaluatorWrapper;
37 this.wrapped = rewrap ? ((VariableMappingExpressionEvaluatorWrapper)wrapped).wrapped : wrapped; 37 this.wrapped = rewrap ? ((VariableMappingExpressionEvaluatorWrapper)wrapped).wrapped : wrapped;
@@ -46,7 +46,7 @@ class VariableMappingExpressionEvaluatorWrapper implements IExpressionEvaluator
46 for (PVariable originalVar : variableMapping.keySet()) { 46 for (PVariable originalVar : variableMapping.keySet()) {
47 names.put(originalVar.getName(), originalVar); 47 names.put(originalVar.getName(), originalVar);
48 } 48 }
49 49
50 // In case of rewrapping, current names are contained by the previous mapping 50 // In case of rewrapping, current names are contained by the previous mapping
51 Map<String, String> previousMapping = null; 51 Map<String, String> previousMapping = null;
52 if (rewrap){ 52 if (rewrap){
@@ -55,6 +55,8 @@ class VariableMappingExpressionEvaluatorWrapper implements IExpressionEvaluator
55 55
56 // Populate mapping 56 // Populate mapping
57 for (String inputParameterName : this.wrapped.getInputParameterNames()) { 57 for (String inputParameterName : this.wrapped.getInputParameterNames()) {
58 // {@code previousMapping} can't be {@code null} if {@code rewrap} is {@code true}.
59 @SuppressWarnings("squid:S2259")
58 String parameterName = rewrap ? previousMapping.get(inputParameterName) : inputParameterName; 60 String parameterName = rewrap ? previousMapping.get(inputParameterName) : inputParameterName;
59 Preconditions.checkArgument(parameterName != null); 61 Preconditions.checkArgument(parameterName != null);
60 PVariable original = names.get(parameterName); 62 PVariable original = names.get(parameterName);
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsLongSetMemory.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsLongSetMemory.java
index fceb54fc..ce3efa92 100644
--- a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsLongSetMemory.java
+++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsLongSetMemory.java
@@ -3,20 +3,21 @@
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 *******************************************************************************/
9package tools.refinery.viatra.runtime.matchers.util; 9package tools.refinery.viatra.runtime.matchers.util;
10 10
11import java.util.Collection;
12import java.util.Iterator;
13import java.util.Set;
14
15import org.eclipse.collections.api.LongIterable; 11import org.eclipse.collections.api.LongIterable;
16import org.eclipse.collections.api.iterator.LongIterator; 12import org.eclipse.collections.api.iterator.LongIterator;
17import org.eclipse.collections.api.set.primitive.LongSet; 13import org.eclipse.collections.api.set.primitive.LongSet;
18import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; 14import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;
19 15
16import java.util.Collection;
17import java.util.Iterator;
18import java.util.NoSuchElementException;
19import java.util.Set;
20
20/** 21/**
21 * @author Gabor Bergmann 22 * @author Gabor Bergmann
22 * @since 2.0 23 * @since 2.0
@@ -31,7 +32,7 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
31 @Override 32 @Override
32 public boolean addSigned(Long value, int count) { 33 public boolean addSigned(Long value, int count) {
33 if (count == 1) return addOne(value); 34 if (count == 1) return addOne(value);
34 else if (count == -1) return removeOne(value); 35 else if (count == -1) return removeOne(value);
35 else throw new IllegalStateException(); 36 else throw new IllegalStateException();
36 } 37 }
37 38
@@ -40,7 +41,7 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
40 // Kept for binary compatibility 41 // Kept for binary compatibility
41 return ISetMemory.super.removeOne(value); 42 return ISetMemory.super.removeOne(value);
42 } 43 }
43 44
44 /** 45 /**
45 * @since 2.3 46 * @since 2.3
46 */ 47 */
@@ -58,7 +59,7 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
58 public int getCount(Long value) { 59 public int getCount(Long value) {
59 return super.contains(value) ? 1 : 0; 60 return super.contains(value) ? 1 : 0;
60 } 61 }
61 62
62 @Override 63 @Override
63 public int getCountUnsafe(Object value) { 64 public int getCountUnsafe(Object value) {
64 return value instanceof Long ? getCount((Long) value) : 0; 65 return value instanceof Long ? getCount((Long) value) : 0;
@@ -68,7 +69,7 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
68 public boolean containsNonZero(Long value) { 69 public boolean containsNonZero(Long value) {
69 return super.contains(value); 70 return super.contains(value);
70 } 71 }
71 72
72 @Override 73 @Override
73 public boolean containsNonZeroUnsafe(Object value) { 74 public boolean containsNonZeroUnsafe(Object value) {
74 return value instanceof Long && containsNonZero((Long) value); 75 return value instanceof Long && containsNonZero((Long) value);
@@ -83,18 +84,18 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
83 public Set<Long> distinctValues() { 84 public Set<Long> distinctValues() {
84 return new SetWrapper(this); 85 return new SetWrapper(this);
85 } 86 }
86 87
87 @Override 88 @Override
88 public boolean isEmpty() { 89 public boolean isEmpty() {
89 return super.isEmpty(); 90 return super.isEmpty();
90 } 91 }
91 92
92 /** 93 /**
93 * Helper for iterating a LongIterable 94 * Helper for iterating a LongIterable
94 */ 95 */
95 public static Iterator<Long> iteratorOf(LongIterable wrapped) { 96 public static Iterator<Long> iteratorOf(LongIterable wrapped) {
96 return new Iterator<Long>() { 97 return new Iterator<Long>() {
97 LongIterator longIterator = wrapped.longIterator(); 98 private final LongIterator longIterator = wrapped.longIterator();
98 99
99 @Override 100 @Override
100 public boolean hasNext() { 101 public boolean hasNext() {
@@ -103,11 +104,14 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
103 104
104 @Override 105 @Override
105 public Long next() { 106 public Long next() {
107 if (!longIterator.hasNext()) {
108 throw new NoSuchElementException("next() called, but the iterator is exhausted");
109 }
106 return longIterator.next(); 110 return longIterator.next();
107 } 111 }
108 }; 112 };
109 } 113 }
110 114
111 @Override 115 @Override
112 public int hashCode() { 116 public int hashCode() {
113 return IMemoryView.hashCode(this); 117 return IMemoryView.hashCode(this);
@@ -117,7 +121,7 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
117 return IMemoryView.equals(this, obj); 121 return IMemoryView.equals(this, obj);
118 } 122 }
119 123
120 124
121 /** 125 /**
122 * Helper that presents a primitive collection as a Set view 126 * Helper that presents a primitive collection as a Set view
123 * @author Gabor Bergmann 127 * @author Gabor Bergmann
@@ -171,7 +175,7 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
171 public <T> T[] toArray(T[] a) { 175 public <T> T[] toArray(T[] a) {
172 int k = 0; 176 int k = 0;
173 LongIterator iterator = wrapped.longIterator(); 177 LongIterator iterator = wrapped.longIterator();
174 while (iterator.hasNext()) 178 while (iterator.hasNext())
175 a[k++] = (T) Long.valueOf(iterator.next()); 179 a[k++] = (T) Long.valueOf(iterator.next());
176 return a; 180 return a;
177 } 181 }
@@ -205,8 +209,8 @@ public class EclipseCollectionsLongSetMemory extends LongHashSet implements ISet
205 public void clear() { 209 public void clear() {
206 throw new UnsupportedOperationException(); 210 throw new UnsupportedOperationException();
207 } 211 }
208 212
209 213
210 } 214 }
211 215
212} 216}