aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/EclipseCollectionsSetMemory.java
blob: 92f65246ecc9ad1aa2fc82d65265e2317658c3b1 (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
94
/*******************************************************************************
 * Copyright (c) 2010-2018, Gabor Bergmann, IncQueryLabs 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.Set;

import org.eclipse.collections.impl.set.mutable.UnifiedSet;

/**
 * @author Gabor Bergmann
 * @since 2.0
 */
public class EclipseCollectionsSetMemory<Value> extends UnifiedSet<Value> implements ISetMemory<Value> {
    @Override
    public int getCount(Value value) {
        return super.contains(value) ? 1 : 0;
    }
    @Override
    public int getCountUnsafe(Object value) {
        return super.contains(value) ? 1 : 0;
    }
    @Override
    public boolean containsNonZero(Value value) {
        return super.contains(value);
    }
    
    @Override
    public boolean containsNonZeroUnsafe(Object value) {
        return super.contains(value);
    }

    @Override
    public boolean addOne(Value value) {
        return super.add(value);
    }

    @Override
    public boolean addSigned(Value value, int count) {
        if (count == 1) return addOne(value);
        else if (count == -1) return removeOne(value); 
        else throw new IllegalStateException();
    }
    
    @Override
    public boolean removeOne(Value value) {
        // Kept for binary compatibility
        return ISetMemory.super.removeOne(value);
    }
    
    @Override
    public boolean removeOneOrNop(Value value) {
        return super.remove(value);
    }

    @Override
    public void clearAllOf(Value value) {
        super.remove(value);
    }

    @Override
    public Set<Value> distinctValues() {
        return this;
    }
    
    @Override
    public Value theContainedVersionOf(Value value) {
        return super.get(value);
    }
    
    @Override
    @SuppressWarnings("unchecked")
    public Value theContainedVersionOfUnsafe(Object value) {
        if (super.contains(value)) 
            return super.get((Value)value);
        else return null;
    }
    
    @Override
    public int hashCode() {
        return IMemoryView.hashCode(this);
    }
    @Override
    public boolean equals(Object obj) {
        return IMemoryView.equals(this, obj);
    }


}