java.util.Comparators Java Examples
The following examples show how to use
java.util.Comparators.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Comparator.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #2
Source File: Comparator.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #3
Source File: Comparator.java From jdk8u-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #4
Source File: Comparator.java From jdk8u-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #5
Source File: Comparator.java From jdk8u-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #6
Source File: Comparator.java From Java8CN with Apache License 2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #7
Source File: Comparator.java From Java8CN with Apache License 2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #8
Source File: Comparator.java From Java8CN with Apache License 2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #9
Source File: Comparator.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #10
Source File: Comparator.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #11
Source File: Comparator.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #12
Source File: Comparator.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #13
Source File: Comparator.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #14
Source File: Comparator.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #15
Source File: Comparator.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #16
Source File: Comparator.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #17
Source File: Comparator.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #18
Source File: Comparator.java From jdk8u_jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #19
Source File: Comparator.java From jdk8u_jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #20
Source File: Comparator.java From jdk8u_jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #21
Source File: Comparator.java From jdk8u-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #22
Source File: Comparator.java From jdk8u-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #23
Source File: Comparator.java From jdk8u-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #24
Source File: Comparator.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #25
Source File: Comparator.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #26
Source File: Comparator.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #27
Source File: Comparator.java From j2objc with Apache License 2.0 | 2 votes |
/** * Returns a comparator that compares {@link Comparable} objects in natural * order. * * <p>The returned comparator is serializable and throws {@link * NullPointerException} when comparing {@code null}. * * @param <T> the {@link Comparable} type of element to be compared * @return a comparator that imposes the <i>natural ordering</i> on {@code * Comparable} objects. * @see Comparable * @since 1.8 */ @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; }
Example #28
Source File: Comparator.java From j2objc with Apache License 2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * less than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be less than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); }
Example #29
Source File: Comparator.java From j2objc with Apache License 2.0 | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }
Example #30
Source File: Comparator.java From JDKSourceCode1.8 with MIT License | 2 votes |
/** * Returns a null-friendly comparator that considers {@code null} to be * greater than non-null. When both are {@code null}, they are considered * equal. If both are non-null, the specified {@code Comparator} is used * to determine the order. If the specified comparator is {@code null}, * then the returned comparator considers all non-null values to be equal. * * <p>The returned comparator is serializable if the specified comparator * is serializable. * * @param <T> the type of the elements to be compared * @param comparator a {@code Comparator} for comparing non-null values * @return a comparator that considers {@code null} to be greater than * non-null, and compares non-null objects with the supplied * {@code Comparator}. * @since 1.8 */ public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); }