src/share/classes/java/util/Set.java

Print this page
rev 3977 : 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.


  93      * @return the number of elements in this set (its cardinality)
  94      */
  95     int size();
  96 
  97     /**
  98      * Returns <tt>true</tt> if this set contains no elements.
  99      *
 100      * @return <tt>true</tt> if this set contains no elements
 101      */
 102     boolean isEmpty();
 103 
 104     /**
 105      * Returns <tt>true</tt> if this set contains the specified element.
 106      * More formally, returns <tt>true</tt> if and only if this set
 107      * contains an element <tt>e</tt> such that
 108      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 109      *
 110      * @param o element whose presence in this set is to be tested
 111      * @return <tt>true</tt> if this set contains the specified element
 112      * @throws ClassCastException if the type of the specified element
 113      *         is incompatible with this set (optional)

 114      * @throws NullPointerException if the specified element is null and this
 115      *         set does not permit null elements (optional)

 116      */
 117     boolean contains(Object o);
 118 
 119     /**
 120      * Returns an iterator over the elements in this set.  The elements are
 121      * returned in no particular order (unless this set is an instance of some
 122      * class that provides a guarantee).
 123      *
 124      * @return an iterator over the elements in this set
 125      */
 126     Iterator<E> iterator();
 127 
 128     /**
 129      * Returns an array containing all of the elements in this set.
 130      * If this set makes any guarantees as to what order its elements
 131      * are returned by its iterator, this method must return the
 132      * elements in the same order.
 133      *
 134      * <p>The returned array will be "safe" in that no references to it
 135      * are maintained by this set.  (In other words, this method must


 219      *         set does not permit null elements
 220      * @throws IllegalArgumentException if some property of the specified element
 221      *         prevents it from being added to this set
 222      */
 223     boolean add(E e);
 224 
 225 
 226     /**
 227      * Removes the specified element from this set if it is present
 228      * (optional operation).  More formally, removes an element <tt>e</tt>
 229      * such that
 230      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
 231      * this set contains such an element.  Returns <tt>true</tt> if this set
 232      * contained the element (or equivalently, if this set changed as a
 233      * result of the call).  (This set will not contain the element once the
 234      * call returns.)
 235      *
 236      * @param o object to be removed from this set, if present
 237      * @return <tt>true</tt> if this set contained the specified element
 238      * @throws ClassCastException if the type of the specified element
 239      *         is incompatible with this set (optional)

 240      * @throws NullPointerException if the specified element is null and this
 241      *         set does not permit null elements (optional)

 242      * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 243      *         is not supported by this set
 244      */
 245     boolean remove(Object o);
 246 
 247 
 248     // Bulk Operations
 249 
 250     /**
 251      * Returns <tt>true</tt> if this set contains all of the elements of the
 252      * specified collection.  If the specified collection is also a set, this
 253      * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
 254      *
 255      * @param  c collection to be checked for containment in this set
 256      * @return <tt>true</tt> if this set contains all of the elements of the
 257      *         specified collection
 258      * @throws ClassCastException if the types of one or more elements
 259      *         in the specified collection are incompatible with this
 260      *         set (optional)

 261      * @throws NullPointerException if the specified collection contains one
 262      *         or more null elements and this set does not permit null
 263      *         elements (optional), or if the specified collection is null


 264      * @see    #contains(Object)
 265      */
 266     boolean containsAll(Collection<?> c);
 267 
 268     /**
 269      * Adds all of the elements in the specified collection to this set if
 270      * they're not already present (optional operation).  If the specified
 271      * collection is also a set, the <tt>addAll</tt> operation effectively
 272      * modifies this set so that its value is the <i>union</i> of the two
 273      * sets.  The behavior of this operation is undefined if the specified
 274      * collection is modified while the operation is in progress.
 275      *
 276      * @param  c collection containing elements to be added to this set
 277      * @return <tt>true</tt> if this set changed as a result of the call
 278      *
 279      * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
 280      *         is not supported by this set
 281      * @throws ClassCastException if the class of an element of the
 282      *         specified collection prevents it from being added to this set
 283      * @throws NullPointerException if the specified collection contains one


 285      *         elements, or if the specified collection is null
 286      * @throws IllegalArgumentException if some property of an element of the
 287      *         specified collection prevents it from being added to this set
 288      * @see #add(Object)
 289      */
 290     boolean addAll(Collection<? extends E> c);
 291 
 292     /**
 293      * Retains only the elements in this set that are contained in the
 294      * specified collection (optional operation).  In other words, removes
 295      * from this set all of its elements that are not contained in the
 296      * specified collection.  If the specified collection is also a set, this
 297      * operation effectively modifies this set so that its value is the
 298      * <i>intersection</i> of the two sets.
 299      *
 300      * @param  c collection containing elements to be retained in this set
 301      * @return <tt>true</tt> if this set changed as a result of the call
 302      * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
 303      *         is not supported by this set
 304      * @throws ClassCastException if the class of an element of this set
 305      *         is incompatible with the specified collection (optional)

 306      * @throws NullPointerException if this set contains a null element and the
 307      *         specified collection does not permit null elements (optional),

 308      *         or if the specified collection is null
 309      * @see #remove(Object)
 310      */
 311     boolean retainAll(Collection<?> c);
 312 
 313     /**
 314      * Removes from this set all of its elements that are contained in the
 315      * specified collection (optional operation).  If the specified
 316      * collection is also a set, this operation effectively modifies this
 317      * set so that its value is the <i>asymmetric set difference</i> of
 318      * the two sets.
 319      *
 320      * @param  c collection containing elements to be removed from this set
 321      * @return <tt>true</tt> if this set changed as a result of the call
 322      * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
 323      *         is not supported by this set
 324      * @throws ClassCastException if the class of an element of this set
 325      *         is incompatible with the specified collection (optional)

 326      * @throws NullPointerException if this set contains a null element and the
 327      *         specified collection does not permit null elements (optional),

 328      *         or if the specified collection is null
 329      * @see #remove(Object)
 330      * @see #contains(Object)
 331      */
 332     boolean removeAll(Collection<?> c);
 333 
 334     /**
 335      * Removes all of the elements from this set (optional operation).
 336      * The set will be empty after this call returns.
 337      *
 338      * @throws UnsupportedOperationException if the <tt>clear</tt> method
 339      *         is not supported by this set
 340      */
 341     void clear();
 342 
 343 
 344     // Comparison and hashing
 345 
 346     /**
 347      * Compares the specified object with this set for equality.  Returns




  93      * @return the number of elements in this set (its cardinality)
  94      */
  95     int size();
  96 
  97     /**
  98      * Returns <tt>true</tt> if this set contains no elements.
  99      *
 100      * @return <tt>true</tt> if this set contains no elements
 101      */
 102     boolean isEmpty();
 103 
 104     /**
 105      * Returns <tt>true</tt> if this set contains the specified element.
 106      * More formally, returns <tt>true</tt> if and only if this set
 107      * contains an element <tt>e</tt> such that
 108      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 109      *
 110      * @param o element whose presence in this set is to be tested
 111      * @return <tt>true</tt> if this set contains the specified element
 112      * @throws ClassCastException if the type of the specified element
 113      *         is incompatible with this set
 114      * (<a href="Collection.html#optional-restrictions">optional</a>)
 115      * @throws NullPointerException if the specified element is null and this
 116      *         set does not permit null elements
 117      * (<a href="Collection.html#optional-restrictions">optional</a>)
 118      */
 119     boolean contains(Object o);
 120 
 121     /**
 122      * Returns an iterator over the elements in this set.  The elements are
 123      * returned in no particular order (unless this set is an instance of some
 124      * class that provides a guarantee).
 125      *
 126      * @return an iterator over the elements in this set
 127      */
 128     Iterator<E> iterator();
 129 
 130     /**
 131      * Returns an array containing all of the elements in this set.
 132      * If this set makes any guarantees as to what order its elements
 133      * are returned by its iterator, this method must return the
 134      * elements in the same order.
 135      *
 136      * <p>The returned array will be "safe" in that no references to it
 137      * are maintained by this set.  (In other words, this method must


 221      *         set does not permit null elements
 222      * @throws IllegalArgumentException if some property of the specified element
 223      *         prevents it from being added to this set
 224      */
 225     boolean add(E e);
 226 
 227 
 228     /**
 229      * Removes the specified element from this set if it is present
 230      * (optional operation).  More formally, removes an element <tt>e</tt>
 231      * such that
 232      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
 233      * this set contains such an element.  Returns <tt>true</tt> if this set
 234      * contained the element (or equivalently, if this set changed as a
 235      * result of the call).  (This set will not contain the element once the
 236      * call returns.)
 237      *
 238      * @param o object to be removed from this set, if present
 239      * @return <tt>true</tt> if this set contained the specified element
 240      * @throws ClassCastException if the type of the specified element
 241      *         is incompatible with this set
 242      * (<a href="Collection.html#optional-restrictions">optional</a>)
 243      * @throws NullPointerException if the specified element is null and this
 244      *         set does not permit null elements
 245      * (<a href="Collection.html#optional-restrictions">optional</a>)
 246      * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 247      *         is not supported by this set
 248      */
 249     boolean remove(Object o);
 250 
 251 
 252     // Bulk Operations
 253 
 254     /**
 255      * Returns <tt>true</tt> if this set contains all of the elements of the
 256      * specified collection.  If the specified collection is also a set, this
 257      * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
 258      *
 259      * @param  c collection to be checked for containment in this set
 260      * @return <tt>true</tt> if this set contains all of the elements of the
 261      *         specified collection
 262      * @throws ClassCastException if the types of one or more elements
 263      *         in the specified collection are incompatible with this
 264      *         set
 265      * (<a href="Collection.html#optional-restrictions">optional</a>)
 266      * @throws NullPointerException if the specified collection contains one
 267      *         or more null elements and this set does not permit null
 268      *         elements
 269      * (<a href="Collection.html#optional-restrictions">optional</a>),
 270      *         or if the specified collection is null
 271      * @see    #contains(Object)
 272      */
 273     boolean containsAll(Collection<?> c);
 274 
 275     /**
 276      * Adds all of the elements in the specified collection to this set if
 277      * they're not already present (optional operation).  If the specified
 278      * collection is also a set, the <tt>addAll</tt> operation effectively
 279      * modifies this set so that its value is the <i>union</i> of the two
 280      * sets.  The behavior of this operation is undefined if the specified
 281      * collection is modified while the operation is in progress.
 282      *
 283      * @param  c collection containing elements to be added to this set
 284      * @return <tt>true</tt> if this set changed as a result of the call
 285      *
 286      * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
 287      *         is not supported by this set
 288      * @throws ClassCastException if the class of an element of the
 289      *         specified collection prevents it from being added to this set
 290      * @throws NullPointerException if the specified collection contains one


 292      *         elements, or if the specified collection is null
 293      * @throws IllegalArgumentException if some property of an element of the
 294      *         specified collection prevents it from being added to this set
 295      * @see #add(Object)
 296      */
 297     boolean addAll(Collection<? extends E> c);
 298 
 299     /**
 300      * Retains only the elements in this set that are contained in the
 301      * specified collection (optional operation).  In other words, removes
 302      * from this set all of its elements that are not contained in the
 303      * specified collection.  If the specified collection is also a set, this
 304      * operation effectively modifies this set so that its value is the
 305      * <i>intersection</i> of the two sets.
 306      *
 307      * @param  c collection containing elements to be retained in this set
 308      * @return <tt>true</tt> if this set changed as a result of the call
 309      * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
 310      *         is not supported by this set
 311      * @throws ClassCastException if the class of an element of this set
 312      *         is incompatible with the specified collection
 313      * (<a href="Collection.html#optional-restrictions">optional</a>)
 314      * @throws NullPointerException if this set contains a null element and the
 315      *         specified collection does not permit null elements
 316      *         (<a href="Collection.html#optional-restrictions">optional</a>),
 317      *         or if the specified collection is null
 318      * @see #remove(Object)
 319      */
 320     boolean retainAll(Collection<?> c);
 321 
 322     /**
 323      * Removes from this set all of its elements that are contained in the
 324      * specified collection (optional operation).  If the specified
 325      * collection is also a set, this operation effectively modifies this
 326      * set so that its value is the <i>asymmetric set difference</i> of
 327      * the two sets.
 328      *
 329      * @param  c collection containing elements to be removed from this set
 330      * @return <tt>true</tt> if this set changed as a result of the call
 331      * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
 332      *         is not supported by this set
 333      * @throws ClassCastException if the class of an element of this set
 334      *         is incompatible with the specified collection
 335      * (<a href="Collection.html#optional-restrictions">optional</a>)
 336      * @throws NullPointerException if this set contains a null element and the
 337      *         specified collection does not permit null elements
 338      *         (<a href="Collection.html#optional-restrictions">optional</a>),
 339      *         or if the specified collection is null
 340      * @see #remove(Object)
 341      * @see #contains(Object)
 342      */
 343     boolean removeAll(Collection<?> c);
 344 
 345     /**
 346      * Removes all of the elements from this set (optional operation).
 347      * The set will be empty after this call returns.
 348      *
 349      * @throws UnsupportedOperationException if the <tt>clear</tt> method
 350      *         is not supported by this set
 351      */
 352     void clear();
 353 
 354 
 355     // Comparison and hashing
 356 
 357     /**
 358      * Compares the specified object with this set for equality.  Returns