org.springframework.util.comparator
Class NullSafeComparator
java.lang.Object
   org.springframework.util.comparator.NullSafeComparator
org.springframework.util.comparator.NullSafeComparator
- All Implemented Interfaces: 
- Comparator
- public class NullSafeComparator 
- extends Object- implements 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(Comparator comparator,
                   boolean nullsLow)Create a NullSafeComparator that sorts
 nullbased on the
 provided flag, decorating the given Comparator. | 
 
 
 
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(Comparator comparator,
                          boolean nullsLow)
- Create a NullSafeComparator that sorts nullbased 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 objects
- nullsLow- whether to treat nulls lower or higher than non-null objects
 
compare
public int compare(Object o1,
                   Object o2)
- 
- Specified by:
- comparein interface- Comparator
 
- 
 
equals
public boolean equals(Object obj)
- 
- Specified by:
- equalsin interface- Comparator
- Overrides:
- equalsin class- Object
 
- 
 
hashCode
public int hashCode()
- 
- Overrides:
- hashCodein class- Object
 
- 
 
toString
public String toString()
- 
- Overrides:
- toStringin class- Object
 
- 
 
Copyright © 2002-2008 The Spring Framework.