ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166x/ConcurrentSkipListSet.java
(Generate patch)

Comparing jsr166/src/jsr166x/ConcurrentSkipListSet.java (file contents):
Revision 1.2 by dl, Mon Sep 6 17:01:54 2004 UTC vs.
Revision 1.4 by dl, Sat Oct 16 14:49:45 2004 UTC

# Line 28 | Line 28 | import java.util.concurrent.*;
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}
42   * interfaces. Like most other concurrent collection implementations,
43   * this class does not permit the use of <tt>null</tt> elements.
44 < * because null arguments and return values cannot be reliably
44 > * because <tt>null</tt> arguments and return values cannot be reliably
45   * distinguished from the absence of elements.
46   *
47   * @author Doug Lea
# Line 85 | Line 90 | public class ConcurrentSkipListSet<E>
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 null.
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>();
# Line 97 | Line 103 | public class ConcurrentSkipListSet<E>
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 null.
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());
# Line 212 | Line 219 | public class ConcurrentSkipListSet<E>
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  
279      /**
280       * Returns an element greater than or equal to the given element, or
281 <     * null if there is no such element.
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 null
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>
# Line 231 | Line 292 | public class ConcurrentSkipListSet<E>
292      }
293  
294      /**
295 <     * Returns an element strictly less than the given element, or null 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
300 <     * null if there is no such element.
300 >     * <tt>null</tt> if there is no such element.
301       * @throws ClassCastException if o cannot be compared with the elements
302       *            currently in the set.
303       * @throws NullPointerException if o is <tt>null</tt>.
# Line 246 | Line 307 | public class ConcurrentSkipListSet<E>
307      }
308  
309      /**
310 <     * Returns an element less than or equal to the given element, or null
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
315 <     * element, or null if there is no such element.
315 >     * element, or <tt>null</tt> if there is no such element.
316       * @throws ClassCastException if o cannot be compared with the elements
317       *            currently in the set.
318       * @throws NullPointerException if o is <tt>null</tt>.
# Line 261 | Line 322 | public class ConcurrentSkipListSet<E>
322      }
323  
324      /**
325 <     * Returns an element strictly greater than the given element, or null
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
330 <     * null if there is no such element.
330 >     * <tt>null</tt> if there is no such element.
331       * @throws ClassCastException if o cannot be compared with the elements
332       *            currently in the set.
333       * @throws NullPointerException if o is <tt>null</tt>.
# Line 328 | Line 389 | public class ConcurrentSkipListSet<E>
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
# Line 411 | Line 474 | public class ConcurrentSkipListSet<E>
474          
475          /**
476           * Creates a new submap.
477 <         * @param fromElement inclusive least value, or null if from start
478 <         * @param toElement exclusive upper bound or null if to end
477 >         * @param fromElement inclusive least value, or <tt>null</tt> if from start
478 >         * @param toElement exclusive upper bound or <tt>null</tt> if to end
479           * @throws IllegalArgumentException if fromElement and toElement
480           * nonnull and fromElement greater than toElement
481           */
# Line 520 | Line 583 | public class ConcurrentSkipListSet<E>
583  
584          /**
585           * Returns an element greater than or equal to the given
586 <         * element, or null if there is no such element.
586 >         * element, or <tt>null</tt> if there is no such element.
587           *
588           * @param o the value to match
589 <         * @return an element greater than or equal to given element, or null
589 >         * @return an element greater than or equal to given element, or <tt>null</tt>
590           * if there is no such element.
591           * @throws ClassCastException if o cannot be compared with the
592           * elements currently in the set.
# Line 539 | Line 602 | public class ConcurrentSkipListSet<E>
602          }
603  
604          /**
605 <         * Returns an element strictly less than the given element, or null if
605 >         * Returns an element strictly less than the given element, or <tt>null</tt> if
606           * there is no such element.
607           *
608           * @param o the value to match
609           * @return the greatest element less than the given element, or
610 <         * null if there is no such element.
610 >         * <tt>null</tt> if there is no such element.
611           * @throws ClassCastException if o cannot be compared with the
612           * elements currently in the set.
613           * @throws NullPointerException if o is <tt>null</tt>.
# Line 555 | Line 618 | public class ConcurrentSkipListSet<E>
618          }
619  
620          /**
621 <         * Returns an element less than or equal to the given element, or null
621 >         * Returns an element less than or equal to the given element, or <tt>null</tt>
622           * if there is no such element.
623           *
624           * @param o the value to match
625           * @return the greatest element less than or equal to given
626 <         * element, or null if there is no such element.
626 >         * element, or <tt>null</tt> if there is no such element.
627           * @throws ClassCastException if o cannot be compared with the
628           * elements currently in the set.
629           * @throws NullPointerException if o is <tt>null</tt>.
# Line 571 | Line 634 | public class ConcurrentSkipListSet<E>
634          }
635  
636          /**
637 <         * Returns an element strictly greater than the given element, or null
637 >         * Returns an element strictly greater than the given element, or <tt>null</tt>
638           * if there is no such element.
639           *
640           * @param o the value to match
641           * @return the least element greater than the given element, or
642 <         * null if there is no such element.
642 >         * <tt>null</tt> if there is no such element.
643           * @throws ClassCastException if o cannot be compared with the
644           * elements currently in the set.
645           * @throws NullPointerException if o is <tt>null</tt>.
# Line 734 | Line 797 | public class ConcurrentSkipListSet<E>
797                                                     fromElement, fence);
798          }
799      }
737
738
800   }    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines