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 {
33 map = new ConcurrentHashMap();
34 keySet = map.keySet();
35 }
36
37 public ConcurrentHashSet(int initialCapacity)
38 {
39 map = new ConcurrentHashMap(initialCapacity);
40 keySet = map.keySet();
41 }
42
43 public ConcurrentHashSet(int initialCapacity, float loadFactor, int concurrencyLevel)
44 {
45 map = new ConcurrentHashMap(initialCapacity, loadFactor, concurrencyLevel);
46 keySet = map.keySet();
47 }
48
49 public int size()
50 {
51 return map.size();
52 }
53
54 public boolean isEmpty()
55 {
56 return map.isEmpty();
57 }
58
59 public boolean contains(Object o)
60 {
61 return map.containsKey(o);
62 }
63
64 public Iteratoriterator()
65 {
66 return keySet.iterator();
67 }
68
69 public Object[] toArray()
70 {
71 return keySet.toArray();
72 }
73
74 publicObject[] toArray(Object[]a)
75 {
76 return keySet.toArray(a);
77 }
78
79 public boolean add(Objecte)
80 {
81 return map.put(e, Boolean.TRUE) == null;
82 }
83
84 public boolean remove(Object o)
85 {
86 return map.remove(o) != null;
87 }
88
89 public boolean removeAll(Collectionc)
90 {
91 return keySet.removeAll(c);
92 }
93
94 public boolean retainAll(Collectionc)
95 {
96 return keySet.retainAll(c);
97 }
98
99 public void clear()
100 {
101 map.clear();
102 }
103
104 public boolean equals(Object o)
105 {
106 return keySet.equals(o);
107 }
108
109 public int hashCode()
110 {
111 return keySet.hashCode();
112 }
113
114 private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException
115 {
116 s.defaultReadObject();
117 keySet = map.keySet();
118 }
119
120 }