diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-09-16 00:28:21 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-09-16 02:21:41 +0200 |
commit | 4f1d586dc24e1f66ab6d07218755423a80e0c615 (patch) | |
tree | 7da3144f834f7ae1adb24d2caa532e7da313ee43 /subprojects | |
parent | Merge pull request #40 from kris7t/update-readme (diff) | |
download | refinery-4f1d586dc24e1f66ab6d07218755423a80e0c615.tar.gz refinery-4f1d586dc24e1f66ab6d07218755423a80e0c615.tar.zst refinery-4f1d586dc24e1f66ab6d07218755423a80e0c615.zip |
build: fix Sonar quality gate issues
Removes VIATRA sources from coverage anaylsis, since those files are maintained
by the VIATRA project.
Diffstat (limited to 'subprojects')
21 files changed, 188 insertions, 154 deletions
diff --git a/subprojects/frontend/src/graph/RelationName.tsx b/subprojects/frontend/src/graph/RelationName.tsx index ec26fb21..e651cb87 100644 --- a/subprojects/frontend/src/graph/RelationName.tsx +++ b/subprojects/frontend/src/graph/RelationName.tsx | |||
@@ -9,7 +9,7 @@ import { observer } from 'mobx-react-lite'; | |||
9 | 9 | ||
10 | import { RelationMetadata } from '../xtext/xtextServiceResults'; | 10 | import { RelationMetadata } from '../xtext/xtextServiceResults'; |
11 | 11 | ||
12 | const Error = styled('span', { | 12 | const ErrorPredicateName = styled('span', { |
13 | name: 'RelationName-Error', | 13 | name: 'RelationName-Error', |
14 | })(({ theme }) => ({ | 14 | })(({ theme }) => ({ |
15 | color: theme.palette.error.main, | 15 | color: theme.palette.error.main, |
@@ -36,7 +36,7 @@ const FormattedName = observer(function FormattedName({ | |||
36 | return <b>{name}</b>; | 36 | return <b>{name}</b>; |
37 | } | 37 | } |
38 | if (detail.type === 'predicate' && detail.error) { | 38 | if (detail.type === 'predicate' && detail.error) { |
39 | return <Error>{name}</Error>; | 39 | return <ErrorPredicateName>{name}</ErrorPredicateName>; |
40 | } | 40 | } |
41 | return name; | 41 | return name; |
42 | }); | 42 | }); |
diff --git a/subprojects/store-dse-visualization/build.gradle.kts b/subprojects/store-dse-visualization/build.gradle.kts index abad0491..ab9ed336 100644 --- a/subprojects/store-dse-visualization/build.gradle.kts +++ b/subprojects/store-dse-visualization/build.gradle.kts | |||
@@ -10,4 +10,5 @@ plugins { | |||
10 | 10 | ||
11 | dependencies { | 11 | dependencies { |
12 | api(project(":refinery-store-query")) | 12 | api(project(":refinery-store-query")) |
13 | implementation(libs.slf4j.api) | ||
13 | } | 14 | } |
diff --git a/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/ModelVisualizerBuilder.java b/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/ModelVisualizerBuilder.java index 1ee41cc3..e122f55c 100644 --- a/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/ModelVisualizerBuilder.java +++ b/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/ModelVisualizerBuilder.java | |||
@@ -9,6 +9,7 @@ import tools.refinery.store.adapter.ModelAdapterBuilder; | |||
9 | import tools.refinery.visualization.internal.FileFormat; | 9 | import tools.refinery.visualization.internal.FileFormat; |
10 | 10 | ||
11 | public interface ModelVisualizerBuilder extends ModelAdapterBuilder { | 11 | public interface ModelVisualizerBuilder extends ModelAdapterBuilder { |
12 | ModelVisualizerBuilder withDotBinaryPath(String dotBinaryPath); | ||
12 | ModelVisualizerBuilder withOutputPath(String outputPath); | 13 | ModelVisualizerBuilder withOutputPath(String outputPath); |
13 | ModelVisualizerBuilder withFormat(FileFormat format); | 14 | ModelVisualizerBuilder withFormat(FileFormat format); |
14 | ModelVisualizerBuilder saveDesignSpace(); | 15 | ModelVisualizerBuilder saveDesignSpace(); |
diff --git a/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java b/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java index a6a3dc69..ef10dd30 100644 --- a/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java +++ b/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java | |||
@@ -5,6 +5,8 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.visualization.internal; | 6 | package tools.refinery.visualization.internal; |
7 | 7 | ||
8 | import org.slf4j.Logger; | ||
9 | import org.slf4j.LoggerFactory; | ||
8 | import tools.refinery.store.map.Version; | 10 | import tools.refinery.store.map.Version; |
9 | import tools.refinery.store.model.Interpretation; | 11 | import tools.refinery.store.model.Interpretation; |
10 | import tools.refinery.store.model.Model; | 12 | import tools.refinery.store.model.Model; |
@@ -20,13 +22,13 @@ import java.util.*; | |||
20 | import java.util.stream.Collectors; | 22 | import java.util.stream.Collectors; |
21 | 23 | ||
22 | public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | 24 | public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { |
25 | private static final Logger LOG = LoggerFactory.getLogger(ModelVisualizerAdapterImpl.class); | ||
26 | |||
23 | private final Model model; | 27 | private final Model model; |
24 | private final ModelVisualizerStoreAdapter storeAdapter; | 28 | private final ModelVisualizerStoreAdapterImpl storeAdapter; |
25 | private final Map<AnySymbol, Interpretation<?>> allInterpretations; | 29 | private final Map<AnySymbol, Interpretation<?>> allInterpretations; |
26 | private final StringBuilder designSpaceBuilder = new StringBuilder(); | 30 | private final StringBuilder designSpaceBuilder = new StringBuilder(); |
27 | private final Map<Version, Integer> states = new HashMap<>(); | 31 | private final Map<Version, Integer> states = new HashMap<>(); |
28 | private int transitionCounter = 0; | ||
29 | private Integer numberOfStates = 0; | ||
30 | private final String outputPath; | 32 | private final String outputPath; |
31 | private final Set<FileFormat> formats; | 33 | private final Set<FileFormat> formats; |
32 | private final boolean renderDesignSpace; | 34 | private final boolean renderDesignSpace; |
@@ -41,7 +43,7 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
41 | false, "0" | 43 | false, "0" |
42 | ); | 44 | ); |
43 | 45 | ||
44 | public ModelVisualizerAdapterImpl(Model model, ModelVisualizerStoreAdapter storeAdapter) { | 46 | public ModelVisualizerAdapterImpl(Model model, ModelVisualizerStoreAdapterImpl storeAdapter) { |
45 | this.model = model; | 47 | this.model = model; |
46 | this.storeAdapter = storeAdapter; | 48 | this.storeAdapter = storeAdapter; |
47 | this.outputPath = storeAdapter.getOutputPath(); | 49 | this.outputPath = storeAdapter.getOutputPath(); |
@@ -257,8 +259,8 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
257 | 259 | ||
258 | try (FileWriter writer = new FileWriter(file)) { | 260 | try (FileWriter writer = new FileWriter(file)) { |
259 | writer.write(dot); | 261 | writer.write(dot); |
260 | } catch (Exception e) { | 262 | } catch (IOException e) { |
261 | e.printStackTrace(); | 263 | LOG.error("Failed to write dot file", e); |
262 | return false; | 264 | return false; |
263 | } | 265 | } |
264 | return true; | 266 | return true; |
@@ -270,14 +272,15 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
270 | 272 | ||
271 | private boolean renderDot(String dot, FileFormat format, String filePath) { | 273 | private boolean renderDot(String dot, FileFormat format, String filePath) { |
272 | try { | 274 | try { |
273 | Process process = new ProcessBuilder("dot", "-T" + format.getFormat(), "-o", filePath).start(); | 275 | Process process = new ProcessBuilder(storeAdapter.getDotBinaryPath(), "-T" + format.getFormat(), |
276 | "-o", filePath).start(); | ||
274 | 277 | ||
275 | OutputStream osToProcess = process.getOutputStream(); | 278 | OutputStream osToProcess = process.getOutputStream(); |
276 | PrintWriter pwToProcess = new PrintWriter(osToProcess); | 279 | PrintWriter pwToProcess = new PrintWriter(osToProcess); |
277 | pwToProcess.write(dot); | 280 | pwToProcess.write(dot); |
278 | pwToProcess.close(); | 281 | pwToProcess.close(); |
279 | } catch (IOException e) { | 282 | } catch (IOException e) { |
280 | e.printStackTrace(); | 283 | LOG.error("Failed to render dot", e); |
281 | return false; | 284 | return false; |
282 | } | 285 | } |
283 | return true; | 286 | return true; |
diff --git a/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerBuilderImpl.java b/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerBuilderImpl.java index 9ba2abe8..db4f37b4 100644 --- a/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerBuilderImpl.java +++ b/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerBuilderImpl.java | |||
@@ -13,16 +13,24 @@ import java.util.LinkedHashSet; | |||
13 | import java.util.Set; | 13 | import java.util.Set; |
14 | 14 | ||
15 | public class ModelVisualizerBuilderImpl | 15 | public class ModelVisualizerBuilderImpl |
16 | extends AbstractModelAdapterBuilder<ModelVisualizeStoreAdapterImpl> | 16 | extends AbstractModelAdapterBuilder<ModelVisualizerStoreAdapterImpl> |
17 | implements ModelVisualizerBuilder { | 17 | implements ModelVisualizerBuilder { |
18 | private String dotBinaryPath = "dot"; | ||
18 | private String outputPath; | 19 | private String outputPath; |
19 | private boolean saveDesignSpace = false; | 20 | private boolean saveDesignSpace = false; |
20 | private boolean saveStates = false; | 21 | private boolean saveStates = false; |
21 | private final Set<FileFormat> formats = new LinkedHashSet<>(); | 22 | private final Set<FileFormat> formats = new LinkedHashSet<>(); |
22 | 23 | ||
23 | @Override | 24 | @Override |
24 | protected ModelVisualizeStoreAdapterImpl doBuild(ModelStore store) { | 25 | protected ModelVisualizerStoreAdapterImpl doBuild(ModelStore store) { |
25 | return new ModelVisualizeStoreAdapterImpl(store, outputPath, formats, saveDesignSpace, saveStates); | 26 | return new ModelVisualizerStoreAdapterImpl(store, dotBinaryPath, outputPath, formats, saveDesignSpace, saveStates); |
27 | } | ||
28 | |||
29 | @Override | ||
30 | public ModelVisualizerBuilder withDotBinaryPath(String dotBinaryPath) { | ||
31 | checkNotConfigured(); | ||
32 | this.dotBinaryPath = dotBinaryPath; | ||
33 | return this; | ||
26 | } | 34 | } |
27 | 35 | ||
28 | @Override | 36 | @Override |
diff --git a/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizeStoreAdapterImpl.java b/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerStoreAdapterImpl.java index 04be22d6..c2ad4d87 100644 --- a/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizeStoreAdapterImpl.java +++ b/subprojects/store-dse-visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerStoreAdapterImpl.java | |||
@@ -12,16 +12,18 @@ import tools.refinery.visualization.ModelVisualizerStoreAdapter; | |||
12 | 12 | ||
13 | import java.util.Set; | 13 | import java.util.Set; |
14 | 14 | ||
15 | public class ModelVisualizeStoreAdapterImpl implements ModelVisualizerStoreAdapter { | 15 | public class ModelVisualizerStoreAdapterImpl implements ModelVisualizerStoreAdapter { |
16 | private final ModelStore store; | 16 | private final ModelStore store; |
17 | private final String dotBinaryPath; | ||
17 | private final String outputPath; | 18 | private final String outputPath; |
18 | private final boolean renderDesignSpace; | 19 | private final boolean renderDesignSpace; |
19 | private final boolean renderStates; | 20 | private final boolean renderStates; |
20 | private final Set<FileFormat> formats; | 21 | private final Set<FileFormat> formats; |
21 | 22 | ||
22 | public ModelVisualizeStoreAdapterImpl(ModelStore store, String outputPath, Set<FileFormat> formats, | 23 | public ModelVisualizerStoreAdapterImpl(ModelStore store, String dotBinaryPath, String outputPath, |
23 | boolean renderDesignSpace, boolean renderStates) { | 24 | Set<FileFormat> formats, boolean renderDesignSpace, boolean renderStates) { |
24 | this.store = store; | 25 | this.store = store; |
26 | this.dotBinaryPath = dotBinaryPath; | ||
25 | this.outputPath = outputPath; | 27 | this.outputPath = outputPath; |
26 | this.formats = formats; | 28 | this.formats = formats; |
27 | this.renderDesignSpace = renderDesignSpace; | 29 | this.renderDesignSpace = renderDesignSpace; |
@@ -38,6 +40,10 @@ public class ModelVisualizeStoreAdapterImpl implements ModelVisualizerStoreAdapt | |||
38 | return new ModelVisualizerAdapterImpl(model, this); | 40 | return new ModelVisualizerAdapterImpl(model, this); |
39 | } | 41 | } |
40 | 42 | ||
43 | String getDotBinaryPath() { | ||
44 | return dotBinaryPath; | ||
45 | } | ||
46 | |||
41 | @Override | 47 | @Override |
42 | public String getOutputPath() { | 48 | public String getOutputPath() { |
43 | return outputPath; | 49 | return outputPath; |
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstExplorer.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstExplorer.java index 5e2f8fa9..ce3efb21 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstExplorer.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstExplorer.java | |||
@@ -16,7 +16,11 @@ public class BestFirstExplorer extends BestFirstWorker { | |||
16 | public BestFirstExplorer(BestFirstStoreManager storeManager, Model model, int id) { | 16 | public BestFirstExplorer(BestFirstStoreManager storeManager, Model model, int id) { |
17 | super(storeManager, model); | 17 | super(storeManager, model); |
18 | this.id = id; | 18 | this.id = id; |
19 | this.random = new Random(id); | 19 | // The use of a non-cryptographic random generator is safe here, because we only use it to direct the state |
20 | // space exploration. | ||
21 | @SuppressWarnings("squid:S2245") | ||
22 | var randomGenerator = new Random(id); | ||
23 | this.random = randomGenerator; | ||
20 | } | 24 | } |
21 | 25 | ||
22 | private boolean shouldRun() { | 26 | private boolean shouldRun() { |
diff --git a/subprojects/viatra-runtime-localsearch/build.gradle.kts b/subprojects/viatra-runtime-localsearch/build.gradle.kts index 31c0c634..d0259d95 100644 --- a/subprojects/viatra-runtime-localsearch/build.gradle.kts +++ b/subprojects/viatra-runtime-localsearch/build.gradle.kts | |||
@@ -6,6 +6,10 @@ | |||
6 | 6 | ||
7 | plugins { | 7 | plugins { |
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 | ||
11 | dependencies { | 15 | dependencies { |
diff --git a/subprojects/viatra-runtime-rete-recipes/build.gradle.kts b/subprojects/viatra-runtime-rete-recipes/build.gradle.kts index b1b11b4e..b0d0139a 100644 --- a/subprojects/viatra-runtime-rete-recipes/build.gradle.kts +++ b/subprojects/viatra-runtime-rete-recipes/build.gradle.kts | |||
@@ -10,6 +10,10 @@ plugins { | |||
10 | id("tools.refinery.gradle.java-library") | 10 | id("tools.refinery.gradle.java-library") |
11 | id("tools.refinery.gradle.mwe2") | 11 | id("tools.refinery.gradle.mwe2") |
12 | id("tools.refinery.gradle.sonarqube") | 12 | id("tools.refinery.gradle.sonarqube") |
13 | // Vendor code from Eclipse VIATRA is maintained by the VIATRA project, | ||
14 | // so we don't need to keep track of coverage ourselves. | ||
15 | // Our own modifications are covered by tests in the `store-query-viatra` subproject. | ||
16 | id("tools.refinery.gradle.skip-coverage") | ||
13 | } | 17 | } |
14 | 18 | ||
15 | dependencies { | 19 | dependencies { |
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 | ||
7 | plugins { | 7 | plugins { |
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 | ||
11 | dependencies { | 15 | dependencies { |
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; | |||
31 | import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo; | 31 | import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo; |
32 | 32 | ||
33 | import java.util.Collection; | 33 | import java.util.Collection; |
34 | import java.util.List; | ||
35 | import java.util.Map; | 34 | import java.util.Map; |
36 | import java.util.Optional; | 35 | import java.util.Optional; |
37 | import java.util.stream.Collectors; | ||
38 | import java.util.stream.Stream; | 36 | import 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 | ||
10 | package tools.refinery.viatra.runtime.rete.network; | 10 | package tools.refinery.viatra.runtime.rete.network; |
11 | 11 | ||
12 | import java.util.ArrayList; | ||
13 | import java.util.Collection; | ||
14 | import java.util.Collections; | ||
15 | import java.util.List; | ||
16 | import java.util.Map; | ||
17 | import java.util.Map.Entry; | ||
18 | import java.util.Set; | ||
19 | import java.util.concurrent.locks.Lock; | ||
20 | import java.util.concurrent.locks.ReadWriteLock; | ||
21 | import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
22 | |||
23 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | 12 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; |
24 | import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; | 13 | import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; |
25 | import tools.refinery.viatra.runtime.matchers.util.Direction; | 14 | import tools.refinery.viatra.runtime.matchers.util.Direction; |
@@ -30,9 +19,15 @@ import tools.refinery.viatra.runtime.rete.remote.Address; | |||
30 | import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo; | 19 | import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo; |
31 | import tools.refinery.viatra.runtime.rete.util.Options; | 20 | import tools.refinery.viatra.runtime.rete.util.Options; |
32 | 21 | ||
22 | import java.util.*; | ||
23 | import java.util.Map.Entry; | ||
24 | import java.util.concurrent.locks.Lock; | ||
25 | import java.util.concurrent.locks.ReadWriteLock; | ||
26 | import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
27 | |||
33 | /** | 28 | /** |
34 | * @author Gabor Bergmann | 29 | * @author Gabor Bergmann |
35 | * | 30 | * |
36 | */ | 31 | */ |
37 | public class Network { | 32 | public 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 | *******************************************************************************/ |
9 | package tools.refinery.viatra.runtime.rete.network.communication; | 9 | package tools.refinery.viatra.runtime.rete.network.communication; |
10 | 10 | ||
11 | import java.util.HashMap; | ||
12 | import java.util.HashSet; | ||
13 | import java.util.List; | ||
14 | import java.util.Map; | ||
15 | import java.util.PriorityQueue; | ||
16 | import java.util.Queue; | ||
17 | import java.util.Set; | ||
18 | |||
19 | import tools.refinery.viatra.runtime.rete.itc.alg.incscc.IncSCCAlg; | ||
20 | import tools.refinery.viatra.runtime.rete.itc.alg.misc.topsort.TopologicalSorting; | ||
21 | import tools.refinery.viatra.runtime.rete.itc.graphimpl.Graph; | ||
22 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | 11 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; |
23 | import tools.refinery.viatra.runtime.rete.aggregation.IAggregatorNode; | 12 | import tools.refinery.viatra.runtime.rete.aggregation.IAggregatorNode; |
24 | import tools.refinery.viatra.runtime.rete.boundary.ExternalInputEnumeratorNode; | 13 | import tools.refinery.viatra.runtime.rete.boundary.ExternalInputEnumeratorNode; |
25 | import tools.refinery.viatra.runtime.rete.eval.RelationEvaluatorNode; | 14 | import tools.refinery.viatra.runtime.rete.eval.RelationEvaluatorNode; |
26 | import tools.refinery.viatra.runtime.rete.index.DualInputNode; | 15 | import tools.refinery.viatra.runtime.rete.index.*; |
27 | import tools.refinery.viatra.runtime.rete.index.ExistenceNode; | 16 | import tools.refinery.viatra.runtime.rete.itc.alg.incscc.IncSCCAlg; |
28 | import tools.refinery.viatra.runtime.rete.index.Indexer; | 17 | import tools.refinery.viatra.runtime.rete.itc.alg.misc.topsort.TopologicalSorting; |
29 | import tools.refinery.viatra.runtime.rete.index.IndexerListener; | 18 | import tools.refinery.viatra.runtime.rete.itc.graphimpl.Graph; |
30 | import tools.refinery.viatra.runtime.rete.index.IterableIndexer; | 19 | import tools.refinery.viatra.runtime.rete.network.*; |
31 | import tools.refinery.viatra.runtime.rete.index.SpecializedProjectionIndexer; | ||
32 | import tools.refinery.viatra.runtime.rete.network.IGroupable; | ||
33 | import tools.refinery.viatra.runtime.rete.network.NetworkStructureChangeSensitiveNode; | ||
34 | import tools.refinery.viatra.runtime.rete.network.Node; | ||
35 | import tools.refinery.viatra.runtime.rete.network.ProductionNode; | ||
36 | import tools.refinery.viatra.runtime.rete.network.Receiver; | ||
37 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
38 | import tools.refinery.viatra.runtime.rete.network.communication.timely.TimelyIndexerListenerProxy; | 20 | import tools.refinery.viatra.runtime.rete.network.communication.timely.TimelyIndexerListenerProxy; |
39 | import tools.refinery.viatra.runtime.rete.network.communication.timely.TimelyMailboxProxy; | 21 | import tools.refinery.viatra.runtime.rete.network.communication.timely.TimelyMailboxProxy; |
40 | import tools.refinery.viatra.runtime.rete.network.mailbox.FallThroughCapableMailbox; | 22 | import tools.refinery.viatra.runtime.rete.network.mailbox.FallThroughCapableMailbox; |
@@ -43,6 +25,8 @@ import tools.refinery.viatra.runtime.rete.network.mailbox.timeless.BehaviorChang | |||
43 | import tools.refinery.viatra.runtime.rete.single.TransitiveClosureNode; | 25 | import tools.refinery.viatra.runtime.rete.single.TransitiveClosureNode; |
44 | import tools.refinery.viatra.runtime.rete.single.TrimmerNode; | 26 | import tools.refinery.viatra.runtime.rete.single.TrimmerNode; |
45 | 27 | ||
28 | import 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 | */ |
20 | public abstract class OrderingCompareAgent<T> { | 20 | public 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 | } |
diff --git a/subprojects/viatra-runtime/build.gradle.kts b/subprojects/viatra-runtime/build.gradle.kts index c4bd9129..05c2b754 100644 --- a/subprojects/viatra-runtime/build.gradle.kts +++ b/subprojects/viatra-runtime/build.gradle.kts | |||
@@ -6,6 +6,10 @@ | |||
6 | 6 | ||
7 | plugins { | 7 | plugins { |
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 | ||
11 | dependencies { | 15 | dependencies { |
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 | *******************************************************************************/ |
9 | package tools.refinery.viatra.runtime.matchers.context.common; | 9 | package 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 | */ |
23 | public class JavaTransitiveInstancesKey extends BaseInputKeyWrapper<String> { | 23 | public 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 | *******************************************************************************/ |
9 | package tools.refinery.viatra.runtime.matchers.psystem.rewriters; | 9 | package tools.refinery.viatra.runtime.matchers.psystem.rewriters; |
10 | 10 | ||
11 | import java.util.HashMap; | ||
12 | import java.util.LinkedHashMap; | ||
13 | import java.util.Map; | ||
14 | |||
15 | import tools.refinery.viatra.runtime.matchers.psystem.IExpressionEvaluator; | 11 | import tools.refinery.viatra.runtime.matchers.psystem.IExpressionEvaluator; |
16 | import tools.refinery.viatra.runtime.matchers.psystem.IValueProvider; | 12 | import tools.refinery.viatra.runtime.matchers.psystem.IValueProvider; |
17 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; | 13 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; |
18 | import tools.refinery.viatra.runtime.matchers.util.Preconditions; | 14 | import tools.refinery.viatra.runtime.matchers.util.Preconditions; |
19 | 15 | ||
16 | import java.util.HashMap; | ||
17 | import java.util.LinkedHashMap; | ||
18 | import 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 | *******************************************************************************/ |
9 | package tools.refinery.viatra.runtime.matchers.util; | 9 | package tools.refinery.viatra.runtime.matchers.util; |
10 | 10 | ||
11 | import java.util.Collection; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.Set; | ||
14 | |||
15 | import org.eclipse.collections.api.LongIterable; | 11 | import org.eclipse.collections.api.LongIterable; |
16 | import org.eclipse.collections.api.iterator.LongIterator; | 12 | import org.eclipse.collections.api.iterator.LongIterator; |
17 | import org.eclipse.collections.api.set.primitive.LongSet; | 13 | import org.eclipse.collections.api.set.primitive.LongSet; |
18 | import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; | 14 | import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; |
19 | 15 | ||
16 | import java.util.Collection; | ||
17 | import java.util.Iterator; | ||
18 | import java.util.NoSuchElementException; | ||
19 | import 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 | } |