1 |
| package org.jboss.cache.util.concurrent; |
2 |
| |
3 |
| import java.util.AbstractSet; |
4 |
| import java.util.Collection; |
5 |
| import java.util.Iterator; |
6 |
| import java.util.concurrent.ConcurrentHashMap; |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| public class ConcurrentHashSet<E> extends AbstractSet<E> |
18 |
| { |
19 |
| protected ConcurrentHashMap<E, Object> map; |
20 |
| private static final Object DUMMY = new Object(); |
21 |
| |
22 |
3257
| public ConcurrentHashSet()
|
23 |
| { |
24 |
3257
| map = new ConcurrentHashMap<E, Object>();
|
25 |
| } |
26 |
| |
27 |
0
| public int size()
|
28 |
| { |
29 |
0
| return map.size();
|
30 |
| } |
31 |
| |
32 |
0
| public boolean isEmpty()
|
33 |
| { |
34 |
0
| return map.isEmpty();
|
35 |
| } |
36 |
| |
37 |
12791
| public boolean contains(Object o)
|
38 |
| { |
39 |
12791
| return map.containsKey(o);
|
40 |
| } |
41 |
| |
42 |
730
| public Iterator<E> iterator()
|
43 |
| { |
44 |
730
| return map.keySet().iterator();
|
45 |
| } |
46 |
0
| public Object[] toArray()
|
47 |
| { |
48 |
0
| return map.keySet().toArray();
|
49 |
| } |
50 |
| |
51 |
0
| public <T> T[] toArray(T[] a)
|
52 |
| { |
53 |
0
| return map.keySet().toArray(a);
|
54 |
| } |
55 |
| |
56 |
575
| public boolean add(E o)
|
57 |
| { |
58 |
575
| Object v = map.put(o, DUMMY);
|
59 |
575
| return v == null;
|
60 |
| } |
61 |
| |
62 |
168
| public boolean remove(Object o)
|
63 |
| { |
64 |
168
| Object v = map.remove(o);
|
65 |
168
| return v != null;
|
66 |
| } |
67 |
| |
68 |
0
| public boolean containsAll(Collection<?> c)
|
69 |
| { |
70 |
0
| return map.keySet().containsAll(c);
|
71 |
| } |
72 |
| |
73 |
0
| public boolean addAll(Collection<? extends E> c)
|
74 |
| { |
75 |
0
| throw new UnsupportedOperationException("Not supported in this implementation since additional locking is required and cannot directly be delegated to multiple calls to ConcurrentHashMap");
|
76 |
| } |
77 |
| |
78 |
0
| public boolean retainAll(Collection<?> c)
|
79 |
| { |
80 |
0
| throw new UnsupportedOperationException("Not supported in this implementation since additional locking is required and cannot directly be delegated to multiple calls to ConcurrentHashMap");
|
81 |
| } |
82 |
| |
83 |
0
| public boolean removeAll(Collection<?> c)
|
84 |
| { |
85 |
0
| throw new UnsupportedOperationException("Not supported in this implementation since additional locking is required and cannot directly be delegated to multiple calls to ConcurrentHashMap");
|
86 |
| } |
87 |
| |
88 |
0
| public void clear()
|
89 |
| { |
90 |
0
| map.clear();
|
91 |
| } |
92 |
| } |