com.programix.collections
Class NullLastComparator
java.lang.Object
com.programix.collections.NullLastComparator
- All Implemented Interfaces:
- Comparator
public class NullLastComparator
- extends Object
- implements Comparator
This Comparator wrapper considers "null" to be "greater than"
any non-null reference and will sort any null's to the bottom.
This Comparator wraps around a "raw" Comparator and
first checks to see if either of the references is null. If they are
both null, then they are considered equal. If one is null and the other
is not null, then the null one is considered to be "greater than" the other.
If both references are not null, then the supplied "raw" Comparator
is used to complete the comparison.
- Author:
- Paul Hyde
- See Also:
NullFirstComparator,
ReverseComparator,
ComparableComparator
|
Constructor Summary |
NullLastComparator(Comparator rawComparator)
Create a wrapper that checks for null references before calling
the rawComparator and considers null's to be "greater than"
non-null references. |
|
Method Summary |
int |
compare(Object obj1,
Object obj2)
This implementation of the
compare method on
Comparator will quickly check
if both references are the same using == (which
evaluates to true if both references are pointing
to the same object or both are null). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NullLastComparator
public NullLastComparator(Comparator rawComparator)
- Create a wrapper that checks for null references before calling
the rawComparator and considers null's to be "greater than"
non-null references.
- Parameters:
rawComparator - the comparator to use if (and only if) both
references are NOT null.
compare
public int compare(Object obj1,
Object obj2)
- This implementation of the
compare method on
Comparator will quickly check
if both references are the same using == (which
evaluates to true if both references are pointing
to the same object or both are null).
If the references are the same, then this will quickly return
0.
- Specified by:
compare in interface Comparator
Copyright © 2001-2007
Programix Incorporated.
All rights reserved.
ProgramixGenericLib is free
and is
OSI Certified
Open Source Software under the BSD
license.