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.11 by jsr166, Mon May 16 08:13:36 2005 UTC vs.
Revision 1.16 by jsr166, Sun Jun 19 23:01:12 2005 UTC

# Line 6 | Line 6
6   */
7  
8   package java.util;
9 + import java.util.*; // for javadoc (till 6280605 is fixed)
10  
11   /**
12   * A {@link NavigableSet} implementation based on a {@link TreeMap}.
# Line 106 | Line 107 | public class TreeSet<E>
107      }
108  
109      /**
110 <     * Constructs a new, empty tree set, sorted according to the
111 <     * specified comparator.  All elements inserted into the set must
112 <     * be <i>mutually comparable</i> by the specified comparator:
113 <     * <tt>comparator.compare(e1, e2)</tt> must not throw a
114 <     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
115 <     * <tt>e2</tt> in the set.  If the user attempts to add an element
116 <     * to the set that violates this constraint, the
116 <     * <tt>add(Object)</tt> call will throw a
117 <     * <tt>ClassCastException</tt>.
110 >     * Constructs a new, empty tree set, sorted according to the specified
111 >     * comparator.  All elements inserted into the set must be <i>mutually
112 >     * comparable</i> by the specified comparator: <tt>comparator.compare(e1,
113 >     * e2)</tt> must not throw a <tt>ClassCastException</tt> for any elements
114 >     * <tt>e1</tt> and <tt>e2</tt> in the set.  If the user attempts to add
115 >     * an element to the set that violates this constraint, the
116 >     * <tt>add(Object)</tt> call will throw a <tt>ClassCastException</tt>.
117       *
118       * @param comparator the comparator that will be used to order this set.
119       *        If <tt>null</tt>, the {@linkplain Comparable natural
# Line 125 | Line 124 | public class TreeSet<E>
124      }
125  
126      /**
127 <     * Constructs a new tree set containing the elements in the
128 <     * specified collection, sorted according to the <i>natural
129 <     * ordering</i> of its elements.  All elements inserted into the
130 <     * set must implement the {@link Comparable} interface.
131 <     * Furthermore, all such elements must be <i>mutually
133 <     * comparable</i>: <tt>e1.compareTo(e2)</tt> must not throw a
127 >     * Constructs a new tree set containing the elements in the specified
128 >     * collection, sorted according to the <i>natural ordering</i> of its
129 >     * elements.  All elements inserted into the set must implement the
130 >     * {@link Comparable} interface.  Furthermore, all such elements must be
131 >     * <i>mutually comparable</i>: <tt>e1.compareTo(e2)</tt> must not throw a
132       * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
133       * <tt>e2</tt> in the set.
134       *
# Line 157 | Line 155 | public class TreeSet<E>
155      }
156  
157      /**
158 <     * Returns an iterator over the elements in this set.  The elements
161 <     * are returned in ascending order.
158 >     * Returns an iterator over the elements in this set in ascending order.
159       *
160 <     * @return an iterator over the elements in this set
160 >     * @return an iterator over the elements in this set in ascending order
161       */
162      public Iterator<E> iterator() {
163          return m.keySet().iterator();
164      }
165  
166      /**
167 <     * Returns an iterator over the elements in this set.  The elements
171 <     * are returned in descending order.
167 >     * Returns an iterator over the elements in this set in descending order.
168       *
169 <     * @return an iterator over the elements in this set
169 >     * @return an iterator over the elements in this set in descending order
170       */
171      public Iterator<E> descendingIterator() {
172          return m.descendingKeySet().iterator();
# Line 196 | 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 211 | 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 227 | 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 251 | 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 379 | Line 389 | public class TreeSet<E>
389  
390      /**
391       * @throws ClassCastException {@inheritDoc}
392 <     * @throws NullPointerException if the specified element is null and
393 <     *         this set uses natural ordering and is non-empty,
394 <     *         or its comparator does not permit null elements
392 >     * @throws NullPointerException if the specified element is null
393 >     *         and this set uses natural ordering, or its comparator
394 >     *         does not permit null elements
395       */
396      public E lower(E e) {
397          return m.lowerKey(e);
# Line 389 | Line 399 | public class TreeSet<E>
399  
400      /**
401       * @throws ClassCastException {@inheritDoc}
402 <     * @throws NullPointerException if the specified element is null and
403 <     *         this set uses natural ordering and is non-empty,
404 <     *         or its comparator does not permit null elements
402 >     * @throws NullPointerException if the specified element is null
403 >     *         and this set uses natural ordering, or its comparator
404 >     *         does not permit null elements
405       */
406      public E floor(E e) {
407          return m.floorKey(e);
# Line 399 | Line 409 | public class TreeSet<E>
409  
410      /**
411       * @throws ClassCastException {@inheritDoc}
412 <     * @throws NullPointerException if the specified element is null and
413 <     *         this set uses natural ordering and is non-empty,
414 <     *         or its comparator does not permit null elements
412 >     * @throws NullPointerException if the specified element is null
413 >     *         and this set uses natural ordering, or its comparator
414 >     *         does not permit null elements
415       */
416      public E ceiling(E e) {
417          return m.ceilingKey(e);
# Line 409 | Line 419 | public class TreeSet<E>
419  
420      /**
421       * @throws ClassCastException {@inheritDoc}
422 <     * @throws NullPointerException if the specified element is null and
423 <     *         this set uses natural ordering and is non-empty,
424 <     *         or its comparator does not permit null elements
422 >     * @throws NullPointerException if the specified element is null
423 >     *         and this set uses natural ordering, or its comparator
424 >     *         does not permit null elements
425       */
426      public E higher(E e) {
427          return m.higherKey(e);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines