1 |
|
/* |
2 |
|
* %W% %E% |
3 |
|
* |
4 |
< |
* Copyright 2004 Sun Microsystems, Inc. All rights reserved. |
4 |
> |
* Copyright 2005 Sun Microsystems, Inc. All rights reserved. |
5 |
|
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
6 |
|
*/ |
7 |
|
|
8 |
< |
package java.util; |
8 |
> |
package java.util; |
9 |
|
|
10 |
|
/** |
11 |
|
* This class implements the <tt>Set</tt> interface, backed by a |
210 |
|
/** |
211 |
|
* Adds the specified element to this set if it is not already present. |
212 |
|
* |
213 |
< |
* @param o element to be added to this set. |
213 |
> |
* @param e element to be added to this set. |
214 |
|
* @return <tt>true</tt> if the set did not already contain the specified |
215 |
|
* element. |
216 |
|
* |
217 |
|
* @throws ClassCastException if the specified object cannot be compared |
218 |
|
* with the elements currently in the set. |
219 |
< |
* @throws NullPointerException if o is <tt>null</tt> and this map |
219 |
> |
* @throws NullPointerException if e is <tt>null</tt> and this map |
220 |
|
* uses natural ordering and is non-empty, or its comparator does |
221 |
|
* not tolerate <tt>null</tt> keys. |
222 |
|
*/ |
223 |
< |
public boolean add(E o) { |
224 |
< |
return m.put(o, PRESENT)==null; |
223 |
> |
public boolean add(E e) { |
224 |
> |
return m.put(e, PRESENT)==null; |
225 |
|
} |
226 |
|
|
227 |
|
/** |
255 |
|
* |
256 |
|
* @throws ClassCastException if the elements provided cannot be compared |
257 |
|
* with the elements currently in the set. |
258 |
< |
* @throws NullPointerException of the specified collection is |
258 |
> |
* @throws NullPointerException if the specified collection is |
259 |
|
* <tt>null</tt> or if any element is <tt>null</tt> and this map |
260 |
|
* uses natural ordering, or its comparator does not tolerate |
261 |
|
* <tt>null</tt> keys. |
265 |
|
if (m.size()==0 && c.size() > 0 && |
266 |
|
c instanceof SortedSet && |
267 |
|
m instanceof TreeMap) { |
268 |
< |
SortedSet<Map.Entry<E, Object>> set = (SortedSet<Map.Entry<E, Object>>) (SortedSet) c; |
268 |
> |
SortedSet<? extends E> set = (SortedSet<? extends E>) c; |
269 |
|
TreeMap<E,Object> map = (TreeMap<E, Object>) m; |
270 |
< |
Comparator<? super E> cc = (Comparator<E>) set.comparator(); |
270 |
> |
Comparator<? super E> cc = (Comparator<? super E>) set.comparator(); |
271 |
|
Comparator<? super E> mc = map.comparator(); |
272 |
|
if (cc==mc || (cc != null && cc.equals(mc))) { |
273 |
|
map.addAllForTreeSet(set, PRESENT); |
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"); |
302 |
> |
* inclusive: |
303 |
> |
* <pre> NavigableSet sub = s.navigableSubSet(low, high+"\0"); |
304 |
|
* </pre> |
305 |
|
* |
306 |
|
* A similar technique can be used to generate an <i>open range</i> (which |
310 |
|
* NavigableSet sub = s.navigableSubSet(low+"\0", high); |
311 |
|
* </pre> |
312 |
|
* |
313 |
< |
* @param fromElement low endpoint (inclusive) of the subSet. |
314 |
< |
* @param toElement high endpoint (exclusive) of the subSet. |
313 |
> |
* @param fromElement low endpoint (inclusive) of the range. |
314 |
> |
* @param toElement high endpoint (exclusive) of the range. |
315 |
|
* @return a view of the portion of this set whose elements range from |
316 |
|
* <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, |
317 |
|
* exclusive. |
349 |
|
* bounded by <tt>successor(highEndpoint)</tt>. For example, |
350 |
|
* suppose that <tt>s</tt> is a navigable set of strings. The |
351 |
|
* following idiom obtains a view containing all of the strings in |
352 |
< |
* <tt>s</tt> that are less than or equal to <tt>high</tt>: |
352 |
> |
* <tt>s</tt> that are less than or equal to <tt>high</tt>: |
353 |
|
* <pre> NavigableSet head = s.navigableHeadSet(high+"\0");</pre> |
354 |
|
* |
355 |
|
* @param toElement high endpoint (exclusive) of the headSet. |
356 |
|
* @return a view of the portion of this set whose elements are strictly |
357 |
< |
* less than toElement. |
357 |
> |
* less than <tt>toElement</tt>. |
358 |
|
* @throws ClassCastException if <tt>toElement</tt> is not compatible |
359 |
|
* with this set's comparator (or, if the set has no comparator, |
360 |
|
* if <tt>toElement</tt> does not implement <tt>Comparable</tt>). |
361 |
< |
* @throws IllegalArgumentException if this set is itself a subSet, |
362 |
< |
* headSet, or tailSet, and <tt>toElement</tt> is not within the |
363 |
< |
* specified range of the subSet, headSet, or tailSet. |
361 |
> |
* @throws IllegalArgumentException if this set is itself a subset, |
362 |
> |
* and <tt>toElement</tt> is not within the |
363 |
> |
* specified range of the subset. |
364 |
|
* @throws NullPointerException if <tt>toElement</tt> is <tt>null</tt> and |
365 |
|
* this set uses natural ordering, or its comparator does |
366 |
|
* not tolerate <tt>null</tt> elements. |
397 |
|
* @throws ClassCastException if <tt>fromElement</tt> is not compatible |
398 |
|
* with this set's comparator (or, if the set has no comparator, |
399 |
|
* if <tt>fromElement</tt> does not implement <tt>Comparable</tt>). |
400 |
< |
* @throws IllegalArgumentException if this set is itself a subSet, |
401 |
< |
* headSet, or tailSet, and <tt>fromElement</tt> is not within the |
402 |
< |
* specified range of the subSet, headSet, or tailSet. |
400 |
> |
* @throws IllegalArgumentException if this set is itself a subset, |
401 |
> |
* and <tt>fromElement</tt> is not within the |
402 |
> |
* specified range of the subset. |
403 |
|
* @throws NullPointerException if <tt>fromElement</tt> is <tt>null</tt> |
404 |
|
* and this set uses natural ordering, or its comparator does |
405 |
|
* not tolerate <tt>null</tt> elements. |
412 |
|
/** |
413 |
|
* Equivalent to <tt>navigableSubSet</tt> but with a return |
414 |
|
* type conforming to the <tt>SortedSet</tt> interface. |
415 |
< |
* @param fromElement low endpoint (inclusive) of the subSet. |
416 |
< |
* @param toElement high endpoint (exclusive) of the subSet. |
415 |
> |
* @param fromElement low endpoint (inclusive) of the range. |
416 |
> |
* @param toElement high endpoint (exclusive) of the range. |
417 |
|
* @return a view of the portion of this set whose elements range from |
418 |
|
* <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, |
419 |
|
* exclusive. |
438 |
|
* |
439 |
|
* @param toElement high endpoint (exclusive) of the headSet. |
440 |
|
* @return a view of the portion of this set whose elements are strictly |
441 |
< |
* less than toElement. |
441 |
> |
* less than <tt>toElement</tt>. |
442 |
|
* @throws ClassCastException if <tt>toElement</tt> is not compatible |
443 |
|
* with this set's comparator (or, if the set has no comparator, |
444 |
|
* if <tt>toElement</tt> does not implement <tt>Comparable</tt>). |
445 |
< |
* @throws IllegalArgumentException if this set is itself a subSet, |
446 |
< |
* headSet, or tailSet, and <tt>toElement</tt> is not within the |
447 |
< |
* specified range of the subSet, headSet, or tailSet. |
445 |
> |
* @throws IllegalArgumentException if this set is itself a subset, |
446 |
> |
* and <tt>toElement</tt> is not within the |
447 |
> |
* specified range of the subset. |
448 |
|
* @throws NullPointerException if <tt>toElement</tt> is <tt>null</tt> and |
449 |
|
* this set uses natural ordering, or its comparator does |
450 |
|
* not tolerate <tt>null</tt> elements. |
462 |
|
* @throws ClassCastException if <tt>fromElement</tt> is not compatible |
463 |
|
* with this set's comparator (or, if the set has no comparator, |
464 |
|
* if <tt>fromElement</tt> does not implement <tt>Comparable</tt>). |
465 |
< |
* @throws IllegalArgumentException if this set is itself a subSet, |
466 |
< |
* headSet, or tailSet, and <tt>fromElement</tt> is not within the |
467 |
< |
* specified range of the subSet, headSet, or tailSet. |
465 |
> |
* @throws IllegalArgumentException if this set is itself a subset, |
466 |
> |
* and <tt>fromElement</tt> is not within the |
467 |
> |
* specified range of the subset. |
468 |
|
* @throws NullPointerException if <tt>fromElement</tt> is <tt>null</tt> |
469 |
|
* and this set uses natural ordering, or its comparator does |
470 |
|
* not tolerate <tt>null</tt> elements. |
510 |
|
/** |
511 |
|
* Returns an element greater than or equal to the given element, or |
512 |
|
* <tt>null</tt> if there is no such element. |
513 |
< |
* |
514 |
< |
* @param o the value to match |
513 |
> |
* |
514 |
> |
* @param e the value to match |
515 |
|
* @return an element greater than or equal to given element, or |
516 |
|
* <tt>null</tt> if there is no such element. |
517 |
< |
* @throws ClassCastException if o cannot be compared with the elements |
517 |
> |
* @throws ClassCastException if e cannot be compared with the elements |
518 |
|
* currently in the set. |
519 |
< |
* @throws NullPointerException if o is <tt>null</tt> and this map |
519 |
> |
* @throws NullPointerException if e is <tt>null</tt> and this map |
520 |
|
* uses natural ordering and is non-empty, or its comparator does |
521 |
|
* not tolerate <tt>null</tt> keys. |
522 |
|
*/ |
523 |
< |
public E ceiling(E o) { |
524 |
< |
return m.ceilingKey(o); |
523 |
> |
public E ceiling(E e) { |
524 |
> |
return m.ceilingKey(e); |
525 |
|
} |
526 |
|
|
527 |
|
/** |
528 |
|
* Returns an element strictly less than the given element, or |
529 |
|
* <tt>null</tt> if there is no such element. |
530 |
< |
* |
531 |
< |
* @param o the value to match |
530 |
> |
* |
531 |
> |
* @param e the value to match |
532 |
|
* @return the greatest element less than the given element, or |
533 |
|
* <tt>null</tt> if there is no such element. |
534 |
< |
* @throws ClassCastException if o cannot be compared with the elements |
534 |
> |
* @throws ClassCastException if e cannot be compared with the elements |
535 |
|
* currently in the set. |
536 |
< |
* @throws NullPointerException if o is <tt>null</tt> and this map |
536 |
> |
* @throws NullPointerException if e is <tt>null</tt> and this map |
537 |
|
* uses natural ordering and is non-empty, or its comparator does |
538 |
|
* not tolerate <tt>null</tt> keys. |
539 |
|
*/ |
540 |
< |
public E lower(E o) { |
541 |
< |
return m.lowerKey(o); |
540 |
> |
public E lower(E e) { |
541 |
> |
return m.lowerKey(e); |
542 |
|
} |
543 |
|
|
544 |
|
/** |
545 |
|
* Returns an element less than or equal to the given element, or |
546 |
|
* <tt>null</tt> if there is no such element. |
547 |
< |
* |
548 |
< |
* @param o the value to match |
547 |
> |
* |
548 |
> |
* @param e the value to match |
549 |
|
* @return the greatest element less than or equal to given |
550 |
|
* element, or <tt>null</tt> if there is no such element. |
551 |
< |
* @throws ClassCastException if o cannot be compared with the elements |
551 |
> |
* @throws ClassCastException if e cannot be compared with the elements |
552 |
|
* currently in the set. |
553 |
< |
* @throws NullPointerException if o is <tt>null</tt> and this map |
553 |
> |
* @throws NullPointerException if e is <tt>null</tt> and this map |
554 |
|
* uses natural ordering and is non-empty, or its comparator does |
555 |
|
* not tolerate <tt>null</tt> keys. |
556 |
|
*/ |
557 |
< |
public E floor(E o) { |
558 |
< |
return m.floorKey(o); |
557 |
> |
public E floor(E e) { |
558 |
> |
return m.floorKey(e); |
559 |
|
} |
560 |
|
|
561 |
|
/** |
562 |
|
* Returns an element strictly greater than the given element, or |
563 |
|
* <tt>null</tt> if there is no such element. |
564 |
< |
* |
565 |
< |
* @param o the value to match |
564 |
> |
* |
565 |
> |
* @param e the value to match |
566 |
|
* @return the least element greater than the given element, or |
567 |
|
* <tt>null</tt> if there is no such element. |
568 |
< |
* @throws ClassCastException if o cannot be compared with the elements |
568 |
> |
* @throws ClassCastException if e cannot be compared with the elements |
569 |
|
* currently in the set. |
570 |
< |
* @throws NullPointerException if o is <tt>null</tt> and this map |
570 |
> |
* @throws NullPointerException if e is <tt>null</tt> and this map |
571 |
|
* uses natural ordering and is non-empty, or its comparator does |
572 |
|
* not tolerate <tt>null</tt> keys. |
573 |
|
*/ |
574 |
< |
public E higher(E o) { |
575 |
< |
return m.higherKey(o); |
574 |
> |
public E higher(E e) { |
575 |
> |
return m.higherKey(e); |
576 |
|
} |
577 |
|
|
578 |
|
/** |
652 |
|
s.defaultReadObject(); |
653 |
|
|
654 |
|
// Read in Comparator |
655 |
< |
Comparator<E> c = (Comparator<E>) s.readObject(); |
655 |
> |
Comparator<? super E> c = (Comparator<? super E>) s.readObject(); |
656 |
|
|
657 |
|
// Create backing TreeMap |
658 |
|
TreeMap<E,Object> tm; |