diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsBagMemory.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsBagMemory.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsBagMemory.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsBagMemory.java new file mode 100644 index 00000000..e24b2448 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsBagMemory.java | |||
@@ -0,0 +1,86 @@ | |||
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.util; | ||
11 | |||
12 | import java.util.Iterator; | ||
13 | import java.util.Set; | ||
14 | import java.util.function.BiConsumer; | ||
15 | |||
16 | import org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap; | ||
17 | |||
18 | /** | ||
19 | * Eclipse Collections-based multiset for tuples. Can contain duplicate occurrences of the same matching. | ||
20 | * | ||
21 | * <p>Inherits Eclipse Collections' Object-to-Int primitive hashmap and counts the number of occurrences of each value. | ||
22 | * Element is deleted if # of occurences drops to 0. | ||
23 | * | ||
24 | * @author Gabor Bergmann. | ||
25 | * @since 1.7 | ||
26 | * @noreference | ||
27 | */ | ||
28 | public abstract class EclipseCollectionsBagMemory<T> extends ObjectIntHashMap<T> implements IMemory<T> { | ||
29 | |||
30 | public EclipseCollectionsBagMemory() { | ||
31 | super(); | ||
32 | } | ||
33 | |||
34 | @Override | ||
35 | public int getCount(T value) { | ||
36 | return super.getIfAbsent(value, 0); | ||
37 | } | ||
38 | @Override | ||
39 | public int getCountUnsafe(Object value) { | ||
40 | return super.getIfAbsent(value, 0); | ||
41 | } | ||
42 | @Override | ||
43 | public boolean containsNonZero(T value) { | ||
44 | return super.containsKey(value); | ||
45 | } | ||
46 | @Override | ||
47 | public boolean containsNonZeroUnsafe(Object value) { | ||
48 | return super.containsKey(value); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public void clearAllOf(T value) { | ||
53 | super.remove(value); | ||
54 | } | ||
55 | |||
56 | |||
57 | @Override | ||
58 | public Iterator<T> iterator() { | ||
59 | return super.keySet().iterator(); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public String toString() { | ||
64 | return "TM" + super.toString(); | ||
65 | } | ||
66 | |||
67 | @Override | ||
68 | public Set<T> distinctValues() { | ||
69 | return super.keySet(); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | public void forEachEntryWithMultiplicities(BiConsumer<T, Integer> entryConsumer) { | ||
74 | super.forEachKeyValue(entryConsumer::accept); | ||
75 | } | ||
76 | |||
77 | @Override | ||
78 | public int hashCode() { | ||
79 | return IMemoryView.hashCode(this); | ||
80 | } | ||
81 | @Override | ||
82 | public boolean equals(Object obj) { | ||
83 | return IMemoryView.equals(this, obj); | ||
84 | } | ||
85 | |||
86 | } | ||