diff options
Diffstat (limited to 'subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/update/TuplePreservingViewUpdateListener.java')
-rw-r--r-- | subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/update/TuplePreservingViewUpdateListener.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/update/TuplePreservingViewUpdateListener.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/update/TuplePreservingViewUpdateListener.java new file mode 100644 index 00000000..c9f69145 --- /dev/null +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/update/TuplePreservingViewUpdateListener.java | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.query.interpreter.internal.update; | ||
7 | |||
8 | import tools.refinery.interpreter.matchers.tuple.Tuples; | ||
9 | import tools.refinery.store.model.Interpretation; | ||
10 | import tools.refinery.store.query.interpreter.internal.QueryInterpreterAdapterImpl; | ||
11 | import tools.refinery.store.query.view.TuplePreservingView; | ||
12 | import tools.refinery.store.tuple.Tuple; | ||
13 | |||
14 | public class TuplePreservingViewUpdateListener<T> extends SymbolViewUpdateListener<T> { | ||
15 | private final TuplePreservingView<T> view; | ||
16 | |||
17 | TuplePreservingViewUpdateListener(QueryInterpreterAdapterImpl adapter, TuplePreservingView<T> view, | ||
18 | Interpretation<T> interpretation) { | ||
19 | super(adapter, interpretation); | ||
20 | this.view = view; | ||
21 | } | ||
22 | |||
23 | @Override | ||
24 | public void put(Tuple key, T fromValue, T toValue, boolean restoring) { | ||
25 | boolean fromPresent = view.filter(key, fromValue); | ||
26 | boolean toPresent = view.filter(key, toValue); | ||
27 | if (fromPresent == toPresent) { | ||
28 | return; | ||
29 | } | ||
30 | var translated = Tuples.flatTupleOf(view.forwardMap(key)); | ||
31 | processUpdate(translated, toPresent); | ||
32 | } | ||
33 | } | ||