diff options
author | 2022-12-13 03:21:58 +0100 | |
---|---|---|
committer | 2022-12-13 12:25:02 +0100 | |
commit | 6ccc179ea305fc27ae121253b1d1f172bad676fd (patch) | |
tree | 8c5bb8dd7bf45157cabb57b19d17ce9af11aca5f /subprojects/store-query-viatra/src/main | |
parent | chore(deps): upgrade to yarn canary (diff) | |
download | refinery-6ccc179ea305fc27ae121253b1d1f172bad676fd.tar.gz refinery-6ccc179ea305fc27ae121253b1d1f172bad676fd.tar.zst refinery-6ccc179ea305fc27ae121253b1d1f172bad676fd.zip |
refactor(store): simplify return types
Prefers sealed non-generic interfaces over wildcard types to avoid
confusion about method return types, especially in collections
(see SonarQube rule java:S1452).
Diffstat (limited to 'subprojects/store-query-viatra/src/main')
8 files changed, 67 insertions, 51 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraQueryableModelStore.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraQueryableModelStore.java index 37cd91a6..94d2db4f 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraQueryableModelStore.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraQueryableModelStore.java | |||
@@ -5,13 +5,17 @@ import tools.refinery.store.model.ModelDiffCursor; | |||
5 | import tools.refinery.store.model.ModelStore; | 5 | import tools.refinery.store.model.ModelStore; |
6 | import tools.refinery.store.model.ModelStoreImpl; | 6 | import tools.refinery.store.model.ModelStoreImpl; |
7 | import tools.refinery.store.model.RelationLike; | 7 | import tools.refinery.store.model.RelationLike; |
8 | import tools.refinery.store.model.representation.AnyDataRepresentation; | ||
8 | import tools.refinery.store.model.representation.DataRepresentation; | 9 | import tools.refinery.store.model.representation.DataRepresentation; |
9 | import tools.refinery.store.query.*; | 10 | import tools.refinery.store.query.DNF; |
11 | import tools.refinery.store.query.DNFAnd; | ||
12 | import tools.refinery.store.query.QueryableModel; | ||
13 | import tools.refinery.store.query.QueryableModelStore; | ||
10 | import tools.refinery.store.query.atom.*; | 14 | import tools.refinery.store.query.atom.*; |
11 | import tools.refinery.store.query.viatra.internal.RawPatternMatcher; | 15 | import tools.refinery.store.query.viatra.internal.RawPatternMatcher; |
12 | import tools.refinery.store.query.viatra.internal.ViatraQueryableModel; | 16 | import tools.refinery.store.query.viatra.internal.ViatraQueryableModel; |
13 | import tools.refinery.store.query.viatra.internal.pquery.DNF2PQuery; | 17 | import tools.refinery.store.query.viatra.internal.pquery.DNF2PQuery; |
14 | import tools.refinery.store.query.view.RelationView; | 18 | import tools.refinery.store.query.view.AnyRelationView; |
15 | 19 | ||
16 | import java.util.Collections; | 20 | import java.util.Collections; |
17 | import java.util.HashMap; | 21 | import java.util.HashMap; |
@@ -21,11 +25,11 @@ import java.util.Set; | |||
21 | public class ViatraQueryableModelStore implements QueryableModelStore { | 25 | public class ViatraQueryableModelStore implements QueryableModelStore { |
22 | protected final ModelStore store; | 26 | protected final ModelStore store; |
23 | 27 | ||
24 | protected final Set<RelationView<?>> relationViews; | 28 | protected final Set<AnyRelationView> relationViews; |
25 | 29 | ||
26 | protected final Map<DNF, GenericQuerySpecification<RawPatternMatcher>> predicates; | 30 | protected final Map<DNF, GenericQuerySpecification<RawPatternMatcher>> predicates; |
27 | 31 | ||
28 | public ViatraQueryableModelStore(ModelStore store, Set<RelationView<?>> relationViews, | 32 | public ViatraQueryableModelStore(ModelStore store, Set<AnyRelationView> relationViews, |
29 | Set<DNF> predicates) { | 33 | Set<DNF> predicates) { |
30 | this.store = store; | 34 | this.store = store; |
31 | validateViews(store.getDataRepresentations(), relationViews); | 35 | validateViews(store.getDataRepresentations(), relationViews); |
@@ -34,13 +38,13 @@ public class ViatraQueryableModelStore implements QueryableModelStore { | |||
34 | this.predicates = initPredicates(predicates); | 38 | this.predicates = initPredicates(predicates); |
35 | } | 39 | } |
36 | 40 | ||
37 | public ViatraQueryableModelStore(Set<DataRepresentation<?, ?>> dataRepresentations, | 41 | public ViatraQueryableModelStore(Set<AnyDataRepresentation> dataRepresentations, |
38 | Set<RelationView<?>> relationViews, Set<DNF> predicates) { | 42 | Set<AnyRelationView> relationViews, Set<DNF> predicates) { |
39 | this(new ModelStoreImpl(dataRepresentations), relationViews, predicates); | 43 | this(new ModelStoreImpl(dataRepresentations), relationViews, predicates); |
40 | } | 44 | } |
41 | 45 | ||
42 | private void validateViews(Set<DataRepresentation<?, ?>> dataRepresentations, Set<RelationView<?>> relationViews) { | 46 | private void validateViews(Set<AnyDataRepresentation> dataRepresentations, Set<AnyRelationView> relationViews) { |
43 | for (RelationView<?> relationView : relationViews) { | 47 | for (var relationView : relationViews) { |
44 | if (!dataRepresentations.contains(relationView.getRepresentation())) { | 48 | if (!dataRepresentations.contains(relationView.getRepresentation())) { |
45 | throw new IllegalArgumentException("%s %s added to %s without a referred representation.".formatted( | 49 | throw new IllegalArgumentException("%s %s added to %s without a referred representation.".formatted( |
46 | DataRepresentation.class.getSimpleName(), relationView.getName(), | 50 | DataRepresentation.class.getSimpleName(), relationView.getName(), |
@@ -49,7 +53,7 @@ public class ViatraQueryableModelStore implements QueryableModelStore { | |||
49 | } | 53 | } |
50 | } | 54 | } |
51 | 55 | ||
52 | private void validatePredicates(Set<RelationView<?>> relationViews, Set<DNF> predicates) { | 56 | private void validatePredicates(Set<AnyRelationView> relationViews, Set<DNF> predicates) { |
53 | for (DNF dnfPredicate : predicates) { | 57 | for (DNF dnfPredicate : predicates) { |
54 | for (DNFAnd clause : dnfPredicate.getClauses()) { | 58 | for (DNFAnd clause : dnfPredicate.getClauses()) { |
55 | for (DNFAtom atom : clause.constraints()) { | 59 | for (DNFAtom atom : clause.constraints()) { |
@@ -65,7 +69,7 @@ public class ViatraQueryableModelStore implements QueryableModelStore { | |||
65 | } | 69 | } |
66 | } | 70 | } |
67 | 71 | ||
68 | private void validateRelationAtom(Set<RelationView<?>> relationViews, DNF dnfPredicate, | 72 | private void validateRelationAtom(Set<AnyRelationView> relationViews, DNF dnfPredicate, |
69 | RelationViewAtom relationViewAtom) { | 73 | RelationViewAtom relationViewAtom) { |
70 | if (!relationViews.contains(relationViewAtom.getTarget())) { | 74 | if (!relationViews.contains(relationViewAtom.getTarget())) { |
71 | throw new IllegalArgumentException( | 75 | throw new IllegalArgumentException( |
@@ -100,12 +104,12 @@ public class ViatraQueryableModelStore implements QueryableModelStore { | |||
100 | } | 104 | } |
101 | 105 | ||
102 | @Override | 106 | @Override |
103 | public Set<DataRepresentation<?, ?>> getDataRepresentations() { | 107 | public Set<AnyDataRepresentation> getDataRepresentations() { |
104 | return store.getDataRepresentations(); | 108 | return store.getDataRepresentations(); |
105 | } | 109 | } |
106 | 110 | ||
107 | @Override | 111 | @Override |
108 | public Set<RelationView<?>> getViews() { | 112 | public Set<AnyRelationView> getViews() { |
109 | return this.relationViews; | 113 | return this.relationViews; |
110 | } | 114 | } |
111 | 115 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java index 5ddad67d..133c4c72 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java | |||
@@ -6,19 +6,20 @@ import org.eclipse.viatra.query.runtime.api.scope.IEngineContext; | |||
6 | import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; | 6 | import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; |
7 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; | 7 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; |
8 | import tools.refinery.store.model.Model; | 8 | import tools.refinery.store.model.Model; |
9 | import tools.refinery.store.tuple.Tuple; | ||
10 | import tools.refinery.store.model.representation.Relation; | 9 | import tools.refinery.store.model.representation.Relation; |
11 | import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; | 10 | import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; |
12 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; | 11 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; |
13 | import tools.refinery.store.query.view.RelationView; | 12 | import tools.refinery.store.query.view.AnyRelationView; |
13 | import tools.refinery.store.tuple.Tuple; | ||
14 | 14 | ||
15 | import java.util.Set; | 15 | import java.util.Set; |
16 | 16 | ||
17 | public class RelationalScope extends QueryScope { | 17 | public class RelationalScope extends QueryScope { |
18 | private final Model model; | 18 | private final Model model; |
19 | |||
19 | private final ModelUpdateListener updateListener; | 20 | private final ModelUpdateListener updateListener; |
20 | 21 | ||
21 | public RelationalScope(Model model, Set<RelationView<?>> relationViews) { | 22 | public RelationalScope(Model model, Set<AnyRelationView> relationViews) { |
22 | this.model = model; | 23 | this.model = model; |
23 | this.updateListener = new ModelUpdateListener(relationViews); | 24 | this.updateListener = new ModelUpdateListener(relationViews); |
24 | } | 25 | } |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java index cd9fb180..5b06e266 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java | |||
@@ -8,6 +8,7 @@ import tools.refinery.store.map.Cursor; | |||
8 | import tools.refinery.store.map.DiffCursor; | 8 | import tools.refinery.store.map.DiffCursor; |
9 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.model.ModelDiffCursor; | 10 | import tools.refinery.store.model.ModelDiffCursor; |
11 | import tools.refinery.store.model.representation.AnyDataRepresentation; | ||
11 | import tools.refinery.store.model.representation.DataRepresentation; | 12 | import tools.refinery.store.model.representation.DataRepresentation; |
12 | import tools.refinery.store.model.representation.Relation; | 13 | import tools.refinery.store.model.representation.Relation; |
13 | import tools.refinery.store.query.QueryableModel; | 14 | import tools.refinery.store.query.QueryableModel; |
@@ -66,7 +67,7 @@ public class ViatraQueryableModel implements QueryableModel { | |||
66 | } | 67 | } |
67 | 68 | ||
68 | @Override | 69 | @Override |
69 | public Set<DataRepresentation<?, ?>> getDataRepresentations() { | 70 | public Set<AnyDataRepresentation> getDataRepresentations() { |
70 | return model.getDataRepresentations(); | 71 | return model.getDataRepresentations(); |
71 | } | 72 | } |
72 | 73 | ||
@@ -113,7 +114,7 @@ public class ViatraQueryableModel implements QueryableModel { | |||
113 | } | 114 | } |
114 | 115 | ||
115 | @Override | 116 | @Override |
116 | public <K, V> long getSize(DataRepresentation<K, V> representation) { | 117 | public long getSize(AnyDataRepresentation representation) { |
117 | return model.getSize(representation); | 118 | return model.getSize(representation); |
118 | } | 119 | } |
119 | 120 | ||
@@ -207,7 +208,8 @@ public class ViatraQueryableModel implements QueryableModel { | |||
207 | 208 | ||
208 | private void restoreWithDiffReplay(long state) { | 209 | private void restoreWithDiffReplay(long state) { |
209 | var modelDiffCursor = getDiffCursor(state); | 210 | var modelDiffCursor = getDiffCursor(state); |
210 | for (DataRepresentation<?, ?> dataRepresentation : this.getDataRepresentations()) { | 211 | for (AnyDataRepresentation anyDataRepresentation : this.getDataRepresentations()) { |
212 | var dataRepresentation = (DataRepresentation<?, ?>) anyDataRepresentation; | ||
211 | restoreRepresentationWithDiffReplay(modelDiffCursor, dataRepresentation); | 213 | restoreRepresentationWithDiffReplay(modelDiffCursor, dataRepresentation); |
212 | } | 214 | } |
213 | } | 215 | } |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java index c007d630..e01525e0 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java | |||
@@ -9,6 +9,7 @@ import org.eclipse.viatra.query.runtime.matchers.util.Accuracy; | |||
9 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.query.viatra.internal.pquery.RelationViewWrapper; | 10 | import tools.refinery.store.query.viatra.internal.pquery.RelationViewWrapper; |
11 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; | 11 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; |
12 | import tools.refinery.store.query.view.AnyRelationView; | ||
12 | import tools.refinery.store.query.view.RelationView; | 13 | import tools.refinery.store.query.view.RelationView; |
13 | 14 | ||
14 | import java.lang.reflect.InvocationTargetException; | 15 | import java.lang.reflect.InvocationTargetException; |
@@ -53,7 +54,7 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
53 | @Override | 54 | @Override |
54 | public boolean isIndexed(IInputKey key, IndexingService service) { | 55 | public boolean isIndexed(IInputKey key, IndexingService service) { |
55 | if (key instanceof RelationView<?> relationalKey) { | 56 | if (key instanceof RelationView<?> relationalKey) { |
56 | return this.modelUpdateListener.containsRelationalView(relationalKey); | 57 | return this.modelUpdateListener.containsRelationView(relationalKey); |
57 | } else { | 58 | } else { |
58 | return false; | 59 | return false; |
59 | } | 60 | } |
@@ -66,11 +67,10 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
66 | } | 67 | } |
67 | } | 68 | } |
68 | 69 | ||
69 | @SuppressWarnings("squid:S1452") | 70 | AnyRelationView checkKey(IInputKey key) { |
70 | RelationView<?> checkKey(IInputKey key) { | ||
71 | if (key instanceof RelationViewWrapper wrappedKey) { | 71 | if (key instanceof RelationViewWrapper wrappedKey) { |
72 | var relationViewKey = wrappedKey.getWrappedKey(); | 72 | var relationViewKey = wrappedKey.getWrappedKey(); |
73 | if (modelUpdateListener.containsRelationalView(relationViewKey)) { | 73 | if (modelUpdateListener.containsRelationView(relationViewKey)) { |
74 | return relationViewKey; | 74 | return relationViewKey; |
75 | } else { | 75 | } else { |
76 | throw new IllegalStateException("Query is asking for non-indexed key"); | 76 | throw new IllegalStateException("Query is asking for non-indexed key"); |
@@ -82,8 +82,8 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
82 | 82 | ||
83 | @Override | 83 | @Override |
84 | public int countTuples(IInputKey key, TupleMask seedMask, ITuple seed) { | 84 | public int countTuples(IInputKey key, TupleMask seedMask, ITuple seed) { |
85 | RelationView<?> relationalViewKey = checkKey(key); | 85 | var relationViewKey = checkKey(key); |
86 | Iterable<Object[]> allObjects = relationalViewKey.getAll(model); | 86 | Iterable<Object[]> allObjects = relationViewKey.getAll(model); |
87 | Iterable<Object[]> filteredBySeed = filter(allObjects, objectArray -> isMatching(objectArray, seedMask, seed)); | 87 | Iterable<Object[]> filteredBySeed = filter(allObjects, objectArray -> isMatching(objectArray, seedMask, seed)); |
88 | Iterator<Object[]> iterator = filteredBySeed.iterator(); | 88 | Iterator<Object[]> iterator = filteredBySeed.iterator(); |
89 | int result = 0; | 89 | int result = 0; |
@@ -101,8 +101,8 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
101 | 101 | ||
102 | @Override | 102 | @Override |
103 | public Iterable<Tuple> enumerateTuples(IInputKey key, TupleMask seedMask, ITuple seed) { | 103 | public Iterable<Tuple> enumerateTuples(IInputKey key, TupleMask seedMask, ITuple seed) { |
104 | RelationView<?> relationalViewKey = checkKey(key); | 104 | var relationViewKey = checkKey(key); |
105 | Iterable<Object[]> allObjects = relationalViewKey.getAll(model); | 105 | Iterable<Object[]> allObjects = relationViewKey.getAll(model); |
106 | Iterable<Object[]> filteredBySeed = filter(allObjects, objectArray -> isMatching(objectArray, seedMask, seed)); | 106 | Iterable<Object[]> filteredBySeed = filter(allObjects, objectArray -> isMatching(objectArray, seedMask, seed)); |
107 | return map(filteredBySeed, Tuples::flatTupleOf); | 107 | return map(filteredBySeed, Tuples::flatTupleOf); |
108 | } | 108 | } |
@@ -125,21 +125,21 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
125 | 125 | ||
126 | @Override | 126 | @Override |
127 | public boolean containsTuple(IInputKey key, ITuple seed) { | 127 | public boolean containsTuple(IInputKey key, ITuple seed) { |
128 | RelationView<?> relationalViewKey = checkKey(key); | 128 | var relationViewKey = checkKey(key); |
129 | return relationalViewKey.get(model, seed.getElements()); | 129 | return relationViewKey.get(model, seed.getElements()); |
130 | } | 130 | } |
131 | 131 | ||
132 | @Override | 132 | @Override |
133 | public void addUpdateListener(IInputKey key, Tuple seed, IQueryRuntimeContextListener listener) { | 133 | public void addUpdateListener(IInputKey key, Tuple seed, IQueryRuntimeContextListener listener) { |
134 | RelationView<?> relationalKey = checkKey(key); | 134 | var relationViewKey = (RelationView<?>) checkKey(key); |
135 | this.modelUpdateListener.addListener(key, relationalKey, seed, listener); | 135 | this.modelUpdateListener.addListener(key, relationViewKey, seed, listener); |
136 | 136 | ||
137 | } | 137 | } |
138 | 138 | ||
139 | @Override | 139 | @Override |
140 | public void removeUpdateListener(IInputKey key, Tuple seed, IQueryRuntimeContextListener listener) { | 140 | public void removeUpdateListener(IInputKey key, Tuple seed, IQueryRuntimeContextListener listener) { |
141 | RelationView<?> relationalKey = checkKey(key); | 141 | var relationViewKey = checkKey(key); |
142 | this.modelUpdateListener.removeListener(key, relationalKey, seed, listener); | 142 | this.modelUpdateListener.removeListener(key, relationViewKey, seed, listener); |
143 | } | 143 | } |
144 | 144 | ||
145 | @Override | 145 | @Override |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java index 98054161..aa3fba6e 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java | |||
@@ -2,7 +2,10 @@ package tools.refinery.store.query.viatra.internal.pquery; | |||
2 | 2 | ||
3 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | 3 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; |
4 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | 4 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; |
5 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.*; | 5 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; |
6 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
7 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
8 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
6 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; | 9 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; |
7 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; | 10 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; |
8 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | 11 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; |
@@ -10,9 +13,11 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeCo | |||
10 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | 13 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; |
11 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | 14 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; |
12 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 15 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
13 | import tools.refinery.store.query.*; | 16 | import tools.refinery.store.query.DNF; |
17 | import tools.refinery.store.query.DNFAnd; | ||
18 | import tools.refinery.store.query.Variable; | ||
14 | import tools.refinery.store.query.atom.*; | 19 | import tools.refinery.store.query.atom.*; |
15 | import tools.refinery.store.query.view.RelationView; | 20 | import tools.refinery.store.query.view.AnyRelationView; |
16 | 21 | ||
17 | import java.util.*; | 22 | import java.util.*; |
18 | import java.util.stream.Collectors; | 23 | import java.util.stream.Collectors; |
@@ -22,7 +27,7 @@ public class DNF2PQuery { | |||
22 | 27 | ||
23 | private final Map<DNF, SimplePQuery> dnf2PQueryMap = new HashMap<>(); | 28 | private final Map<DNF, SimplePQuery> dnf2PQueryMap = new HashMap<>(); |
24 | 29 | ||
25 | private final Map<RelationView<?>, RelationViewWrapper> view2WrapperMap = new HashMap<>(); | 30 | private final Map<AnyRelationView, RelationViewWrapper> view2WrapperMap = new HashMap<>(); |
26 | 31 | ||
27 | public SimplePQuery translate(DNF dnfQuery) { | 32 | public SimplePQuery translate(DNF dnfQuery) { |
28 | if (translating.contains(dnfQuery)) { | 33 | if (translating.contains(dnfQuery)) { |
@@ -115,7 +120,7 @@ public class DNF2PQuery { | |||
115 | return Tuples.flatTupleOf(variables); | 120 | return Tuples.flatTupleOf(variables); |
116 | } | 121 | } |
117 | 122 | ||
118 | private RelationViewWrapper wrapView(RelationView<?> relationView) { | 123 | private RelationViewWrapper wrapView(AnyRelationView relationView) { |
119 | return view2WrapperMap.computeIfAbsent(relationView, RelationViewWrapper::new); | 124 | return view2WrapperMap.computeIfAbsent(relationView, RelationViewWrapper::new); |
120 | } | 125 | } |
121 | 126 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RelationViewWrapper.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RelationViewWrapper.java index 2a4148dc..e48648bf 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RelationViewWrapper.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RelationViewWrapper.java | |||
@@ -1,10 +1,10 @@ | |||
1 | package tools.refinery.store.query.viatra.internal.pquery; | 1 | package tools.refinery.store.query.viatra.internal.pquery; |
2 | 2 | ||
3 | import org.eclipse.viatra.query.runtime.matchers.context.common.BaseInputKeyWrapper; | 3 | import org.eclipse.viatra.query.runtime.matchers.context.common.BaseInputKeyWrapper; |
4 | import tools.refinery.store.query.view.RelationView; | 4 | import tools.refinery.store.query.view.AnyRelationView; |
5 | 5 | ||
6 | public class RelationViewWrapper extends BaseInputKeyWrapper<RelationView<?>> { | 6 | public class RelationViewWrapper extends BaseInputKeyWrapper<AnyRelationView> { |
7 | public RelationViewWrapper(RelationView<?> wrappedKey) { | 7 | public RelationViewWrapper(AnyRelationView wrappedKey) { |
8 | super(wrappedKey); | 8 | super(wrappedKey); |
9 | } | 9 | } |
10 | 10 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java index 1a2fcee7..6a1d06a9 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java | |||
@@ -3,6 +3,8 @@ package tools.refinery.store.query.viatra.internal.viewupdate; | |||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | 3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; |
4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
6 | import tools.refinery.store.model.representation.AnyRelation; | ||
7 | import tools.refinery.store.query.view.AnyRelationView; | ||
6 | import tools.refinery.store.tuple.Tuple; | 8 | import tools.refinery.store.tuple.Tuple; |
7 | import tools.refinery.store.model.representation.Relation; | 9 | import tools.refinery.store.model.representation.Relation; |
8 | import tools.refinery.store.query.view.RelationView; | 10 | import tools.refinery.store.query.view.RelationView; |
@@ -16,24 +18,24 @@ public class ModelUpdateListener { | |||
16 | /** | 18 | /** |
17 | * Collections of Relations and their Views. | 19 | * Collections of Relations and their Views. |
18 | */ | 20 | */ |
19 | private final Map<Relation<?>, Set<RelationView<?>>> relation2View; | 21 | private final Map<AnyRelation, Set<AnyRelationView>> relation2View; |
20 | 22 | ||
21 | /** | 23 | /** |
22 | * Collection of Views and their buffers. | 24 | * Collection of Views and their buffers. |
23 | */ | 25 | */ |
24 | private final Map<RelationView<?>, Set<ViewUpdateBuffer<?>>> view2Buffers; | 26 | private final Map<AnyRelationView, Set<ViewUpdateBuffer<?>>> view2Buffers; |
25 | 27 | ||
26 | public ModelUpdateListener(Set<RelationView<?>> relationViews) { | 28 | public ModelUpdateListener(Set<AnyRelationView> relationViews) { |
27 | this.relation2View = new HashMap<>(); | 29 | this.relation2View = new HashMap<>(); |
28 | this.view2Buffers = new HashMap<>(); | 30 | this.view2Buffers = new HashMap<>(); |
29 | 31 | ||
30 | for (RelationView<?> relationView : relationViews) { | 32 | for (var relationView : relationViews) { |
31 | registerView(relationView); | 33 | registerView(relationView); |
32 | } | 34 | } |
33 | } | 35 | } |
34 | 36 | ||
35 | private void registerView(RelationView<?> view) { | 37 | private void registerView(AnyRelationView view) { |
36 | Relation<?> relation = view.getRepresentation(); | 38 | AnyRelation relation = view.getRepresentation(); |
37 | 39 | ||
38 | // 1. register views to relations, if necessary | 40 | // 1. register views to relations, if necessary |
39 | var views = relation2View.computeIfAbsent(relation, x -> new HashSet<>()); | 41 | var views = relation2View.computeIfAbsent(relation, x -> new HashSet<>()); |
@@ -43,7 +45,7 @@ public class ModelUpdateListener { | |||
43 | view2Buffers.computeIfAbsent(view, x -> new HashSet<>()); | 45 | view2Buffers.computeIfAbsent(view, x -> new HashSet<>()); |
44 | } | 46 | } |
45 | 47 | ||
46 | public boolean containsRelationalView(RelationView<?> relationalKey) { | 48 | public boolean containsRelationView(AnyRelationView relationalKey) { |
47 | return view2Buffers.containsKey(relationalKey); | 49 | return view2Buffers.containsKey(relationalKey); |
48 | } | 50 | } |
49 | 51 | ||
@@ -58,7 +60,7 @@ public class ModelUpdateListener { | |||
58 | } | 60 | } |
59 | } | 61 | } |
60 | 62 | ||
61 | public void removeListener(IInputKey key, RelationView<?> relationView, ITuple seed, | 63 | public void removeListener(IInputKey key, AnyRelationView relationView, ITuple seed, |
62 | IQueryRuntimeContextListener listener) { | 64 | IQueryRuntimeContextListener listener) { |
63 | if (view2Buffers.containsKey(relationView)) { | 65 | if (view2Buffers.containsKey(relationView)) { |
64 | Set<ViewUpdateBuffer<?>> buffers = this.view2Buffers.get(relationView); | 66 | Set<ViewUpdateBuffer<?>> buffers = this.view2Buffers.get(relationView); |
@@ -92,8 +94,9 @@ public class ModelUpdateListener { | |||
92 | public boolean hasChanges() { | 94 | public boolean hasChanges() { |
93 | for (var bufferCollection : this.view2Buffers.values()) { | 95 | for (var bufferCollection : this.view2Buffers.values()) { |
94 | for (ViewUpdateBuffer<?> buffer : bufferCollection) { | 96 | for (ViewUpdateBuffer<?> buffer : bufferCollection) { |
95 | if (buffer.hasChanges()) | 97 | if (buffer.hasChanges()) { |
96 | return true; | 98 | return true; |
99 | } | ||
97 | } | 100 | } |
98 | } | 101 | } |
99 | return false; | 102 | return false; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java index 74d0b366..c324c84a 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java | |||
@@ -4,8 +4,9 @@ import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | |||
4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
7 | import tools.refinery.store.tuple.Tuple; | 7 | import tools.refinery.store.query.view.AnyRelationView; |
8 | import tools.refinery.store.query.view.RelationView; | 8 | import tools.refinery.store.query.view.RelationView; |
9 | import tools.refinery.store.tuple.Tuple; | ||
9 | 10 | ||
10 | import java.util.Objects; | 11 | import java.util.Objects; |
11 | 12 | ||
@@ -27,7 +28,7 @@ public class ViewUpdateTranslator<D> { | |||
27 | this.listener = listener; | 28 | this.listener = listener; |
28 | } | 29 | } |
29 | 30 | ||
30 | public boolean equals(IInputKey wrappedKey, RelationView<?> relationView, ITuple seed, | 31 | public boolean equals(IInputKey wrappedKey, AnyRelationView relationView, ITuple seed, |
31 | IQueryRuntimeContextListener listener) { | 32 | IQueryRuntimeContextListener listener) { |
32 | return this.wrappedKey == wrappedKey && key == relationView && filter.equals(seed) && this.listener == listener; | 33 | return this.wrappedKey == wrappedKey && key == relationView && filter.equals(seed) && this.listener == listener; |
33 | } | 34 | } |