278 |
|
} |
279 |
|
|
280 |
|
/** |
281 |
< |
* Returns a view of the portion of this set whose elements range from |
282 |
< |
* <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive. (If |
283 |
< |
* <tt>fromElement</tt> and <tt>toElement</tt> are equal, the returned |
284 |
< |
* sorted set is empty.) The returned sorted set is backed by this set, |
285 |
< |
* so changes in the returned sorted set are reflected in this set, and |
286 |
< |
* vice-versa. The returned sorted set supports all optional Set |
287 |
< |
* operations.<p> |
281 |
> |
* Returns a view of the portion of this set whose elements range |
282 |
> |
* from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, |
283 |
> |
* exclusive. (If <tt>fromElement</tt> and <tt>toElement</tt> are |
284 |
> |
* equal, the returned navigable set is empty.) The returned |
285 |
> |
* navigable set is backed by this set, so changes in the returned |
286 |
> |
* navigable set are reflected in this set, and vice-versa. The |
287 |
> |
* returned navigable set supports all optional Set operations.<p> |
288 |
|
* |
289 |
< |
* The sorted set returned by this method will throw an |
289 |
> |
* The navigable set returned by this method will throw an |
290 |
|
* <tt>IllegalArgumentException</tt> if the user attempts to insert an |
291 |
|
* element outside the specified range.<p> |
292 |
|
* |
293 |
< |
* Note: this method always returns a <i>half-open range</i> (which |
294 |
< |
* includes its low endpoint but not its high endpoint). If you need a |
295 |
< |
* <i>closed range</i> (which includes both endpoints), and the element |
296 |
< |
* type allows for calculation of the successor of a specified value, |
297 |
< |
* merely request the subrange from <tt>lowEndpoint</tt> to |
298 |
< |
* <tt>successor(highEndpoint)</tt>. For example, suppose that <tt>s</tt> |
299 |
< |
* is a sorted set of strings. The following idiom obtains a view |
300 |
< |
* containing all of the strings in <tt>s</tt> from <tt>low</tt> to |
301 |
< |
* <tt>high</tt>, inclusive: <pre> |
302 |
< |
* NavigableSet sub = s.subSet(low, high+"\0"); |
293 |
> |
* Note: this method always returns a <i>half-open range</i> |
294 |
> |
* (which includes its low endpoint but not its high endpoint). |
295 |
> |
* If you need a <i>closed range</i> (which includes both |
296 |
> |
* endpoints), and the element type allows for calculation of the |
297 |
> |
* successor of a specified value, merely request the subrange |
298 |
> |
* from <tt>lowEndpoint</tt> to <tt>successor(highEndpoint)</tt>. |
299 |
> |
* For example, suppose that <tt>s</tt> is a navigable set of |
300 |
> |
* strings. The following idiom obtains a view containing all of |
301 |
> |
* the strings in <tt>s</tt> from <tt>low</tt> to <tt>high</tt>, |
302 |
> |
* inclusive: <pre> NavigableSet sub = s.subSet(low, high+"\0"); |
303 |
|
* </pre> |
304 |
|
* |
305 |
|
* A similar technique can be used to generate an <i>open range</i> (which |
306 |
|
* contains neither endpoint). The following idiom obtains a view |
307 |
|
* containing all of the strings in <tt>s</tt> from <tt>low</tt> to |
308 |
|
* <tt>high</tt>, exclusive: <pre> |
309 |
< |
* NavigableSet sub = s.subSet(low+"\0", high); |
309 |
> |
* NavigableSet sub = s.navigableSubSet(low+"\0", high); |
310 |
|
* </pre> |
311 |
|
* |
312 |
|
* @param fromElement low endpoint (inclusive) of the subSet. |
325 |
|
* order, or its comparator does not tolerate <tt>null</tt> |
326 |
|
* elements. |
327 |
|
*/ |
328 |
< |
public NavigableSet<E> subSet(E fromElement, E toElement) { |
329 |
< |
return new TreeSet<E>(m.subMap(fromElement, toElement)); |
328 |
> |
public NavigableSet<E> navigableSubSet(E fromElement, E toElement) { |
329 |
> |
return new TreeSet<E>(m.navigableSubMap(fromElement, toElement)); |
330 |
|
} |
331 |
|
|
332 |
|
/** |
333 |
< |
* Returns a view of the portion of this set whose elements are strictly |
334 |
< |
* less than <tt>toElement</tt>. The returned sorted set is backed by |
335 |
< |
* this set, so changes in the returned sorted set are reflected in this |
336 |
< |
* set, and vice-versa. The returned sorted set supports all optional set |
337 |
< |
* operations.<p> |
338 |
< |
* |
339 |
< |
* The sorted set returned by this method will throw an |
340 |
< |
* <tt>IllegalArgumentException</tt> if the user attempts to insert an |
341 |
< |
* element greater than or equal to <tt>toElement</tt>.<p> |
342 |
< |
* |
343 |
< |
* Note: this method always returns a view that does not contain its |
344 |
< |
* (high) endpoint. If you need a view that does contain this endpoint, |
345 |
< |
* and the element type allows for calculation of the successor of a |
346 |
< |
* specified value, merely request a headSet bounded by |
347 |
< |
* <tt>successor(highEndpoint)</tt>. For example, suppose that <tt>s</tt> |
348 |
< |
* is a sorted set of strings. The following idiom obtains a view |
349 |
< |
* containing all of the strings in <tt>s</tt> that are less than or equal |
350 |
< |
* to <tt>high</tt>: <pre> NavigableSet head = s.headSet(high+"\0");</pre> |
333 |
> |
* Returns a view of the portion of this set whose elements are |
334 |
> |
* strictly less than <tt>toElement</tt>. The returned navigable |
335 |
> |
* set is backed by this set, so changes in the returned navigable |
336 |
> |
* set are reflected in this set, and vice-versa. The returned |
337 |
> |
* navigable set supports all optional set operations.<p> |
338 |
> |
* |
339 |
> |
* The navigable set returned by this method will throw an |
340 |
> |
* <tt>IllegalArgumentException</tt> if the user attempts to |
341 |
> |
* insert an element greater than or equal to |
342 |
> |
* <tt>toElement</tt>.<p> |
343 |
> |
* |
344 |
> |
* Note: this method always returns a view that does not contain |
345 |
> |
* its (high) endpoint. If you need a view that does contain this |
346 |
> |
* endpoint, and the element type allows for calculation of the |
347 |
> |
* successor of a specified value, merely request a headSet |
348 |
> |
* bounded by <tt>successor(highEndpoint)</tt>. For example, |
349 |
> |
* suppose that <tt>s</tt> is a navigable set of strings. The |
350 |
> |
* following idiom obtains a view containing all of the strings in |
351 |
> |
* <tt>s</tt> that are less than or equal to <tt>high</tt>: |
352 |
> |
* <pre> NavigableSet head = s.navigableHeadSet(high+"\0");</pre> |
353 |
|
* |
354 |
|
* @param toElement high endpoint (exclusive) of the headSet. |
355 |
|
* @return a view of the portion of this set whose elements are strictly |
364 |
|
* this set uses natural ordering, or its comparator does |
365 |
|
* not tolerate <tt>null</tt> elements. |
366 |
|
*/ |
367 |
< |
public NavigableSet<E> headSet(E toElement) { |
368 |
< |
return new TreeSet<E>(m.headMap(toElement)); |
367 |
> |
public NavigableSet<E> navigableHeadSet(E toElement) { |
368 |
> |
return new TreeSet<E>(m.navigableHeadMap(toElement)); |
369 |
|
} |
370 |
|
|
371 |
|
/** |
372 |
|
* Returns a view of the portion of this set whose elements are |
373 |
< |
* greater than or equal to <tt>fromElement</tt>. The returned sorted set |
374 |
< |
* is backed by this set, so changes in the returned sorted set are |
375 |
< |
* reflected in this set, and vice-versa. The returned sorted set |
376 |
< |
* supports all optional set operations.<p> |
373 |
> |
* greater than or equal to <tt>fromElement</tt>. The returned |
374 |
> |
* navigable set is backed by this set, so changes in the returned |
375 |
> |
* navigable set are reflected in this set, and vice-versa. The |
376 |
> |
* returned navigable set supports all optional set operations.<p> |
377 |
|
* |
378 |
< |
* The sorted set returned by this method will throw an |
378 |
> |
* The navigable set returned by this method will throw an |
379 |
|
* <tt>IllegalArgumentException</tt> if the user attempts to insert an |
380 |
|
* element less than <tt>fromElement</tt>. |
381 |
|
* |
382 |
|
* Note: this method always returns a view that contains its (low) |
383 |
< |
* endpoint. If you need a view that does not contain this endpoint, and |
384 |
< |
* the element type allows for calculation of the successor of a specified |
385 |
< |
* value, merely request a tailSet bounded by |
386 |
< |
* <tt>successor(lowEndpoint)</tt>. For example, suppose that <tt>s</tt> |
387 |
< |
* is a sorted set of strings. The following idiom obtains a view |
388 |
< |
* containing all of the strings in <tt>s</tt> that are strictly greater |
389 |
< |
* than <tt>low</tt>: <pre> |
390 |
< |
* NavigableSet tail = s.tailSet(low+"\0"); |
383 |
> |
* endpoint. If you need a view that does not contain this |
384 |
> |
* endpoint, and the element type allows for calculation of the |
385 |
> |
* successor of a specified value, merely request a tailSet |
386 |
> |
* bounded by <tt>successor(lowEndpoint)</tt>. For example, |
387 |
> |
* suppose that <tt>s</tt> is a navigable set of strings. The |
388 |
> |
* following idiom obtains a view containing all of the strings in |
389 |
> |
* <tt>s</tt> that are strictly greater than <tt>low</tt>: |
390 |
> |
* <pre> NavigableSet tail = s.navigableTailSet(low+"\0"); |
391 |
|
* </pre> |
392 |
|
* |
393 |
|
* @param fromElement low endpoint (inclusive) of the tailSet. |
403 |
|
* and this set uses natural ordering, or its comparator does |
404 |
|
* not tolerate <tt>null</tt> elements. |
405 |
|
*/ |
406 |
< |
public NavigableSet<E> tailSet(E fromElement) { |
407 |
< |
return new TreeSet<E>(m.tailMap(fromElement)); |
406 |
> |
public NavigableSet<E> navigableTailSet(E fromElement) { |
407 |
> |
return new TreeSet<E>(m.navigableTailMap(fromElement)); |
408 |
> |
} |
409 |
> |
|
410 |
> |
|
411 |
> |
/** |
412 |
> |
* Equivalent to <tt>navigableSubSet</tt> but with a return |
413 |
> |
* type conforming to the <tt>SortedSet</tt> interface. |
414 |
> |
* @param fromElement low endpoint (inclusive) of the subSet. |
415 |
> |
* @param toElement high endpoint (exclusive) of the subSet. |
416 |
> |
* @return a view of the portion of this set whose elements range from |
417 |
> |
* <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, |
418 |
> |
* exclusive. |
419 |
> |
* @throws ClassCastException if <tt>fromElement</tt> and |
420 |
> |
* <tt>toElement</tt> cannot be compared to one another using |
421 |
> |
* this set's comparator (or, if the set has no comparator, |
422 |
> |
* using natural ordering). |
423 |
> |
* @throws IllegalArgumentException if <tt>fromElement</tt> is greater than |
424 |
> |
* <tt>toElement</tt>. |
425 |
> |
* @throws NullPointerException if <tt>fromElement</tt> or |
426 |
> |
* <tt>toElement</tt> is <tt>null</tt> and this set uses natural |
427 |
> |
* order, or its comparator does not tolerate <tt>null</tt> |
428 |
> |
* elements. |
429 |
> |
*/ |
430 |
> |
public SortedSet<E> subSet(E fromElement, E toElement) { |
431 |
> |
return new TreeSet<E>(m.navigableSubMap(fromElement, toElement)); |
432 |
> |
} |
433 |
> |
|
434 |
> |
/** |
435 |
> |
* Equivalent to <tt>navigableHeadSet</tt> but with a return |
436 |
> |
* type conforming to the <tt>SortedSet</tt> interface. |
437 |
> |
* |
438 |
> |
* @param toElement high endpoint (exclusive) of the headSet. |
439 |
> |
* @return a view of the portion of this set whose elements are strictly |
440 |
> |
* less than toElement. |
441 |
> |
* @throws ClassCastException if <tt>toElement</tt> is not compatible |
442 |
> |
* with this set's comparator (or, if the set has no comparator, |
443 |
> |
* if <tt>toElement</tt> does not implement <tt>Comparable</tt>). |
444 |
> |
* @throws IllegalArgumentException if this set is itself a subSet, |
445 |
> |
* headSet, or tailSet, and <tt>toElement</tt> is not within the |
446 |
> |
* specified range of the subSet, headSet, or tailSet. |
447 |
> |
* @throws NullPointerException if <tt>toElement</tt> is <tt>null</tt> and |
448 |
> |
* this set uses natural ordering, or its comparator does |
449 |
> |
* not tolerate <tt>null</tt> elements. |
450 |
> |
*/ |
451 |
> |
public SortedSet<E> headSet(E toElement) { |
452 |
> |
return new TreeSet<E>(m.navigableHeadMap(toElement)); |
453 |
> |
} |
454 |
> |
|
455 |
> |
/** |
456 |
> |
* Equivalent to <tt>navigableTailSet</tt> but with a return |
457 |
> |
* type conforming to the <tt>SortedSet</tt> interface. |
458 |
> |
* @param fromElement low endpoint (inclusive) of the tailSet. |
459 |
> |
* @return a view of the portion of this set whose elements are |
460 |
> |
* greater than or equal to <tt>fromElement</tt>. |
461 |
> |
* @throws ClassCastException if <tt>fromElement</tt> is not compatible |
462 |
> |
* with this set's comparator (or, if the set has no comparator, |
463 |
> |
* if <tt>fromElement</tt> does not implement <tt>Comparable</tt>). |
464 |
> |
* @throws IllegalArgumentException if this set is itself a subSet, |
465 |
> |
* headSet, or tailSet, and <tt>fromElement</tt> is not within the |
466 |
> |
* specified range of the subSet, headSet, or tailSet. |
467 |
> |
* @throws NullPointerException if <tt>fromElement</tt> is <tt>null</tt> |
468 |
> |
* and this set uses natural ordering, or its comparator does |
469 |
> |
* not tolerate <tt>null</tt> elements. |
470 |
> |
*/ |
471 |
> |
public SortedSet<E> tailSet(E fromElement) { |
472 |
> |
return new TreeSet<E>(m.navigableTailMap(fromElement)); |
473 |
|
} |
474 |
|
|
475 |
|
/** |