diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyNullaryMaskedTupleMemory.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyNullaryMaskedTupleMemory.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyNullaryMaskedTupleMemory.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyNullaryMaskedTupleMemory.java new file mode 100644 index 00000000..75987a89 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/timely/TimelyNullaryMaskedTupleMemory.java | |||
@@ -0,0 +1,108 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2018, Gabor Bergmann, IncQuery Labs Ltd. | ||
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 | package tools.refinery.viatra.runtime.matchers.memories.timely; | ||
10 | |||
11 | import java.util.Collection; | ||
12 | import java.util.Collections; | ||
13 | import java.util.Map; | ||
14 | import java.util.Set; | ||
15 | |||
16 | import tools.refinery.viatra.runtime.matchers.tuple.ITuple; | ||
17 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
18 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
19 | import tools.refinery.viatra.runtime.matchers.tuple.Tuples; | ||
20 | import tools.refinery.viatra.runtime.matchers.util.timeline.Diff; | ||
21 | import tools.refinery.viatra.runtime.matchers.util.timeline.Timeline; | ||
22 | |||
23 | /** | ||
24 | * Timely specialization for nullary mask. | ||
25 | * | ||
26 | * @author Tamas Szabo | ||
27 | * @since 2.3 | ||
28 | */ | ||
29 | public final class TimelyNullaryMaskedTupleMemory<Timestamp extends Comparable<Timestamp>> | ||
30 | extends AbstractTimelyTrivialMaskedMemory<Timestamp> { | ||
31 | |||
32 | protected static final Tuple EMPTY_TUPLE = Tuples.staticArityFlatTupleOf(); | ||
33 | protected static final Set<Tuple> UNIT_RELATION = Collections.singleton(EMPTY_TUPLE); | ||
34 | protected static final Set<Tuple> EMPTY_RELATION = Collections.emptySet(); | ||
35 | |||
36 | public TimelyNullaryMaskedTupleMemory(final TupleMask mask, final Object owner, final boolean isLazy) { | ||
37 | super(mask, owner, isLazy); | ||
38 | if (0 != mask.getSize()) { | ||
39 | throw new IllegalArgumentException(mask.toString()); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public int getKeysetSize() { | ||
45 | return this.memory.isEmpty() ? 0 : 1; | ||
46 | } | ||
47 | |||
48 | @Override | ||
49 | public Iterable<Tuple> getSignatures() { | ||
50 | return this.memory.isEmpty() ? EMPTY_RELATION : UNIT_RELATION; | ||
51 | } | ||
52 | |||
53 | @Override | ||
54 | public Collection<Tuple> get(final ITuple signature) { | ||
55 | if (0 == signature.getSize()) { | ||
56 | return this.memory.getTuplesAtInfinity(); | ||
57 | } else { | ||
58 | return null; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public Map<Tuple, Timeline<Timestamp>> getWithTimeline(final ITuple signature) { | ||
64 | if (0 == signature.getSize()) { | ||
65 | return this.memory.asMap(); | ||
66 | } else { | ||
67 | return null; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | public Diff<Timestamp> removeWithTimestamp(final Tuple tuple, final Tuple signature, final Timestamp timestamp) { | ||
73 | try { | ||
74 | return this.memory.remove(tuple, timestamp); | ||
75 | } catch (final IllegalStateException e) { | ||
76 | throw raiseDuplicateDeletion(tuple); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public Diff<Timestamp> addWithTimestamp(final Tuple tuple, final Tuple signature, final Timestamp timestamp) { | ||
82 | return this.memory.put(tuple, timestamp); | ||
83 | } | ||
84 | |||
85 | @Override | ||
86 | public boolean isPresentAtInfinity(final ITuple signature) { | ||
87 | if (0 == signature.getSize()) { | ||
88 | return this.memory.getCountAtInfinity() > 0; | ||
89 | } else { | ||
90 | return false; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public Set<Tuple> getResumableSignatures() { | ||
96 | if (this.memory.getResumableTimestamp() != null) { | ||
97 | return UNIT_RELATION; | ||
98 | } else { | ||
99 | return EMPTY_RELATION; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | @Override | ||
104 | public Map<Tuple, Map<Tuple, Diff<Timestamp>>> resumeAt(final Timestamp timestamp) { | ||
105 | return Collections.singletonMap(EMPTY_TUPLE, this.memory.resumeAt(timestamp)); | ||
106 | } | ||
107 | |||
108 | } | ||