diff options
author | 2022-09-26 00:39:23 +0200 | |
---|---|---|
committer | 2022-10-03 20:06:52 +0200 | |
commit | aac386f0d8c4e4585026b11bfeca20f378f7f261 (patch) | |
tree | cad56fc2c88a1abd56258d64b5ce3a16baaff011 /subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java | |
parent | chore: fix some warnings (diff) | |
download | refinery-aac386f0d8c4e4585026b11bfeca20f378f7f261.tar.gz refinery-aac386f0d8c4e4585026b11bfeca20f378f7f261.tar.zst refinery-aac386f0d8c4e4585026b11bfeca20f378f7f261.zip |
refactor: move viatra into a separate subproject
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java')
-rw-r--r-- | subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java | 62 |
1 files changed, 62 insertions, 0 deletions
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 new file mode 100644 index 00000000..2f7f9a9c --- /dev/null +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java | |||
@@ -0,0 +1,62 @@ | |||
1 | package tools.refinery.store.query.viatra.internal.viewupdate; | ||
2 | |||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | ||
4 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | ||
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
6 | import tools.refinery.store.model.Tuple; | ||
7 | import tools.refinery.store.query.view.RelationView; | ||
8 | |||
9 | import java.util.Objects; | ||
10 | |||
11 | public class ViewUpdateTranslator<D> { | ||
12 | private final RelationView<D> key; | ||
13 | |||
14 | private final ITuple filter; | ||
15 | |||
16 | private final IQueryRuntimeContextListener listener; | ||
17 | |||
18 | public ViewUpdateTranslator(RelationView<D> key, ITuple filter, IQueryRuntimeContextListener listener) { | ||
19 | super(); | ||
20 | this.key = key; | ||
21 | this.filter = filter; | ||
22 | this.listener = listener; | ||
23 | } | ||
24 | |||
25 | public boolean equals(RelationView<?> relationView, ITuple seed, IQueryRuntimeContextListener listener) { | ||
26 | return key == relationView && filter.equals(seed) && this.listener == listener; | ||
27 | } | ||
28 | |||
29 | public void processChange(ViewUpdate change) { | ||
30 | listener.update(key, Tuples.flatTupleOf(change.tuple()), change.isInsertion()); | ||
31 | } | ||
32 | |||
33 | public Object[] isMatching(Tuple tuple, D value) { | ||
34 | return isMatching(key.getWrappedKey().transform(tuple, value), filter); | ||
35 | } | ||
36 | |||
37 | @SuppressWarnings("squid:S1168") | ||
38 | private Object[] isMatching(Object[] tuple, ITuple filter) { | ||
39 | for (int i = 0; i < filter.getSize(); i++) { | ||
40 | final Object filterObject = filter.get(i); | ||
41 | if (filterObject != null && !filterObject.equals(tuple[i])) { | ||
42 | return null; | ||
43 | } | ||
44 | } | ||
45 | return tuple; | ||
46 | } | ||
47 | |||
48 | @Override | ||
49 | public int hashCode() { | ||
50 | return Objects.hash(filter, key, listener); | ||
51 | } | ||
52 | |||
53 | @Override | ||
54 | public boolean equals(Object obj) { | ||
55 | if (this == obj) | ||
56 | return true; | ||
57 | if (!(obj instanceof ViewUpdateTranslator<?> other)) | ||
58 | return false; | ||
59 | return Objects.equals(filter, other.filter) && Objects.equals(key, other.key) | ||
60 | && Objects.equals(listener, other.listener); | ||
61 | } | ||
62 | } | ||