28 |
|
* other operations. |
29 |
|
* |
30 |
|
* <p>Beware that, unlike in most collections, the <tt>size</tt> |
31 |
< |
* method is <em>NOT</em> a constant-time operation. Because of the |
31 |
> |
* method is <em>not</em> a constant-time operation. Because of the |
32 |
|
* asynchronous nature of these sets, determining the current number |
33 |
< |
* of elements requires a traversal of the elements. |
33 |
> |
* of elements requires a traversal of the elements. Additionally, the |
34 |
> |
* bulk operations <tt>addAll</tt>, <tt>removeAll</tt>, |
35 |
> |
* <<tt>retainAll</tt>, and tt>containsAll</tt> are <em>not</em> |
36 |
> |
* guaranteed to be performed atomically. For example, an iterator |
37 |
> |
* operating concurrently with an <tt>addAll</tt> operation might view |
38 |
> |
* only some of the added elements. |
39 |
|
* |
40 |
|
* <p>This class and its iterators implement all of the |
41 |
|
* <em>optional</em> methods of the {@link Set} and {@link Iterator} |
90 |
|
* |
91 |
|
* @throws ClassCastException if the elements in the specified |
92 |
|
* collection are not comparable, or are not mutually comparable. |
93 |
< |
* @throws NullPointerException if the specified collection is <tt>null</tt>. |
93 |
> |
* @throws NullPointerException if the specified collection is |
94 |
> |
* <tt>null</tt>. |
95 |
|
*/ |
96 |
|
public ConcurrentSkipListSet(Collection<? extends E> c) { |
97 |
|
m = new ConcurrentSkipListMap<E,Object>(); |
103 |
|
* sorted set, sorted according to the same ordering. |
104 |
|
* |
105 |
|
* @param s sorted set whose elements will comprise the new set. |
106 |
< |
* @throws NullPointerException if the specified sorted set is <tt>null</tt>. |
106 |
> |
* @throws NullPointerException if the specified sorted set is |
107 |
> |
* <tt>null</tt>. |
108 |
|
*/ |
109 |
|
public ConcurrentSkipListSet(SortedSet<E> s) { |
110 |
|
m = new ConcurrentSkipListMap<E,Object>(s.comparator()); |
219 |
|
public Iterator<E> iterator() { |
220 |
|
return m.keyIterator(); |
221 |
|
} |
222 |
+ |
|
223 |
+ |
/* ---------------- AbstractSet Overrides -------------- */ |
224 |
+ |
|
225 |
+ |
/** |
226 |
+ |
* Compares the specified object with this set for equality. Returns |
227 |
+ |
* <tt>true</tt> if the specified object is also a set, the two sets |
228 |
+ |
* have the same size, and every member of the specified set is |
229 |
+ |
* contained in this set (or equivalently, every member of this set is |
230 |
+ |
* contained in the specified set). This definition ensures that the |
231 |
+ |
* equals method works properly across different implementations of the |
232 |
+ |
* set interface. |
233 |
+ |
* |
234 |
+ |
* @param o Object to be compared for equality with this set. |
235 |
+ |
* @return <tt>true</tt> if the specified Object is equal to this set. |
236 |
+ |
*/ |
237 |
+ |
public boolean equals(Object o) { |
238 |
+ |
// Override AbstractSet version to avoid calling size() |
239 |
+ |
if (o == this) |
240 |
+ |
return true; |
241 |
+ |
if (!(o instanceof Set)) |
242 |
+ |
return false; |
243 |
+ |
Collection c = (Collection) o; |
244 |
+ |
try { |
245 |
+ |
return containsAll(c) && c.containsAll(this); |
246 |
+ |
} catch(ClassCastException unused) { |
247 |
+ |
return false; |
248 |
+ |
} catch(NullPointerException unused) { |
249 |
+ |
return false; |
250 |
+ |
} |
251 |
+ |
} |
252 |
+ |
|
253 |
+ |
/** |
254 |
+ |
* Removes from this set all of its elements that are contained in |
255 |
+ |
* the specified collection. If the specified collection is also |
256 |
+ |
* a set, this operation effectively modifies this set so that its |
257 |
+ |
* value is the <i>asymmetric set difference</i> of the two sets. |
258 |
+ |
* |
259 |
+ |
* @param c collection that defines which elements will be removed from |
260 |
+ |
* this set. |
261 |
+ |
* @return <tt>true</tt> if this set changed as a result of the call. |
262 |
+ |
* |
263 |
+ |
* @throws ClassCastException if the types of one or more elements in this |
264 |
+ |
* set are incompatible with the specified collection |
265 |
+ |
* @throws NullPointerException if the specified collection, or any |
266 |
+ |
* of its elements are <tt>null</tt>. |
267 |
+ |
*/ |
268 |
+ |
public boolean removeAll(Collection<?> c) { |
269 |
+ |
// Override AbstractSet version to avoid unnecessary call to size() |
270 |
+ |
boolean modified = false; |
271 |
+ |
for (Iterator<?> i = c.iterator(); i.hasNext(); ) |
272 |
+ |
if (remove(i.next())) |
273 |
+ |
modified = true; |
274 |
+ |
return modified; |
275 |
+ |
} |
276 |
|
|
277 |
|
/* ---------------- Relational operations -------------- */ |
278 |
|
|
281 |
|
* <tt>null</tt> if there is no such element. |
282 |
|
* |
283 |
|
* @param o the value to match |
284 |
< |
* @return an element greater than or equal to given element, or <tt>null</tt> |
285 |
< |
* if there is no such element. |
284 |
> |
* @return an element greater than or equal to given element, or |
285 |
> |
* <tt>null</tt> if there is no such element. |
286 |
|
* @throws ClassCastException if o cannot be compared with the elements |
287 |
|
* currently in the set. |
288 |
|
* @throws NullPointerException if o is <tt>null</tt> |
292 |
|
} |
293 |
|
|
294 |
|
/** |
295 |
< |
* Returns an element strictly less than the given element, or <tt>null</tt> if |
296 |
< |
* there is no such element. |
295 |
> |
* Returns an element strictly less than the given element, or |
296 |
> |
* <tt>null</tt> if there is no such element. |
297 |
|
* |
298 |
|
* @param o the value to match |
299 |
|
* @return the greatest element less than the given element, or |
307 |
|
} |
308 |
|
|
309 |
|
/** |
310 |
< |
* Returns an element less than or equal to the given element, or <tt>null</tt> |
311 |
< |
* if there is no such element. |
310 |
> |
* Returns an element less than or equal to the given element, or |
311 |
> |
* <tt>null</tt> if there is no such element. |
312 |
|
* |
313 |
|
* @param o the value to match |
314 |
|
* @return the greatest element less than or equal to given |
322 |
|
} |
323 |
|
|
324 |
|
/** |
325 |
< |
* Returns an element strictly greater than the given element, or <tt>null</tt> |
326 |
< |
* if there is no such element. |
325 |
> |
* Returns an element strictly greater than the given element, or |
326 |
> |
* <tt>null</tt> if there is no such element. |
327 |
|
* |
328 |
|
* @param o the value to match |
329 |
|
* @return the least element greater than the given element, or |
389 |
|
return m.lastKey(); |
390 |
|
} |
391 |
|
|
392 |
+ |
|
393 |
+ |
|
394 |
|
/** |
395 |
|
* Returns a view of the portion of this set whose elements range from |
396 |
|
* <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive. (If |
797 |
|
fromElement, fence); |
798 |
|
} |
799 |
|
} |
737 |
– |
|
738 |
– |
|
800 |
|
} |