< prev index next >

src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java

Print this page




 130      *
 131      * @return the number of elements in this set
 132      */
 133     public int size() {
 134         return al.size();
 135     }
 136 
 137     /**
 138      * Returns {@code true} if this set contains no elements.
 139      *
 140      * @return {@code true} if this set contains no elements
 141      */
 142     public boolean isEmpty() {
 143         return al.isEmpty();
 144     }
 145 
 146     /**
 147      * Returns {@code true} if this set contains the specified element.
 148      * More formally, returns {@code true} if and only if this set
 149      * contains an element {@code e} such that
 150      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 151      *
 152      * @param o element whose presence in this set is to be tested
 153      * @return {@code true} if this set contains the specified element
 154      */
 155     public boolean contains(Object o) {
 156         return al.contains(o);
 157     }
 158 
 159     /**
 160      * Returns an array containing all of the elements in this set.
 161      * If this set makes any guarantees as to what order its elements
 162      * are returned by its iterator, this method must return the
 163      * elements in the same order.
 164      *
 165      * <p>The returned array will be "safe" in that no references to it
 166      * are maintained by this set.  (In other words, this method must
 167      * allocate a new array even if this set is backed by an array).
 168      * The caller is thus free to modify the returned array.
 169      *
 170      * <p>This method acts as bridge between array-based and collection-based


 215      * @throws ArrayStoreException if the runtime type of the specified array
 216      *         is not a supertype of the runtime type of every element in this
 217      *         set
 218      * @throws NullPointerException if the specified array is null
 219      */
 220     public <T> T[] toArray(T[] a) {
 221         return al.toArray(a);
 222     }
 223 
 224     /**
 225      * Removes all of the elements from this set.
 226      * The set will be empty after this call returns.
 227      */
 228     public void clear() {
 229         al.clear();
 230     }
 231 
 232     /**
 233      * Removes the specified element from this set if it is present.
 234      * More formally, removes an element {@code e} such that
 235      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>,
 236      * if this set contains such an element.  Returns {@code true} if
 237      * this set contained the element (or equivalently, if this set
 238      * changed as a result of the call).  (This set will not contain the
 239      * element once the call returns.)
 240      *
 241      * @param o object to be removed from this set, if present
 242      * @return {@code true} if this set contained the specified element
 243      */
 244     public boolean remove(Object o) {
 245         return al.remove(o);
 246     }
 247 
 248     /**
 249      * Adds the specified element to this set if it is not already present.
 250      * More formally, adds the specified element {@code e} to this set if
 251      * the set contains no element {@code e2} such that
 252      * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
 253      * If this set already contains the element, the call leaves the set
 254      * unchanged and returns {@code false}.
 255      *
 256      * @param e element to be added to this set
 257      * @return {@code true} if this set did not already contain the specified
 258      *         element
 259      */
 260     public boolean add(E e) {
 261         return al.addIfAbsent(e);
 262     }
 263 
 264     /**
 265      * Returns {@code true} if this set contains all of the elements of the
 266      * specified collection.  If the specified collection is also a set, this
 267      * method returns {@code true} if it is a <i>subset</i> of this set.
 268      *
 269      * @param  c collection to be checked for containment in this set
 270      * @return {@code true} if this set contains all of the elements of the
 271      *         specified collection
 272      * @throws NullPointerException if the specified collection is null




 130      *
 131      * @return the number of elements in this set
 132      */
 133     public int size() {
 134         return al.size();
 135     }
 136 
 137     /**
 138      * Returns {@code true} if this set contains no elements.
 139      *
 140      * @return {@code true} if this set contains no elements
 141      */
 142     public boolean isEmpty() {
 143         return al.isEmpty();
 144     }
 145 
 146     /**
 147      * Returns {@code true} if this set contains the specified element.
 148      * More formally, returns {@code true} if and only if this set
 149      * contains an element {@code e} such that
 150      * <code>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</code>.
 151      *
 152      * @param o element whose presence in this set is to be tested
 153      * @return {@code true} if this set contains the specified element
 154      */
 155     public boolean contains(Object o) {
 156         return al.contains(o);
 157     }
 158 
 159     /**
 160      * Returns an array containing all of the elements in this set.
 161      * If this set makes any guarantees as to what order its elements
 162      * are returned by its iterator, this method must return the
 163      * elements in the same order.
 164      *
 165      * <p>The returned array will be "safe" in that no references to it
 166      * are maintained by this set.  (In other words, this method must
 167      * allocate a new array even if this set is backed by an array).
 168      * The caller is thus free to modify the returned array.
 169      *
 170      * <p>This method acts as bridge between array-based and collection-based


 215      * @throws ArrayStoreException if the runtime type of the specified array
 216      *         is not a supertype of the runtime type of every element in this
 217      *         set
 218      * @throws NullPointerException if the specified array is null
 219      */
 220     public <T> T[] toArray(T[] a) {
 221         return al.toArray(a);
 222     }
 223 
 224     /**
 225      * Removes all of the elements from this set.
 226      * The set will be empty after this call returns.
 227      */
 228     public void clear() {
 229         al.clear();
 230     }
 231 
 232     /**
 233      * Removes the specified element from this set if it is present.
 234      * More formally, removes an element {@code e} such that
 235      * <code>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</code>,
 236      * if this set contains such an element.  Returns {@code true} if
 237      * this set contained the element (or equivalently, if this set
 238      * changed as a result of the call).  (This set will not contain the
 239      * element once the call returns.)
 240      *
 241      * @param o object to be removed from this set, if present
 242      * @return {@code true} if this set contained the specified element
 243      */
 244     public boolean remove(Object o) {
 245         return al.remove(o);
 246     }
 247 
 248     /**
 249      * Adds the specified element to this set if it is not already present.
 250      * More formally, adds the specified element {@code e} to this set if
 251      * the set contains no element {@code e2} such that
 252      * <code>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</code>.
 253      * If this set already contains the element, the call leaves the set
 254      * unchanged and returns {@code false}.
 255      *
 256      * @param e element to be added to this set
 257      * @return {@code true} if this set did not already contain the specified
 258      *         element
 259      */
 260     public boolean add(E e) {
 261         return al.addIfAbsent(e);
 262     }
 263 
 264     /**
 265      * Returns {@code true} if this set contains all of the elements of the
 266      * specified collection.  If the specified collection is also a set, this
 267      * method returns {@code true} if it is a <i>subset</i> of this set.
 268      *
 269      * @param  c collection to be checked for containment in this set
 270      * @return {@code true} if this set contains all of the elements of the
 271      *         specified collection
 272      * @throws NullPointerException if the specified collection is null


< prev index next >