This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 192759
Collapse All | Expand All

(-)a/cnd.utils/src/org/netbeans/modules/cnd/utils/cache/WeakSharedSet.java (-16 / +16 lines)
Lines 42-51 Link Here
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
/*
44
/*
45
 *  @(#)WeakSharedSet.java	0.2 07/02/26
45
 *  @(#)WeakSet.java	0.2 07/02/26
46
 */
46
 */
47
47
48
package org.netbeans.modules.cnd.utils.cache;
48
package org.openide.util;
49
49
50
import java.io.IOException;
50
import java.io.IOException;
51
import java.lang.ref.ReferenceQueue;
51
import java.lang.ref.ReferenceQueue;
Lines 71-124 Link Here
71
 * @author Vladimir Voskresensky
71
 * @author Vladimir Voskresensky
72
 */
72
 */
73
@SuppressWarnings("unchecked")
73
@SuppressWarnings("unchecked")
74
public class WeakSharedSet <E> extends AbstractSet<E> implements Set<E> {
74
public class WeakSet <E> extends AbstractSet<E> implements Set<E> {
75
    private final SharedKeyWeakHashMap<E, Boolean> m;  // The backing map
75
    private final SharedKeyWeakHashMap<E, Boolean> m;  // The backing map
76
    private transient Set<E> s;       // Its keySet
76
    private transient Set<E> s;       // Its keySet
77
77
78
    /**
78
    /**
79
     * Constructs a new, empty <tt>WeakSharedSet</tt> with the given initial
79
     * Constructs a new, empty <tt>WeakSet</tt> with the given initial
80
     * capacity and the given load factor.
80
     * capacity and the given load factor.
81
     *
81
     *
82
     * @param  initialCapacity The initial capacity of the <tt>WeakSharedSet</tt>
82
     * @param  initialCapacity The initial capacity of the <tt>WeakSet</tt>
83
     * @param  loadFactor      The load factor of the <tt>WeakSharedSet</tt>
83
     * @param  loadFactor      The load factor of the <tt>WeakSet</tt>
84
     * @throws IllegalArgumentException if the initial capacity is negative,
84
     * @throws IllegalArgumentException if the initial capacity is negative,
85
     *         or if the load factor is nonpositive.
85
     *         or if the load factor is nonpositive.
86
     */
86
     */
87
    public WeakSharedSet(int initialCapacity, float loadFactor) {
87
    public WeakSet(int initialCapacity, float loadFactor) {
88
        m = new SharedKeyWeakHashMap<E, Boolean>(initialCapacity, loadFactor);
88
        m = new SharedKeyWeakHashMap<E, Boolean>(initialCapacity, loadFactor);
89
        s = m.keySet();
89
        s = m.keySet();
90
    }
90
    }
91
91
92
    /**
92
    /**
93
     * Constructs a new, empty <tt>WeakSharedSet</tt> with the given initial
93
     * Constructs a new, empty <tt>WeakSet</tt> with the given initial
94
     * capacity and the default load factor (0.75).
94
     * capacity and the default load factor (0.75).
95
     *
95
     *
96
     * @param  initialCapacity The initial capacity of the <tt>WeakSharedSet</tt>
96
     * @param  initialCapacity The initial capacity of the <tt>WeakSet</tt>
97
     * @throws IllegalArgumentException if the initial capacity is negative
97
     * @throws IllegalArgumentException if the initial capacity is negative
98
     */
98
     */
99
    public WeakSharedSet(int initialCapacity) {
99
    public WeakSet(int initialCapacity) {
100
        this(initialCapacity, SharedKeyWeakHashMap.DEFAULT_LOAD_FACTOR);
100
        this(initialCapacity, SharedKeyWeakHashMap.DEFAULT_LOAD_FACTOR);
101
    }
101
    }
102
102
103
    /**
103
    /**
104
     * Constructs a new, empty <tt>WeakSharedSet</tt> with the default initial
104
     * Constructs a new, empty <tt>WeakSet</tt> with the default initial
105
     * capacity (16) and load factor (0.75).
105
     * capacity (16) and load factor (0.75).
106
     */
106
     */
107
    public WeakSharedSet() {
107
    public WeakSet() {
108
        m = new SharedKeyWeakHashMap<E, Boolean>();
108
        m = new SharedKeyWeakHashMap<E, Boolean>();
109
        s = m.keySet();
109
        s = m.keySet();
110
    }
110
    }
111
111
112
    /**
112
    /**
113
     * Constructs a new <tt>WeakSharedSet</tt> with the same mappings as the
113
     * Constructs a new <tt>WeakSet</tt> with the same mappings as the
114
     * specified map.  The <tt>WeakSharedSet</tt> is created with the default
114
     * specified map.  The <tt>WeakSet</tt> is created with the default
115
     * load factor (0.75) and an initial capacity sufficient to hold the
115
     * load factor (0.75) and an initial capacity sufficient to hold the
116
     * mappings in the specified map.
116
     * mappings in the specified map.
117
     *
117
     *
118
     * @param   m the map whose mappings are to be placed in this map
118
     * @param   m the map whose mappings are to be placed in this map
119
     * @throws  NullPointerException if the specified map is null
119
     * @throws  NullPointerException if the specified map is null
120
     */
120
     */
121
    public WeakSharedSet(Set<? extends E> s) {
121
    public WeakSet(Set<? extends E> s) {
122
        this(Math.max((int) (s.size() / SharedKeyWeakHashMap.DEFAULT_LOAD_FACTOR) + 1, 16),
122
        this(Math.max((int) (s.size() / SharedKeyWeakHashMap.DEFAULT_LOAD_FACTOR) + 1, 16),
123
                SharedKeyWeakHashMap.DEFAULT_LOAD_FACTOR);
123
                SharedKeyWeakHashMap.DEFAULT_LOAD_FACTOR);
124
        addAll(s);
124
        addAll(s);
Lines 140-146 Link Here
140
    }
140
    }
141
141
142
    /**
142
    /**
143
     * it is expected that method putIfAbsent is used instead of add
143
     * @see #putIfAbsent
144
     */
144
     */
145
    @Override
145
    @Override
146
    public boolean add(E e) { return m.put(e, null) == null; }
146
    public boolean add(E e) { return m.put(e, null) == null; }

Return to bug 192759