1
22
23 package com.liferay.util;
24
25 import com.liferay.portal.kernel.util.StringPool;
26
27 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
28
29 import java.util.AbstractSet;
30 import java.util.Iterator;
31 import java.util.Map;
32 import java.util.Set;
33
34
40 public class ConcurrentHashSet extends AbstractSet {
41
42 public ConcurrentHashSet() {
43 _map = new ConcurrentHashMap();
44 }
45
46 public ConcurrentHashSet(int capacity) {
47 _map = new ConcurrentHashMap(capacity);
48 }
49
50 public ConcurrentHashSet(Set set) {
51 Iterator itr = set.iterator();
52
53 while (itr.hasNext()) {
54 Object obj = (Object)itr.next();
55
56 _map.put(obj, StringPool.BLANK);
57 }
58 }
59
60 public boolean add(Object obj) {
61 if (_map.put(obj, StringPool.BLANK) == null) {
62 return true;
63 }
64 else {
65 return false;
66 }
67 }
68
69 public void clear() {
70 _map.clear();
71 }
72
73 public boolean contains(Object obj) {
74 if (_map.containsKey(obj)) {
75 return true;
76 }
77 else {
78 return false;
79 }
80 }
81
82 public Iterator iterator() {
83 return _map.keySet().iterator();
84 }
85
86 public boolean remove(Object obj) {
87 if (_map.remove(obj) == null) {
88 return false;
89 }
90 else {
91 return true;
92 }
93 }
94
95 public int size() {
96 return _map.size();
97 }
98
99 private Map _map;
100
101 }