Fix Comparators.nullsLow and Comporators.nullsHigh behavior

Commit 33454a4007 introduced a regression in Comparators.nullsLow() and
Comporators.nullsHigh().

This commit updates the code so that nullsLow() sorts null values lower
than non-null values and nullsHigh sorts null values higher than
non-null values.

See gh-25478
Closes gh-31808
This commit is contained in:
Mathieu AMBLARD (u118971)
2023-12-11 09:30:44 +01:00
committed by Sam Brannen
parent d75a7c3818
commit a01384068a
2 changed files with 57 additions and 6 deletions

View File

@@ -39,7 +39,7 @@ public abstract class Comparators {
/**
* Return a {@link Comparable} adapter which accepts
* null values and sorts them lower than non-null values.
* @see Comparator#nullsLast(Comparator)
* @see Comparator#nullsFirst(Comparator)
*/
public static <T> Comparator<T> nullsLow() {
return nullsLow(comparable());
@@ -48,16 +48,16 @@ public abstract class Comparators {
/**
* Return a decorator for the given comparator which accepts
* null values and sorts them lower than non-null values.
* @see Comparator#nullsLast(Comparator)
* @see Comparator#nullsFirst(Comparator)
*/
public static <T> Comparator<T> nullsLow(Comparator<T> comparator) {
return Comparator.nullsLast(comparator);
return Comparator.nullsFirst(comparator);
}
/**
* Return a {@link Comparable} adapter which accepts
* null values and sorts them higher than non-null values.
* @see Comparator#nullsFirst(Comparator)
* @see Comparator#nullsLast(Comparator)
*/
public static <T> Comparator<T> nullsHigh() {
return nullsHigh(comparable());
@@ -66,10 +66,10 @@ public abstract class Comparators {
/**
* Return a decorator for the given comparator which accepts
* null values and sorts them higher than non-null values.
* @see Comparator#nullsFirst(Comparator)
* @see Comparator#nullsLast(Comparator)
*/
public static <T> Comparator<T> nullsHigh(Comparator<T> comparator) {
return Comparator.nullsFirst(comparator);
return Comparator.nullsLast(comparator);
}
}