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

Comparing jsr166/src/main/java/util/TreeSet.java (file contents):
Revision 1.13 by jsr166, Tue May 17 07:29:01 2005 UTC vs.
Revision 1.20 by jsr166, Tue Feb 7 20:54:24 2006 UTC

# Line 1 | Line 1
1   /*
2   * %W% %E%
3   *
4 < * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
4 > * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5   * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6   */
7  
# Line 28 | Line 28 | package java.util;
28   * <i>is</i> well-defined even if its ordering is inconsistent with equals; it
29   * just fails to obey the general contract of the <tt>Set</tt> interface.
30   *
31 < * <p><b>Note that this implementation is not synchronized.</b> If multiple
32 < * threads access a set concurrently, and at least one of the threads modifies
33 < * the set, it <i>must</i> be synchronized externally.  This is typically
34 < * accomplished by synchronizing on some object that naturally encapsulates
35 < * the set.  If no such object exists, the set should be "wrapped" using the
36 < * <tt>Collections.synchronizedSet</tt> method.  This is best done at creation
37 < * time, to prevent accidental unsynchronized access to the set: <pre>
38 < *     SortedSet s = Collections.synchronizedSortedSet(new TreeSet(...));
39 < * </pre>
31 > * <p><strong>Note that this implementation is not synchronized.</strong>
32 > * If multiple threads access a tree set concurrently, and at least one
33 > * of the threads modifies the set, it <i>must</i> be synchronized
34 > * externally.  This is typically accomplished by synchronizing on some
35 > * object that naturally encapsulates the set.
36 > * If no such object exists, the set should be "wrapped" using the
37 > * {@link Collections#synchronizedSortedSet Collections.synchronizedSortedSet}
38 > * method.  This is best done at creation time, to prevent accidental
39 > * unsynchronized access to the set: <pre>
40 > *   SortedSet s = Collections.synchronizedSortedSet(new TreeSet(...));</pre>
41   *
42   * <p>The iterators returned by this class's <tt>iterator</tt> method are
43   * <i>fail-fast</i>: if the set is modified at any time after the iterator is
# Line 67 | Line 68 | package java.util;
68   * @see     HashSet
69   * @see     Comparable
70   * @see     Comparator
70 * @see     Collections#synchronizedSortedSet(SortedSet)
71   * @see     TreeMap
72   * @since   1.2
73   */
# Line 166 | Line 166 | public class TreeSet<E>
166       * Returns an iterator over the elements in this set in descending order.
167       *
168       * @return an iterator over the elements in this set in descending order
169 +     * @since 1.6
170       */
171      public Iterator<E> descendingIterator() {
172          return m.descendingKeySet().iterator();
# Line 191 | Line 192 | public class TreeSet<E>
192  
193      /**
194       * Returns <tt>true</tt> if this set contains the specified element.
195 +     * More formally, returns <tt>true</tt> if and only if this set
196 +     * contains an element <tt>e</tt> such that
197 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
198       *
199 <     * @param o the object to be checked for containment in this set
199 >     * @param o object to be checked for containment in this set
200       * @return <tt>true</tt> if this set contains the specified element
201       * @throws ClassCastException if the specified object cannot be compared
202       *         with the elements currently in the set
203 <     * @throws NullPointerException if the specified element is null and
204 <     *         this set uses natural ordering and is non-empty, or its
205 <     *         comparator does not permit null elements
203 >     * @throws NullPointerException if the specified element is null
204 >     *         and this set uses natural ordering, or its comparator
205 >     *         does not permit null elements
206       */
207      public boolean contains(Object o) {
208          return m.containsKey(o);
# Line 206 | Line 210 | public class TreeSet<E>
210  
211      /**
212       * Adds the specified element to this set if it is not already present.
213 +     * More formally, adds the specified element <tt>e</tt> to this set if
214 +     * the set contains no element <tt>e2</tt> such that
215 +     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
216 +     * If this set already contains the element, the call leaves the set
217 +     * unchanged and returns <tt>false</tt>.
218       *
219       * @param e element to be added to this set
220 <     * @return <tt>true</tt> if the set did not already contain the specified
220 >     * @return <tt>true</tt> if this set did not already contain the specified
221       *         element
222       * @throws ClassCastException if the specified object cannot be compared
223 <     *         with the elements currently in the set
224 <     * @throws NullPointerException if the specified element is null and
225 <     *         this set uses natural ordering and is non-empty, or its
226 <     *         comparator does not permit null elements
223 >     *         with the elements currently in this set
224 >     * @throws NullPointerException if the specified element is null
225 >     *         and this set uses natural ordering, or its comparator
226 >     *         does not permit null elements
227       */
228      public boolean add(E e) {
229          return m.put(e, PRESENT)==null;
# Line 222 | Line 231 | public class TreeSet<E>
231  
232      /**
233       * Removes the specified element from this set if it is present.
234 +     * More formally, removes an element <tt>e</tt> such that
235 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>,
236 +     * if this set contains such an element.  Returns <tt>true</tt> if
237 +     * this set contained the element (or equivalently, if this set
238 +     * changed as a result of the call).  (This set will not contain the
239 +     * element once the call returns.)
240       *
241       * @param o object to be removed from this set, if present
242 <     * @return <tt>true</tt> if the set contained the specified element
242 >     * @return <tt>true</tt> if this set contained the specified element
243       * @throws ClassCastException if the specified object cannot be compared
244 <     *         with the elements currently in the set
245 <     * @throws NullPointerException if the specified element is null and
246 <     *         this set uses natural ordering and is non-empty, or its
247 <     *         comparator does not permit null elements
244 >     *         with the elements currently in this set
245 >     * @throws NullPointerException if the specified element is null
246 >     *         and this set uses natural ordering, or its comparator
247 >     *         does not permit null elements
248       */
249      public boolean remove(Object o) {
250          return m.remove(o)==PRESENT;
# Line 246 | Line 261 | public class TreeSet<E>
261      /**
262       * Adds all of the elements in the specified collection to this set.
263       *
264 <     * @param c elements to be added
264 >     * @param c collection containing elements to be added to this set
265       * @return <tt>true</tt> if this set changed as a result of the call
266       * @throws ClassCastException if the elements provided cannot be compared
267       *         with the elements currently in the set
# Line 277 | Line 292 | public class TreeSet<E>
292       *         <tt>toElement</tt> is null and this set uses natural ordering,
293       *         or its comparator does not permit null elements
294       * @throws IllegalArgumentException {@inheritDoc}
295 +     * @since 1.6
296       */
297      public NavigableSet<E> navigableSubSet(E fromElement, E toElement) {
298          return new TreeSet<E>(m.navigableSubMap(fromElement, toElement));
# Line 288 | Line 304 | public class TreeSet<E>
304       *         this set uses natural ordering, or its comparator does
305       *         not permit null elements
306       * @throws IllegalArgumentException {@inheritDoc}
307 +     * @since 1.6
308       */
309      public NavigableSet<E> navigableHeadSet(E toElement) {
310          return new TreeSet<E>(m.navigableHeadMap(toElement));
# Line 299 | Line 316 | public class TreeSet<E>
316       *         this set uses natural ordering, or its comparator does
317       *         not permit null elements
318       * @throws IllegalArgumentException {@inheritDoc}
319 +     * @since 1.6
320       */
321      public NavigableSet<E> navigableTailSet(E fromElement) {
322          return new TreeSet<E>(m.navigableTailMap(fromElement));
# Line 374 | Line 392 | public class TreeSet<E>
392  
393      /**
394       * @throws ClassCastException {@inheritDoc}
395 <     * @throws NullPointerException if the specified element is null and
396 <     *         this set uses natural ordering and is non-empty,
397 <     *         or its comparator does not permit null elements
395 >     * @throws NullPointerException if the specified element is null
396 >     *         and this set uses natural ordering, or its comparator
397 >     *         does not permit null elements
398 >     * @since 1.6
399       */
400      public E lower(E e) {
401          return m.lowerKey(e);
# Line 384 | Line 403 | public class TreeSet<E>
403  
404      /**
405       * @throws ClassCastException {@inheritDoc}
406 <     * @throws NullPointerException if the specified element is null and
407 <     *         this set uses natural ordering and is non-empty,
408 <     *         or its comparator does not permit null elements
406 >     * @throws NullPointerException if the specified element is null
407 >     *         and this set uses natural ordering, or its comparator
408 >     *         does not permit null elements
409 >     * @since 1.6
410       */
411      public E floor(E e) {
412          return m.floorKey(e);
# Line 394 | Line 414 | public class TreeSet<E>
414  
415      /**
416       * @throws ClassCastException {@inheritDoc}
417 <     * @throws NullPointerException if the specified element is null and
418 <     *         this set uses natural ordering and is non-empty,
419 <     *         or its comparator does not permit null elements
417 >     * @throws NullPointerException if the specified element is null
418 >     *         and this set uses natural ordering, or its comparator
419 >     *         does not permit null elements
420 >     * @since 1.6
421       */
422      public E ceiling(E e) {
423          return m.ceilingKey(e);
# Line 404 | Line 425 | public class TreeSet<E>
425  
426      /**
427       * @throws ClassCastException {@inheritDoc}
428 <     * @throws NullPointerException if the specified element is null and
429 <     *         this set uses natural ordering and is non-empty,
430 <     *         or its comparator does not permit null elements
428 >     * @throws NullPointerException if the specified element is null
429 >     *         and this set uses natural ordering, or its comparator
430 >     *         does not permit null elements
431 >     * @since 1.6
432       */
433      public E higher(E e) {
434          return m.higherKey(e);
435      }
436  
437 +    /**
438 +     * @since 1.6
439 +     */
440      public E pollFirst() {
441          Map.Entry<E,?> e = m.pollFirstEntry();
442          return (e == null)? null : e.getKey();
443      }
444  
445 +    /**
446 +     * @since 1.6
447 +     */
448      public E pollLast() {
449          Map.Entry<E,?> e = m.pollLastEntry();
450          return (e == null)? null : e.getKey();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines