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