jdk/src/share/classes/java/util/Comparator.java
changeset 19208 1e3d351eba80
parent 18571 8e3cb3c46ae8
child 19605 0f98f8e3bdcb
equal deleted inserted replaced
19207:3448b0cb4077 19208:1e3d351eba80
   350      * @return a comparator that imposes the <i>natural ordering</i> on {@code
   350      * @return a comparator that imposes the <i>natural ordering</i> on {@code
   351      *         Comparable} objects.
   351      *         Comparable} objects.
   352      * @see Comparable
   352      * @see Comparable
   353      * @since 1.8
   353      * @since 1.8
   354      */
   354      */
       
   355     @SuppressWarnings("unchecked")
   355     public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() {
   356     public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() {
   356         return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE;
   357         return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE;
   357     }
   358     }
   358 
   359 
   359     /**
   360     /**
   372      *         non-null, and compares non-null objects with the supplied
   373      *         non-null, and compares non-null objects with the supplied
   373      *         {@code Comparator}.
   374      *         {@code Comparator}.
   374      * @since 1.8
   375      * @since 1.8
   375      */
   376      */
   376     public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) {
   377     public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) {
   377         return new Comparators.NullComparator(true, comparator);
   378         return new Comparators.NullComparator<>(true, comparator);
   378     }
   379     }
   379 
   380 
   380     /**
   381     /**
   381      * Returns a null-friendly comparator that considers {@code null} to be
   382      * Returns a null-friendly comparator that considers {@code null} to be
   382      * greater than non-null. When both are {@code null}, they are considered
   383      * greater than non-null. When both are {@code null}, they are considered
   393      *         non-null, and compares non-null objects with the supplied
   394      *         non-null, and compares non-null objects with the supplied
   394      *         {@code Comparator}.
   395      *         {@code Comparator}.
   395      * @since 1.8
   396      * @since 1.8
   396      */
   397      */
   397     public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) {
   398     public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) {
   398         return new Comparators.NullComparator(false, comparator);
   399         return new Comparators.NullComparator<>(false, comparator);
   399     }
   400     }
   400 
   401 
   401     /**
   402     /**
   402      * Accepts a function that extracts a sort key from a type {@code T}, and
   403      * Accepts a function that extracts a sort key from a type {@code T}, and
   403      * returns a {@code Comparator<T>} that compares by that sort key using
   404      * returns a {@code Comparator<T>} that compares by that sort key using