Returns the specified comparator if not null; otherwise returns Ordering.natural(). This method is an abomination of generics; the only purpose of this method is to contain the ugly type-casting in one place.
(@Nullable Comparator<? super E> comparator)
| 699 | * purpose of this method is to contain the ugly type-casting in one place. |
| 700 | */ |
| 701 | @SuppressWarnings("unchecked") |
| 702 | static <E> Comparator<? super E> orNaturalOrder(@Nullable Comparator<? super E> comparator) { |
| 703 | if (comparator != null) { // can't use ? : because of javac bug 5080917 |
| 704 | return comparator; |
| 705 | } |
| 706 | return (Comparator<E>) Ordering.natural(); |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * Returns a live {@link Map} view whose keys are the contents of {@code set} |