16 |
|
* vastly outnumber mutative operations, and you need |
17 |
|
* to prevent interference among threads during traversal. |
18 |
|
* <li>It is thread-safe. |
19 |
< |
* <li>Mutative operations (<tt>add</tt>, <tt>set</tt>, <tt>remove</tt>, etc.) |
19 |
> |
* <li>Mutative operations ({@code add}, {@code set}, {@code remove}, etc.) |
20 |
|
* are expensive since they usually entail copying the entire underlying |
21 |
|
* array. |
22 |
< |
* <li>Iterators do not support the mutative <tt>remove</tt> operation. |
22 |
> |
* <li>Iterators do not support the mutative {@code remove} operation. |
23 |
|
* <li>Traversal via iterators is fast and cannot encounter |
24 |
|
* interference from other threads. Iterators rely on |
25 |
|
* unchanging snapshots of the array at the time the iterators were |
92 |
|
} |
93 |
|
|
94 |
|
/** |
95 |
< |
* Returns <tt>true</tt> if this set contains no elements. |
95 |
> |
* Returns {@code true} if this set contains no elements. |
96 |
|
* |
97 |
< |
* @return <tt>true</tt> if this set contains no elements |
97 |
> |
* @return {@code true} if this set contains no elements |
98 |
|
*/ |
99 |
|
public boolean isEmpty() { |
100 |
|
return al.isEmpty(); |
101 |
|
} |
102 |
|
|
103 |
|
/** |
104 |
< |
* Returns <tt>true</tt> if this set contains the specified element. |
105 |
< |
* More formally, returns <tt>true</tt> if and only if this set |
106 |
< |
* contains an element <tt>e</tt> such that |
104 |
> |
* Returns {@code true} if this set contains the specified element. |
105 |
> |
* More formally, returns {@code true} if and only if this set |
106 |
> |
* contains an element {@code e} such that |
107 |
|
* <tt>(o==null ? e==null : o.equals(e))</tt>. |
108 |
|
* |
109 |
|
* @param o element whose presence in this set is to be tested |
110 |
< |
* @return <tt>true</tt> if this set contains the specified element |
110 |
> |
* @return {@code true} if this set contains the specified element |
111 |
|
*/ |
112 |
|
public boolean contains(Object o) { |
113 |
|
return al.contains(o); |
143 |
|
* <p>If this set fits in the specified array with room to spare |
144 |
|
* (i.e., the array has more elements than this set), the element in |
145 |
|
* the array immediately following the end of the set is set to |
146 |
< |
* <tt>null</tt>. (This is useful in determining the length of this |
146 |
> |
* {@code null}. (This is useful in determining the length of this |
147 |
|
* set <i>only</i> if the caller knows that this set does not contain |
148 |
|
* any null elements.) |
149 |
|
* |
156 |
|
* precise control over the runtime type of the output array, and may, |
157 |
|
* under certain circumstances, be used to save allocation costs. |
158 |
|
* |
159 |
< |
* <p>Suppose <tt>x</tt> is a set known to contain only strings. |
159 |
> |
* <p>Suppose {@code x} is a set known to contain only strings. |
160 |
|
* The following code can be used to dump the set into a newly allocated |
161 |
< |
* array of <tt>String</tt>: |
161 |
> |
* array of {@code String}: |
162 |
|
* |
163 |
|
* <pre> {@code String[] y = x.toArray(new String[0]);}</pre> |
164 |
|
* |
165 |
< |
* Note that <tt>toArray(new Object[0])</tt> is identical in function to |
166 |
< |
* <tt>toArray()</tt>. |
165 |
> |
* Note that {@code toArray(new Object[0])} is identical in function to |
166 |
> |
* {@code toArray()}. |
167 |
|
* |
168 |
|
* @param a the array into which the elements of this set are to be |
169 |
|
* stored, if it is big enough; otherwise, a new array of the same |
188 |
|
|
189 |
|
/** |
190 |
|
* Removes the specified element from this set if it is present. |
191 |
< |
* More formally, removes an element <tt>e</tt> such that |
191 |
> |
* More formally, removes an element {@code e} such that |
192 |
|
* <tt>(o==null ? e==null : o.equals(e))</tt>, |
193 |
< |
* if this set contains such an element. Returns <tt>true</tt> if |
193 |
> |
* if this set contains such an element. Returns {@code true} if |
194 |
|
* this set contained the element (or equivalently, if this set |
195 |
|
* changed as a result of the call). (This set will not contain the |
196 |
|
* element once the call returns.) |
197 |
|
* |
198 |
|
* @param o object to be removed from this set, if present |
199 |
< |
* @return <tt>true</tt> if this set contained the specified element |
199 |
> |
* @return {@code true} if this set contained the specified element |
200 |
|
*/ |
201 |
|
public boolean remove(Object o) { |
202 |
|
return al.remove(o); |
204 |
|
|
205 |
|
/** |
206 |
|
* Adds the specified element to this set if it is not already present. |
207 |
< |
* More formally, adds the specified element <tt>e</tt> to this set if |
208 |
< |
* the set contains no element <tt>e2</tt> such that |
207 |
> |
* More formally, adds the specified element {@code e} to this set if |
208 |
> |
* the set contains no element {@code e2} such that |
209 |
|
* <tt>(e==null ? e2==null : e.equals(e2))</tt>. |
210 |
|
* If this set already contains the element, the call leaves the set |
211 |
< |
* unchanged and returns <tt>false</tt>. |
211 |
> |
* unchanged and returns {@code false}. |
212 |
|
* |
213 |
|
* @param e element to be added to this set |
214 |
< |
* @return <tt>true</tt> if this set did not already contain the specified |
214 |
> |
* @return {@code true} if this set did not already contain the specified |
215 |
|
* element |
216 |
|
*/ |
217 |
|
public boolean add(E e) { |
219 |
|
} |
220 |
|
|
221 |
|
/** |
222 |
< |
* Returns <tt>true</tt> if this set contains all of the elements of the |
222 |
> |
* Returns {@code true} if this set contains all of the elements of the |
223 |
|
* specified collection. If the specified collection is also a set, this |
224 |
< |
* method returns <tt>true</tt> if it is a <i>subset</i> of this set. |
224 |
> |
* method returns {@code true} if it is a <i>subset</i> of this set. |
225 |
|
* |
226 |
|
* @param c collection to be checked for containment in this set |
227 |
< |
* @return <tt>true</tt> if this set contains all of the elements of the |
227 |
> |
* @return {@code true} if this set contains all of the elements of the |
228 |
|
* specified collection |
229 |
|
* @throws NullPointerException if the specified collection is null |
230 |
|
* @see #contains(Object) |
236 |
|
/** |
237 |
|
* Adds all of the elements in the specified collection to this set if |
238 |
|
* they're not already present. If the specified collection is also a |
239 |
< |
* set, the <tt>addAll</tt> operation effectively modifies this set so |
239 |
> |
* set, the {@code addAll} operation effectively modifies this set so |
240 |
|
* that its value is the <i>union</i> of the two sets. The behavior of |
241 |
|
* this operation is undefined if the specified collection is modified |
242 |
|
* while the operation is in progress. |
243 |
|
* |
244 |
|
* @param c collection containing elements to be added to this set |
245 |
< |
* @return <tt>true</tt> if this set changed as a result of the call |
245 |
> |
* @return {@code true} if this set changed as a result of the call |
246 |
|
* @throws NullPointerException if the specified collection is null |
247 |
|
* @see #add(Object) |
248 |
|
*/ |
257 |
|
* <i>asymmetric set difference</i> of the two sets. |
258 |
|
* |
259 |
|
* @param c collection containing elements to be removed from this set |
260 |
< |
* @return <tt>true</tt> if this set changed as a result of the call |
260 |
> |
* @return {@code true} if this set changed as a result of the call |
261 |
|
* @throws ClassCastException if the class of an element of this set |
262 |
|
* is incompatible with the specified collection (optional) |
263 |
|
* @throws NullPointerException if this set contains a null element and the |
278 |
|
* two sets. |
279 |
|
* |
280 |
|
* @param c collection containing elements to be retained in this set |
281 |
< |
* @return <tt>true</tt> if this set changed as a result of the call |
281 |
> |
* @return {@code true} if this set changed as a result of the call |
282 |
|
* @throws ClassCastException if the class of an element of this set |
283 |
|
* is incompatible with the specified collection (optional) |
284 |
|
* @throws NullPointerException if this set contains a null element and the |
297 |
|
* <p>The returned iterator provides a snapshot of the state of the set |
298 |
|
* when the iterator was constructed. No synchronization is needed while |
299 |
|
* traversing the iterator. The iterator does <em>NOT</em> support the |
300 |
< |
* <tt>remove</tt> method. |
300 |
> |
* {@code remove} method. |
301 |
|
* |
302 |
|
* @return an iterator over the elements in this set |
303 |
|
*/ |