1
14
15 package com.liferay.portal.kernel.util;
16
17 import java.util.AbstractSet;
18 import java.util.Iterator;
19 import java.util.Map;
20 import java.util.Set;
21 import java.util.concurrent.ConcurrentHashMap;
22
23
28 public class ConcurrentHashSet<E> extends AbstractSet<E> {
29
30 public ConcurrentHashSet() {
31 _map = new ConcurrentHashMap<E, String>();
32 }
33
34 public ConcurrentHashSet(int capacity) {
35 _map = new ConcurrentHashMap<E, String>(capacity);
36 }
37
38 public ConcurrentHashSet(Set<E> set) {
39 Iterator<E> itr = set.iterator();
40
41 while (itr.hasNext()) {
42 E e = itr.next();
43
44 _map.put(e, StringPool.BLANK);
45 }
46 }
47
48 public boolean add(E e) {
49 if (_map.put(e, StringPool.BLANK) == null) {
50 return true;
51 }
52 else {
53 return false;
54 }
55 }
56
57 public void clear() {
58 _map.clear();
59 }
60
61 public boolean contains(Object obj) {
62 if (_map.containsKey(obj)) {
63 return true;
64 }
65 else {
66 return false;
67 }
68 }
69
70 public Iterator<E> iterator() {
71 return _map.keySet().iterator();
72 }
73
74 public boolean remove(Object obj) {
75 if (_map.remove(obj) == null) {
76 return false;
77 }
78 else {
79 return true;
80 }
81 }
82
83 public int size() {
84 return _map.size();
85 }
86
87 private Map<E, String> _map;
88
89 }