1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util.concurrent; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import java.io.IOException; |
20 | |
import java.io.Serializable; |
21 | |
import java.util.AbstractSet; |
22 | |
import java.util.Collection; |
23 | |
import java.util.Iterator; |
24 | |
import java.util.Set; |
25 | |
|
26 | |
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap; |
27 | |
|
28 | |
public class ConcurrentHashSetextends AbstractSetimplements Set, Serializable |
29 | |
{ |
30 | |
private static final long serialVersionUID = 2454657854757543876L; |
31 | |
|
32 | |
private final ConcurrentHashMapmap; |
33 | |
private transient SetkeySet; |
34 | |
|
35 | |
public ConcurrentHashSet() |
36 | 392 | { |
37 | 392 | map = new ConcurrentHashMap(); |
38 | 392 | keySet = map.keySet(); |
39 | 392 | } |
40 | |
|
41 | |
public ConcurrentHashSet(int initialCapacity) |
42 | 0 | { |
43 | 0 | map = new ConcurrentHashMap(initialCapacity); |
44 | 0 | keySet = map.keySet(); |
45 | 0 | } |
46 | |
|
47 | |
public ConcurrentHashSet(int initialCapacity, float loadFactor, int concurrencyLevel) |
48 | 0 | { |
49 | 0 | map = new ConcurrentHashMap(initialCapacity, loadFactor, concurrencyLevel); |
50 | 0 | keySet = map.keySet(); |
51 | 0 | } |
52 | |
|
53 | |
public int size() |
54 | |
{ |
55 | 0 | return map.size(); |
56 | |
} |
57 | |
|
58 | |
public boolean isEmpty() |
59 | |
{ |
60 | 0 | return map.isEmpty(); |
61 | |
} |
62 | |
|
63 | |
public boolean contains(Object o) |
64 | |
{ |
65 | 0 | return map.containsKey(o); |
66 | |
} |
67 | |
|
68 | |
public Iteratoriterator() |
69 | |
{ |
70 | 3413 | return keySet.iterator(); |
71 | |
} |
72 | |
|
73 | |
public Object[] toArray() |
74 | |
{ |
75 | 0 | return keySet.toArray(); |
76 | |
} |
77 | |
|
78 | |
publicObject[] toArray(Object[]a) |
79 | |
{ |
80 | 0 | return keySet.toArray(a); |
81 | |
} |
82 | |
|
83 | |
public boolean add(Objecte) |
84 | |
{ |
85 | 24 | return map.put(e, Boolean.TRUE) == null; |
86 | |
} |
87 | |
|
88 | |
public boolean remove(Object o) |
89 | |
{ |
90 | 4 | return map.remove(o) != null; |
91 | |
} |
92 | |
|
93 | |
public boolean removeAll(Collectionc) |
94 | |
{ |
95 | 0 | return keySet.removeAll(c); |
96 | |
} |
97 | |
|
98 | |
public boolean retainAll(Collectionc) |
99 | |
{ |
100 | 0 | return keySet.retainAll(c); |
101 | |
} |
102 | |
|
103 | |
public void clear() |
104 | |
{ |
105 | 392 | map.clear(); |
106 | 392 | } |
107 | |
|
108 | |
public boolean equals(Object o) |
109 | |
{ |
110 | 0 | return keySet.equals(o); |
111 | |
} |
112 | |
|
113 | |
public int hashCode() |
114 | |
{ |
115 | 0 | return keySet.hashCode(); |
116 | |
} |
117 | |
|
118 | |
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException |
119 | |
{ |
120 | 0 | s.defaultReadObject(); |
121 | 0 | keySet = map.keySet(); |
122 | 0 | } |
123 | |
|
124 | |
} |