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)
| 723 | */ |
| 724 | |
| 725 | @SuppressWarnings("unchecked") |
| 726 | static <E> Comparator<? super E> orNaturalOrder(@Nullable Comparator<? super E> comparator) { |
| 727 | if (comparator != null) { // can't use ? : because of javac bug 5080917 |
| 728 | return comparator; |
| 729 | } |
| 730 | return (Comparator<E>) Ordering.natural(); |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Returns a live {@link Map} view whose keys are the contents of {@code set} |