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}. |
155 |
|
} |
156 |
|
|
157 |
|
/** |
158 |
< |
* Returns an iterator over the elements in this set. The elements |
158 |
< |
* 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 |
168 |
< |
* 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(); |
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 ? e==null : 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); |
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 ? e2==null : 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; |
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 ? e==null : 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; |
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 |
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); |
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); |
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); |
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); |