OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 27... Line 27...
27
 * 
27
 * 
28
 * @param <E> the type of elements maintained by this set
28
 * @param <E> the type of elements maintained by this set
29
 */
29
 */
30
public final class IdentityHashSet<E> extends AbstractSet<E> implements IdentitySet<E>, Cloneable {
30
public final class IdentityHashSet<E> extends AbstractSet<E> implements IdentitySet<E>, Cloneable {
31
 
31
 
-
 
32
    static private final Object VALUE = new Object();
-
 
33
 
32
    private final IdentityHashMap<E, Object> map;
34
    private final IdentityHashMap<E, Object> map;
33
 
35
 
34
    public IdentityHashSet() {
36
    public IdentityHashSet() {
35
        this.map = new IdentityHashMap<E, Object>();
37
        this.map = new IdentityHashMap<E, Object>();
36
    }
38
    }
Line 44... Line 46...
44
        this.addAll(c);
46
        this.addAll(c);
45
    }
47
    }
46
 
48
 
47
    @Override
49
    @Override
48
    public boolean add(E e) {
50
    public boolean add(E e) {
49
        if (this.contains(e))
-
 
50
            return false;
-
 
51
        else {
-
 
52
            this.map.put(e, null);
51
        return this.map.put(e, VALUE) != VALUE;
53
            return true;
-
 
54
        }
-
 
55
    }
52
    }
56
 
53
 
57
    @Override
54
    @Override
58
    public boolean addAll(Collection<? extends E> c) {
55
    public boolean addAll(Collection<? extends E> c) {
59
        // let the super which calls add() since we don't want to build a map to use Map.addAll()
56
        // let the super which calls add() since we don't want to build a map to use Map.addAll()
Line 80... Line 77...
80
        return this.map.keySet().iterator();
77
        return this.map.keySet().iterator();
81
    }
78
    }
82
 
79
 
83
    @Override
80
    @Override
84
    public boolean contains(Object o) {
81
    public boolean contains(Object o) {
85
        return this.map.keySet().contains(o);
82
        return this.map.containsKey(o);
86
    }
83
    }
87
 
84
 
88
    @Override
85
    @Override
89
    public boolean containsAll(Collection<?> c) {
86
    public boolean containsAll(Collection<?> c) {
90
        return this.map.keySet().containsAll(c);
87
        return this.map.keySet().containsAll(c);
91
    }
88
    }
92
 
89
 
93
    @Override
90
    @Override
94
    public boolean remove(Object o) {
91
    public boolean remove(Object o) {
95
        return this.map.keySet().remove(o);
92
        return this.map.remove(o) == VALUE;
96
    }
93
    }
97
 
94
 
98
    @Override
95
    @Override
99
    public boolean removeAll(Collection<?> c) {
96
    public boolean removeAll(Collection<?> c) {
100
        return this.map.keySet().removeAll(c);
97
        return this.map.keySet().removeAll(c);
Line 113... Line 110...
113
    @Override
110
    @Override
114
    public <T> T[] toArray(T[] a) {
111
    public <T> T[] toArray(T[] a) {
115
        return this.map.keySet().toArray(a);
112
        return this.map.keySet().toArray(a);
116
    }
113
    }
117
 
114
 
-
 
115
    // use System.identityHashCode()
-
 
116
    @Override
-
 
117
    public int hashCode() {
-
 
118
        return this.map.keySet().hashCode();
-
 
119
    }
-
 
120
 
-
 
121
    // equals() uses containsAll which is correct
-
 
122
 
118
    /**
123
    /**
119
     * Returns a shallow copy of this <tt>HashSet</tt> instance: the elements themselves are not
124
     * Returns a shallow copy of this <tt>HashSet</tt> instance: the elements themselves are not
120
     * cloned.
125
     * cloned.
121
     * 
126
     * 
122
     * @return a shallow copy of this set
127
     * @return a shallow copy of this set