diff options
Diffstat (limited to 'model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/RelationalRuntimeContext.java')
-rw-r--r-- | model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/RelationalRuntimeContext.java | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/RelationalRuntimeContext.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/RelationalRuntimeContext.java index 8f6fb8dd..7d1682b2 100644 --- a/model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/RelationalRuntimeContext.java +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/RelationalRuntimeContext.java | |||
@@ -19,12 +19,16 @@ import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | |||
19 | import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; | 19 | import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; |
20 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 20 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
21 | import org.eclipse.viatra.query.runtime.matchers.util.Accuracy; | 21 | import org.eclipse.viatra.query.runtime.matchers.util.Accuracy; |
22 | import org.eclipse.viatra.solver.data.model.Model; | ||
23 | import org.eclipse.viatra.solver.data.query.view.RelationView; | ||
22 | 24 | ||
23 | public class RelationalRuntimeContext implements IQueryRuntimeContext { | 25 | public class RelationalRuntimeContext implements IQueryRuntimeContext { |
24 | private final RelationalQueryMetaContext metaContext = new RelationalQueryMetaContext(); | 26 | private final RelationalQueryMetaContext metaContext = new RelationalQueryMetaContext(); |
25 | private final RelationUpdateListener relationUpdateListener; | 27 | private final RelationUpdateListener relationUpdateListener; |
28 | private final Model model; | ||
26 | 29 | ||
27 | public RelationalRuntimeContext(RelationUpdateListener relationUpdateListener) { | 30 | public RelationalRuntimeContext(Model model, RelationUpdateListener relationUpdateListener) { |
31 | this.model = model; | ||
28 | this.relationUpdateListener = relationUpdateListener; | 32 | this.relationUpdateListener = relationUpdateListener; |
29 | } | 33 | } |
30 | 34 | ||
@@ -53,8 +57,8 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
53 | 57 | ||
54 | @Override | 58 | @Override |
55 | public boolean isIndexed(IInputKey key, IndexingService service) { | 59 | public boolean isIndexed(IInputKey key, IndexingService service) { |
56 | if(key instanceof RelationViewKey<?>) { | 60 | if(key instanceof RelationView<?>) { |
57 | RelationViewKey<?> relationalKey = (RelationViewKey<?>) key; | 61 | RelationView<?> relationalKey = (RelationView<?>) key; |
58 | return this.relationUpdateListener.containsRelationalView(relationalKey); | 62 | return this.relationUpdateListener.containsRelationalView(relationalKey); |
59 | } else { | 63 | } else { |
60 | return false; | 64 | return false; |
@@ -68,9 +72,9 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
68 | } | 72 | } |
69 | } | 73 | } |
70 | 74 | ||
71 | RelationViewKey<?> checkKey(IInputKey key) { | 75 | RelationView<?> checkKey(IInputKey key) { |
72 | if(key instanceof RelationViewKey) { | 76 | if(key instanceof RelationView) { |
73 | RelationViewKey<?> relationViewKey = (RelationViewKey<?>) key; | 77 | RelationView<?> relationViewKey = (RelationView<?>) key; |
74 | if(relationUpdateListener.containsRelationalView(relationViewKey)) { | 78 | if(relationUpdateListener.containsRelationalView(relationViewKey)) { |
75 | return relationViewKey; | 79 | return relationViewKey; |
76 | } else { | 80 | } else { |
@@ -83,8 +87,8 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
83 | 87 | ||
84 | @Override | 88 | @Override |
85 | public int countTuples(IInputKey key, TupleMask seedMask, ITuple seed) { | 89 | public int countTuples(IInputKey key, TupleMask seedMask, ITuple seed) { |
86 | RelationViewKey<?> relationalViewKey = checkKey(key); | 90 | RelationView<?> relationalViewKey = checkKey(key); |
87 | Iterable<Object[]> allObjects = relationalViewKey.getWrappedKey().getAll(); | 91 | Iterable<Object[]> allObjects = relationalViewKey.getAll(model); |
88 | Iterable<Object[]> filteredBySeed = filter(allObjects,objectArray -> isMatching(objectArray,seedMask,seed)); | 92 | Iterable<Object[]> filteredBySeed = filter(allObjects,objectArray -> isMatching(objectArray,seedMask,seed)); |
89 | Iterator<Object[]> iterator = filteredBySeed.iterator(); | 93 | Iterator<Object[]> iterator = filteredBySeed.iterator(); |
90 | int result = 0; | 94 | int result = 0; |
@@ -102,8 +106,8 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
102 | 106 | ||
103 | @Override | 107 | @Override |
104 | public Iterable<Tuple> enumerateTuples(IInputKey key, TupleMask seedMask, ITuple seed) { | 108 | public Iterable<Tuple> enumerateTuples(IInputKey key, TupleMask seedMask, ITuple seed) { |
105 | RelationViewKey<?> relationalViewKey = checkKey(key); | 109 | RelationView<?> relationalViewKey = checkKey(key); |
106 | Iterable<Object[]> allObjects = relationalViewKey.getWrappedKey().getAll(); | 110 | Iterable<Object[]> allObjects = relationalViewKey.getAll(model); |
107 | Iterable<Object[]> filteredBySeed = filter(allObjects,objectArray -> isMatching(objectArray,seedMask,seed)); | 111 | Iterable<Object[]> filteredBySeed = filter(allObjects,objectArray -> isMatching(objectArray,seedMask,seed)); |
108 | return map(filteredBySeed,Tuples::flatTupleOf); | 112 | return map(filteredBySeed,Tuples::flatTupleOf); |
109 | } | 113 | } |
@@ -134,20 +138,20 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
134 | 138 | ||
135 | @Override | 139 | @Override |
136 | public boolean containsTuple(IInputKey key, ITuple seed) { | 140 | public boolean containsTuple(IInputKey key, ITuple seed) { |
137 | RelationViewKey<?> relationalViewKey = checkKey(key); | 141 | RelationView<?> relationalViewKey = checkKey(key); |
138 | return relationalViewKey.getWrappedKey().get(seed.getElements()); | 142 | return relationalViewKey.get(model,seed.getElements()); |
139 | } | 143 | } |
140 | 144 | ||
141 | @Override | 145 | @Override |
142 | public void addUpdateListener(IInputKey key, Tuple seed, IQueryRuntimeContextListener listener) { | 146 | public void addUpdateListener(IInputKey key, Tuple seed, IQueryRuntimeContextListener listener) { |
143 | RelationViewKey<?> relationalKey = checkKey(key); | 147 | RelationView<?> relationalKey = checkKey(key); |
144 | this.relationUpdateListener.addListener(relationalKey, seed, listener); | 148 | this.relationUpdateListener.addListener(relationalKey, seed, listener); |
145 | 149 | ||
146 | } | 150 | } |
147 | 151 | ||
148 | @Override | 152 | @Override |
149 | public void removeUpdateListener(IInputKey key, Tuple seed, IQueryRuntimeContextListener listener) { | 153 | public void removeUpdateListener(IInputKey key, Tuple seed, IQueryRuntimeContextListener listener) { |
150 | RelationViewKey<?> relationalKey = checkKey(key); | 154 | RelationView<?> relationalKey = checkKey(key); |
151 | this.relationUpdateListener.removeListener(relationalKey, seed, listener); | 155 | this.relationUpdateListener.removeListener(relationalKey, seed, listener); |
152 | } | 156 | } |
153 | 157 | ||