public class NullSafeComparator<T>
extends java.lang.Object
implements java.util.Comparator<T>
Comparable| Modifier and Type | Field and Description |
|---|---|
static NullSafeComparator |
NULLS_HIGH
A shared default instance of this comparator, treating nulls higher
than non-null objects.
|
static NullSafeComparator |
NULLS_LOW
A shared default instance of this comparator, treating nulls lower
than non-null objects.
|
| Constructor and Description |
|---|
NullSafeComparator(java.util.Comparator<T> comparator,
boolean nullsLow)
Create a NullSafeComparator that sorts
null based on the
provided flag, decorating the given Comparator. |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(T o1,
T o2) |
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
java.lang.String |
toString() |
public static final NullSafeComparator NULLS_LOW
public static final NullSafeComparator NULLS_HIGH
public NullSafeComparator(java.util.Comparator<T> comparator, boolean nullsLow)
null based on the
provided flag, decorating the given Comparator.
When comparing two non-null objects, the specified Comparator will be used. The given underlying Comparator must be able to handle the elements that this Comparator will be applied to.
comparator - the comparator to use when comparing two non-null objectsnullsLow - whether to treat nulls lower or higher than non-null objectspublic boolean equals(java.lang.Object obj)
equals in interface java.util.Comparator<T>equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object