1 7 8 package java.util.concurrent; 9 import java.util.*; 10 11 61 public class CopyOnWriteArraySet<E> extends AbstractSet<E> 62 implements java.io.Serializable { 63 private static final long serialVersionUID = 5457747651344034263L; 64 65 private final CopyOnWriteArrayList <E> al; 66 67 70 public CopyOnWriteArraySet() { 71 al = new CopyOnWriteArrayList <E>(); 72 } 73 74 79 public CopyOnWriteArraySet(Collection<? extends E> c) { 80 al = new CopyOnWriteArrayList <E>(); 81 al.addAllAbsent(c); 82 } 83 84 85 public int size() { return al.size(); } 86 public boolean isEmpty() { return al.isEmpty(); } 87 public boolean contains(Object o) { return al.contains(o); } 88 public Object [] toArray() { return al.toArray(); } 89 public <T> T[] toArray(T[] a) { return al.toArray(a); } 90 public void clear() { al.clear(); } 91 public Iterator<E> iterator() { return al.iterator(); } 92 public boolean remove(Object o) { return al.remove(o); } 93 public boolean add(E o) { return al.addIfAbsent(o); } 94 public boolean containsAll(Collection<?> c) { return al.containsAll(c); } 95 public boolean addAll(Collection<? extends E> c) { return al.addAllAbsent(c) > 0; } 96 public boolean removeAll(Collection<?> c) { return al.removeAll(c); } 97 public boolean retainAll(Collection<?> c) { return al.retainAll(c); } 98 99 } 100 | Popular Tags |