diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyDefaultMaskedTupleMemory.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyDefaultMaskedTupleMemory.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyDefaultMaskedTupleMemory.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyDefaultMaskedTupleMemory.java new file mode 100644 index 00000000..623d7399 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyDefaultMaskedTupleMemory.java | |||
@@ -0,0 +1,98 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | |||
10 | package tools.refinery.viatra.runtime.matchers.memories.timely; | ||
11 | |||
12 | import java.util.Collection; | ||
13 | import java.util.Collections; | ||
14 | import java.util.Map; | ||
15 | import java.util.Set; | ||
16 | |||
17 | import tools.refinery.viatra.runtime.matchers.tuple.ITuple; | ||
18 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
19 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
20 | import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; | ||
21 | import tools.refinery.viatra.runtime.matchers.util.TimelyMemory; | ||
22 | import tools.refinery.viatra.runtime.matchers.util.timeline.Diff; | ||
23 | import tools.refinery.viatra.runtime.matchers.util.timeline.Timeline; | ||
24 | |||
25 | /** | ||
26 | * Default timely implementation that covers all cases. | ||
27 | * | ||
28 | * @author Tamas Szabo | ||
29 | * @since 2.3 | ||
30 | */ | ||
31 | public final class TimelyDefaultMaskedTupleMemory<Timestamp extends Comparable<Timestamp>> | ||
32 | extends AbstractTimelyMaskedMemory<Timestamp, Tuple> { | ||
33 | |||
34 | public TimelyDefaultMaskedTupleMemory(final TupleMask mask, final Object owner, final boolean isLazy) { | ||
35 | super(mask, owner, isLazy); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public Iterable<Tuple> getSignatures() { | ||
40 | return this.memoryMap.keySet(); | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public Diff<Timestamp> removeWithTimestamp(final Tuple tuple, final Tuple signature, | ||
45 | final Timestamp timestamp) { | ||
46 | final Tuple key = mask.transform(tuple); | ||
47 | return removeInternal(key, tuple, timestamp); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public Diff<Timestamp> addWithTimestamp(final Tuple tuple, final Tuple signature, | ||
52 | final Timestamp timestamp) { | ||
53 | final Tuple key = this.mask.transform(tuple); | ||
54 | return addInternal(key, tuple, timestamp); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | public Collection<Tuple> get(final ITuple signature) { | ||
59 | return getInternal(signature.toImmutable()); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public Map<Tuple, Timeline<Timestamp>> getWithTimeline(final ITuple signature) { | ||
64 | return getWithTimestampInternal(signature.toImmutable()); | ||
65 | } | ||
66 | |||
67 | @Override | ||
68 | public boolean isPresentAtInfinity(final ITuple signature) { | ||
69 | return isPresentAtInfinityInteral(signature.toImmutable()); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | public Set<Tuple> getResumableSignatures() { | ||
74 | if (this.foldingStates == null || this.foldingStates.isEmpty()) { | ||
75 | return Collections.emptySet(); | ||
76 | } else { | ||
77 | return this.foldingStates.firstEntry().getValue(); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public Map<Tuple, Map<Tuple, Diff<Timestamp>>> resumeAt(final Timestamp timestamp) { | ||
83 | final Map<Tuple, Map<Tuple, Diff<Timestamp>>> result = CollectionsFactory.createMap(); | ||
84 | final Timestamp resumableTimestamp = this.getResumableTimestamp(); | ||
85 | if (resumableTimestamp == null || resumableTimestamp.compareTo(timestamp) != 0) { | ||
86 | throw new IllegalStateException("Expected to continue folding at " + resumableTimestamp + "!"); | ||
87 | } | ||
88 | final Set<Tuple> signatures = this.foldingStates.remove(timestamp); | ||
89 | for (final Tuple signature : signatures) { | ||
90 | final TimelyMemory<Timestamp> memory = this.memoryMap.get(signature); | ||
91 | final Map<Tuple, Diff<Timestamp>> diffMap = memory.resumeAt(resumableTimestamp); | ||
92 | result.put(signature, diffMap); | ||
93 | registerFoldingState(memory.getResumableTimestamp(), signature); | ||
94 | } | ||
95 | return result; | ||
96 | } | ||
97 | |||
98 | } | ||