diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EmptyMemory.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EmptyMemory.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EmptyMemory.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EmptyMemory.java new file mode 100644 index 00000000..a17b3a3f --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EmptyMemory.java | |||
@@ -0,0 +1,93 @@ | |||
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.util; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.Set; | ||
14 | |||
15 | /** | ||
16 | * A singleton immutable empty memory. | ||
17 | * @author Gabor Bergmann | ||
18 | * @since 2.0 | ||
19 | * | ||
20 | */ | ||
21 | public class EmptyMemory<T> implements IMemoryView<T> { | ||
22 | |||
23 | @SuppressWarnings("rawtypes") | ||
24 | private static final EmptyMemory INSTANCE = new EmptyMemory(); | ||
25 | |||
26 | @SuppressWarnings("unchecked") | ||
27 | public static <T> EmptyMemory<T> instance() { | ||
28 | return INSTANCE; | ||
29 | } | ||
30 | |||
31 | |||
32 | |||
33 | /** | ||
34 | * Singleton; hidden constructor | ||
35 | */ | ||
36 | private EmptyMemory() { | ||
37 | super(); | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public Iterator<T> iterator() { | ||
42 | return Collections.<T>emptySet().iterator(); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public int getCount(T value) { | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public int getCountUnsafe(Object value) { | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public boolean containsNonZero(T value) { | ||
57 | return false; | ||
58 | } | ||
59 | |||
60 | @Override | ||
61 | public boolean containsNonZeroUnsafe(Object value) { | ||
62 | return false; | ||
63 | } | ||
64 | |||
65 | @Override | ||
66 | public int size() { | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public boolean isEmpty() { | ||
72 | return true; | ||
73 | } | ||
74 | |||
75 | @Override | ||
76 | public Set<T> distinctValues() { | ||
77 | return Collections.emptySet(); | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public int hashCode() { | ||
82 | return IMemoryView.hashCode(this); | ||
83 | } | ||
84 | @Override | ||
85 | public boolean equals(Object obj) { | ||
86 | return IMemoryView.equals(this, obj); | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public String toString() { | ||
91 | return "{}"; | ||
92 | } | ||
93 | } | ||