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