001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.util.AbstractSet;
018 import java.util.Iterator;
019 import java.util.Map;
020 import java.util.Set;
021 import java.util.concurrent.ConcurrentHashMap;
022
023
026 public class ConcurrentHashSet<E> extends AbstractSet<E> {
027
028 public ConcurrentHashSet() {
029 _map = new ConcurrentHashMap<E, String>();
030 }
031
032 public ConcurrentHashSet(int capacity) {
033 _map = new ConcurrentHashMap<E, String>(capacity);
034 }
035
036 public ConcurrentHashSet(Set<E> set) {
037 Iterator<E> itr = set.iterator();
038
039 while (itr.hasNext()) {
040 E e = itr.next();
041
042 _map.put(e, StringPool.BLANK);
043 }
044 }
045
046 public boolean add(E e) {
047 if (_map.put(e, StringPool.BLANK) == null) {
048 return true;
049 }
050 else {
051 return false;
052 }
053 }
054
055 public void clear() {
056 _map.clear();
057 }
058
059 public boolean contains(Object obj) {
060 if (_map.containsKey(obj)) {
061 return true;
062 }
063 else {
064 return false;
065 }
066 }
067
068 public Iterator<E> iterator() {
069 return _map.keySet().iterator();
070 }
071
072 public boolean remove(Object obj) {
073 if (_map.remove(obj) == null) {
074 return false;
075 }
076 else {
077 return true;
078 }
079 }
080
081 public int size() {
082 return _map.size();
083 }
084
085 private Map<E, String> _map;
086
087 }