aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EmptyMemory.java
blob: a17b3a3ff5d5975155e7800721ef87fe648f9234 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
 * Copyright (c) 2010-2018, Gabor Bergmann, IncQuery Labs Ltd.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-v20.html.
 * 
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package tools.refinery.viatra.runtime.matchers.util;

import java.util.Collections;
import java.util.Iterator;
import java.util.Set;

/**
 * A singleton immutable empty memory. 
 * @author Gabor Bergmann
 * @since 2.0
 *
 */
public class EmptyMemory<T> implements IMemoryView<T> {

    @SuppressWarnings("rawtypes")
    private static final EmptyMemory INSTANCE = new EmptyMemory();
    
    @SuppressWarnings("unchecked")
    public static <T> EmptyMemory<T> instance() {
        return INSTANCE;
    }
    
    
    
    /**
     * Singleton; hidden constructor
     */
    private EmptyMemory() {
        super();
    }

    @Override
    public Iterator<T> iterator() {
        return Collections.<T>emptySet().iterator();
    }

    @Override
    public int getCount(T value) {
        return 0;
    }

    @Override
    public int getCountUnsafe(Object value) {
        return 0;
    }

    @Override
    public boolean containsNonZero(T value) {
        return false;
    }

    @Override
    public boolean containsNonZeroUnsafe(Object value) {
        return false;
    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public boolean isEmpty() {
        return true;
    }

    @Override
    public Set<T> distinctValues() {
        return Collections.emptySet();
    }
    
    @Override
    public int hashCode() {
        return IMemoryView.hashCode(this);
    }
    @Override
    public boolean equals(Object obj) {
        return IMemoryView.equals(this, obj);
    }

    @Override
    public String toString() {
        return "{}";
    }
}