diff options
Diffstat (limited to 'subprojects/store/src/main/java/tools/refinery/store/model/internal/UnaryVersionedInterpretation.java')
-rw-r--r-- | subprojects/store/src/main/java/tools/refinery/store/model/internal/UnaryVersionedInterpretation.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/internal/UnaryVersionedInterpretation.java b/subprojects/store/src/main/java/tools/refinery/store/model/internal/UnaryVersionedInterpretation.java new file mode 100644 index 00000000..75946680 --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/model/internal/UnaryVersionedInterpretation.java | |||
@@ -0,0 +1,48 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.model.internal; | ||
7 | |||
8 | import tools.refinery.store.map.Cursor; | ||
9 | import tools.refinery.store.map.Cursors; | ||
10 | import tools.refinery.store.map.VersionedMap; | ||
11 | import tools.refinery.store.representation.Symbol; | ||
12 | import tools.refinery.store.tuple.Tuple; | ||
13 | |||
14 | import java.util.Objects; | ||
15 | |||
16 | class UnaryVersionedInterpretation<T> extends VersionedInterpretation<T> { | ||
17 | public UnaryVersionedInterpretation(ModelImpl model, Symbol<T> symbol, VersionedMap<Tuple, T> map) { | ||
18 | super(model, symbol, map); | ||
19 | } | ||
20 | |||
21 | private void validateSlot(int slot) { | ||
22 | if (slot != 0) { | ||
23 | throw new IllegalArgumentException("Invalid index: " + slot); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | @Override | ||
28 | public Cursor<Tuple, T> getAdjacent(int slot, int node) { | ||
29 | validateSlot(slot); | ||
30 | var key = Tuple.of(node); | ||
31 | var value = get(key); | ||
32 | if (Objects.equals(value, getSymbol().defaultValue())) { | ||
33 | return Cursors.empty(); | ||
34 | } | ||
35 | return Cursors.singleton(key, value); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public int getAdjacentSize(int slot, int node) { | ||
40 | validateSlot(slot); | ||
41 | var key = Tuple.of(node); | ||
42 | var value = get(key); | ||
43 | if (Objects.equals(value, getSymbol().defaultValue())) { | ||
44 | return 0; | ||
45 | } | ||
46 | return 1; | ||
47 | } | ||
48 | } | ||