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

Comparing jsr166/src/main/java/util/concurrent/ConcurrentSkipListSet.java (file contents):
Revision 1.2 by dl, Tue Mar 8 12:27:11 2005 UTC vs.
Revision 1.3 by dl, Tue Mar 22 01:30:18 2005 UTC

# Line 11 | Line 11 | import java.util.*;
11   * A scalable concurrent {@link NavigableSet} implementation based on
12   * a {@link ConcurrentSkipListMap}.  This class maintains a set in
13   * ascending order, sorted according to the <i>natural order</i> for
14 < * the element's class (see {@link Comparable}), or by the comparator
14 > * the elements' class (see {@link Comparable}), or by the comparator
15   * provided at creation time, depending on which constructor is
16   * used.<p>
17   *
# Line 30 | Line 30 | import java.util.*;
30   * asynchronous nature of these sets, determining the current number
31   * of elements requires a traversal of the elements. Additionally, the
32   * bulk operations <tt>addAll</tt>, <tt>removeAll</tt>,
33 < * <<tt>retainAll</tt>, and tt>containsAll</tt> are <em>not</em>
33 > * <tt>retainAll</tt>, and <tt>containsAll</tt> are <em>not</em>
34   * guaranteed to be performed atomically. For example, an iterator
35   * operating concurrently with an <tt>addAll</tt> operation might view
36   * only some of the added elements.
# Line 397 | Line 397 | public class ConcurrentSkipListSet<E>
397          return m.lastKey();
398      }
399  
400
401
400      /**
401       * Returns a view of the portion of this set whose elements range from
402       * <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive.  (If
403       * <tt>fromElement</tt> and <tt>toElement</tt> are equal, the returned
404 <     * sorted set is empty.)  The returned sorted set is backed by this set,
405 <     * so changes in the returned sorted set are reflected in this set, and
404 >     * navigable set is empty.)  The returned navigable set is backed by this set,
405 >     * so changes in the returned navigable set are reflected in this set, and
406       * vice-versa.
407       * @param fromElement low endpoint (inclusive) of the subSet.
408       * @param toElement high endpoint (exclusive) of the subSet.
# Line 420 | Line 418 | public class ConcurrentSkipListSet<E>
418       * @throws NullPointerException if <tt>fromElement</tt> or
419       *         <tt>toElement</tt> is <tt>null</tt>.
420       */
421 <    public NavigableSet<E> subSet(E fromElement, E toElement) {
421 >    public NavigableSet<E> navigableSubSet(E fromElement, E toElement) {
422          return new ConcurrentSkipListSubSet<E>(m, fromElement, toElement);
423      }
424  
425      /**
426       * Returns a view of the portion of this set whose elements are strictly
427 <     * less than <tt>toElement</tt>.  The returned sorted set is backed by
428 <     * this set, so changes in the returned sorted set are reflected in this
427 >     * less than <tt>toElement</tt>.  The returned navigable set is backed by
428 >     * this set, so changes in the returned navigable set are reflected in this
429       * set, and vice-versa.  
430       * @param toElement high endpoint (exclusive) of the headSet.
431       * @return a view of the portion of this set whose elements are strictly
# Line 437 | Line 435 | public class ConcurrentSkipListSet<E>
435       *         if <tt>toElement</tt> does not implement <tt>Comparable</tt>).
436       * @throws NullPointerException if <tt>toElement</tt> is <tt>null</tt>.
437       */
438 <    public NavigableSet<E> headSet(E toElement) {
438 >    public NavigableSet<E> navigableHeadSet(E toElement) {
439          return new ConcurrentSkipListSubSet<E>(m, null, toElement);
440      }
441  
# Line 445 | Line 443 | public class ConcurrentSkipListSet<E>
443      /**
444       * Returns a view of the portion of this set whose elements are
445       * greater than or equal to <tt>fromElement</tt>.  The returned
446 <     * sorted set is backed by this set, so changes in the returned
447 <     * sorted set are reflected in this set, and vice-versa.
446 >     * navigable set is backed by this set, so changes in the returned
447 >     * navigable set are reflected in this set, and vice-versa.
448       * @param fromElement low endpoint (inclusive) of the tailSet.
449       * @return a view of the portion of this set whose elements are
450       * greater than or equal to <tt>fromElement</tt>.
# Line 456 | Line 454 | public class ConcurrentSkipListSet<E>
454       * <tt>Comparable</tt>).
455       * @throws NullPointerException if <tt>fromElement</tt> is <tt>null</tt>.
456       */
457 <    public NavigableSet<E> tailSet(E fromElement) {
457 >    public NavigableSet<E> navigableTailSet(E fromElement) {
458 >        return new ConcurrentSkipListSubSet<E>(m, fromElement, null);
459 >    }
460 >
461 >
462 >    /**
463 >     * Equivalent to <tt>navigableSubSet</tt> but with a return
464 >     * type conforming to the <tt>SortedSet</tt> interface.
465 >     * @param fromElement low endpoint (inclusive) of the subSet.
466 >     * @param toElement high endpoint (exclusive) of the subSet.
467 >     * @return a view of the portion of this set whose elements range from
468 >     *         <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
469 >     *         exclusive.
470 >     * @throws ClassCastException if <tt>fromElement</tt> and
471 >     *         <tt>toElement</tt> cannot be compared to one another using
472 >     *         this set's comparator (or, if the set has no comparator,
473 >     *         using natural ordering).
474 >     * @throws IllegalArgumentException if <tt>fromElement</tt> is
475 >     * greater than <tt>toElement</tt>.
476 >     * @throws NullPointerException if <tt>fromElement</tt> or
477 >     *         <tt>toElement</tt> is <tt>null</tt>.
478 >     */
479 >    public SortedSet<E> subSet(E fromElement, E toElement) {
480 >        return new ConcurrentSkipListSubSet<E>(m, fromElement, toElement);
481 >    }
482 >
483 >    /**
484 >     * Equivalent to <tt>navigableHeadSet</tt> but with a return
485 >     * type conforming to the <tt>SortedSet</tt> interface.
486 >     * @param toElement high endpoint (exclusive) of the headSet.
487 >     * @return a view of the portion of this set whose elements are strictly
488 >     *         less than toElement.
489 >     * @throws ClassCastException if <tt>toElement</tt> is not compatible
490 >     *         with this set's comparator (or, if the set has no comparator,
491 >     *         if <tt>toElement</tt> does not implement <tt>Comparable</tt>).
492 >     * @throws NullPointerException if <tt>toElement</tt> is <tt>null</tt>.
493 >     */
494 >    public SortedSet<E> headSet(E toElement) {
495 >        return new ConcurrentSkipListSubSet<E>(m, null, toElement);
496 >    }
497 >
498 >
499 >    /**
500 >     * Equivalent to <tt>navigableTailSet</tt> but with a return
501 >     * type conforming to the <tt>SortedSet</tt> interface.
502 >     * @param fromElement low endpoint (inclusive) of the tailSet.
503 >     * @return a view of the portion of this set whose elements are
504 >     * greater than or equal to <tt>fromElement</tt>.
505 >     * @throws ClassCastException if <tt>fromElement</tt> is not
506 >     * compatible with this set's comparator (or, if the set has no
507 >     * comparator, if <tt>fromElement</tt> does not implement
508 >     * <tt>Comparable</tt>).
509 >     * @throws NullPointerException if <tt>fromElement</tt> is <tt>null</tt>.
510 >     */
511 >    public SortedSet<E> tailSet(E fromElement) {
512          return new ConcurrentSkipListSubSet<E>(m, fromElement, null);
513      }
514  
# Line 495 | Line 547 | public class ConcurrentSkipListSet<E>
547  
548          // subsubset construction
549  
550 <        public NavigableSet<E> subSet(E fromElement, E toElement) {
550 >        public NavigableSet<E> navigableSubSet(E fromElement, E toElement) {
551              if (!s.inOpenRange(fromElement) || !s.inOpenRange(toElement))
552                  throw new IllegalArgumentException("element out of range");
553              return new ConcurrentSkipListSubSet<E>(s.getMap(),
554                                                     fromElement, toElement);
555          }
556  
557 <        public NavigableSet<E> headSet(E toElement) {
557 >        public NavigableSet<E> navigableHeadSet(E toElement) {
558              E least = s.getLeast();
559              if (!s.inOpenRange(toElement))
560                  throw new IllegalArgumentException("element out of range");
# Line 510 | Line 562 | public class ConcurrentSkipListSet<E>
562                                                     least, toElement);
563          }
564          
565 <        public NavigableSet<E> tailSet(E fromElement) {
565 >        public NavigableSet<E> navigableTailSet(E fromElement) {
566              E fence = s.getFence();
567              if (!s.inOpenRange(fromElement))
568                  throw new IllegalArgumentException("element out of range");
# Line 518 | Line 570 | public class ConcurrentSkipListSet<E>
570                                                     fromElement, fence);
571          }
572  
573 +        public SortedSet<E> subSet(E fromElement, E toElement) {
574 +            return  navigableSubSet(fromElement, toElement);
575 +        }
576 +
577 +        public SortedSet<E> headSet(E toElement) {
578 +            return navigableHeadSet(toElement);
579 +        }
580 +        
581 +        public SortedSet<E> tailSet(E fromElement) {
582 +            return navigableTailSet(fromElement);
583 +        }
584 +
585          // relays to submap methods
586  
587          public int size()                 { return s.size(); }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines