2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.util;
21 import java.util.AbstractSet;
22 import java.util.Collection;
23 import java.util.Iterator;
26 import java.util.concurrent.ConcurrentHashMap;
28 public class ConcurrentHashSet<E> extends AbstractSet<E> implements Set<E>
30 private final Map<E, Boolean> _map = new ConcurrentHashMap<E, Boolean>();
31 private transient Set<E> _keys = _map.keySet();
33 public ConcurrentHashSet()
38 public boolean add(E e)
40 return _map.put(e,Boolean.TRUE) == null;
50 public boolean contains(Object o)
52 return _map.containsKey(o);
56 public boolean containsAll(Collection<?> c)
58 return _keys.containsAll(c);
62 public boolean equals(Object o)
64 return o == this || _keys.equals(o);
70 return _keys.hashCode();
74 public boolean isEmpty()
76 return _map.isEmpty();
80 public Iterator<E> iterator()
82 return _keys.iterator();
86 public boolean remove(Object o)
88 return _map.remove(o) != null;
92 public boolean removeAll(Collection<?> c)
94 return _keys.removeAll(c);
98 public boolean retainAll(Collection<?> c)
100 return _keys.retainAll(c);
110 public Object[] toArray()
112 return _keys.toArray();
116 public <T> T[] toArray(T[] a)
118 return _keys.toArray(a);
122 public String toString()
124 return _keys.toString();