|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.comparator.NullSafeComparator<T>
public class NullSafeComparator<T>
A Comparator that will safely compare nulls to be lower or higher than other objects. Can decorate a given Comparator or work on Comparables.
Comparable
Field Summary | |
---|---|
private java.util.Comparator<T> |
nonNullComparator
|
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. |
private boolean |
nullsLow
|
Constructor Summary | |
---|---|
private |
NullSafeComparator(boolean nullsLow)
Create a NullSafeComparator that sorts null based on
the provided flag, working on Comparables. |
|
NullSafeComparator(java.util.Comparator<T> comparator,
boolean nullsLow)
Create a NullSafeComparator that sorts null based on the
provided flag, decorating the given Comparator. |
Method Summary | |
---|---|
int |
compare(T o1,
T o2)
|
boolean |
equals(java.lang.Object obj)
|
int |
hashCode()
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final NullSafeComparator NULLS_LOW
public static final NullSafeComparator NULLS_HIGH
private final java.util.Comparator<T> nonNullComparator
private final boolean nullsLow
Constructor Detail |
---|
private NullSafeComparator(boolean nullsLow)
null
based on
the provided flag, working on Comparables.
When comparing two non-null objects, their Comparable implementation will be used: this means that non-null elements (that this Comparator will be applied to) need to implement Comparable.
As a convenience, you can use the default shared instances:
NullSafeComparator.NULLS_LOW
and
NullSafeComparator.NULLS_HIGH
.
nullsLow
- whether to treat nulls lower or higher than non-null objectsComparable
,
NULLS_LOW
,
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 objectsMethod Detail |
---|
public int compare(T o1, T o2)
compare
in interface java.util.Comparator<T>
public boolean equals(java.lang.Object obj)
equals
in interface java.util.Comparator<T>
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |