diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsSetMemory.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsSetMemory.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsSetMemory.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsSetMemory.java new file mode 100644 index 00000000..92f65246 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsSetMemory.java | |||
@@ -0,0 +1,94 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2018, Gabor Bergmann, IncQueryLabs 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.util; | ||
10 | |||
11 | import java.util.Set; | ||
12 | |||
13 | import org.eclipse.collections.impl.set.mutable.UnifiedSet; | ||
14 | |||
15 | /** | ||
16 | * @author Gabor Bergmann | ||
17 | * @since 2.0 | ||
18 | */ | ||
19 | public class EclipseCollectionsSetMemory<Value> extends UnifiedSet<Value> implements ISetMemory<Value> { | ||
20 | @Override | ||
21 | public int getCount(Value value) { | ||
22 | return super.contains(value) ? 1 : 0; | ||
23 | } | ||
24 | @Override | ||
25 | public int getCountUnsafe(Object value) { | ||
26 | return super.contains(value) ? 1 : 0; | ||
27 | } | ||
28 | @Override | ||
29 | public boolean containsNonZero(Value value) { | ||
30 | return super.contains(value); | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | public boolean containsNonZeroUnsafe(Object value) { | ||
35 | return super.contains(value); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public boolean addOne(Value value) { | ||
40 | return super.add(value); | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public boolean addSigned(Value value, int count) { | ||
45 | if (count == 1) return addOne(value); | ||
46 | else if (count == -1) return removeOne(value); | ||
47 | else throw new IllegalStateException(); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public boolean removeOne(Value value) { | ||
52 | // Kept for binary compatibility | ||
53 | return ISetMemory.super.removeOne(value); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | public boolean removeOneOrNop(Value value) { | ||
58 | return super.remove(value); | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public void clearAllOf(Value value) { | ||
63 | super.remove(value); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public Set<Value> distinctValues() { | ||
68 | return this; | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | public Value theContainedVersionOf(Value value) { | ||
73 | return super.get(value); | ||
74 | } | ||
75 | |||
76 | @Override | ||
77 | @SuppressWarnings("unchecked") | ||
78 | public Value theContainedVersionOfUnsafe(Object value) { | ||
79 | if (super.contains(value)) | ||
80 | return super.get((Value)value); | ||
81 | else return null; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public int hashCode() { | ||
86 | return IMemoryView.hashCode(this); | ||
87 | } | ||
88 | @Override | ||
89 | public boolean equals(Object obj) { | ||
90 | return IMemoryView.equals(this, obj); | ||
91 | } | ||
92 | |||
93 | |||
94 | } | ||