org.springframework.util.comparator
Class NullSafeComparator
java.lang.Object
org.springframework.util.comparator.NullSafeComparator
- All Implemented Interfaces:
- java.util.Comparator
public class NullSafeComparator
- extends java.lang.Object
- implements java.util.Comparator
A Comparator that will safely compare nulls to be lower or higher than
other objects. Can decorate a given Comparator or work on Comparables.
- Since:
- 1.2.2
- Author:
- Keith Donald, Juergen Hoeller
- See Also:
Comparable
Constructor Summary |
NullSafeComparator(java.util.Comparator comparator,
boolean nullsLow)
Create a NullSafeComparator that sorts null based on the
provided flag, decorating the given Comparator. |
Method Summary |
int |
compare(java.lang.Object o1,
java.lang.Object 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 |
NULLS_LOW
public static final NullSafeComparator NULLS_LOW
- A shared default instance of this comparator, treating nulls lower
than non-null objects.
NULLS_HIGH
public static final NullSafeComparator NULLS_HIGH
- A shared default instance of this comparator, treating nulls higher
than non-null objects.
NullSafeComparator
public NullSafeComparator(java.util.Comparator comparator,
boolean nullsLow)
- Create a NullSafeComparator that sorts
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.
- Parameters:
comparator
- the comparator to use when comparing two non-null objectsnullsLow
- whether to treat nulls lower or higher than non-null objects
compare
public int compare(java.lang.Object o1,
java.lang.Object o2)
- Specified by:
compare
in interface java.util.Comparator
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equals
in interface java.util.Comparator
- Overrides:
equals
in class java.lang.Object
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
Copyright © 2002-2008 The Spring Framework.