|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jga.util.NullComparator<T>
public class NullComparator<T>
Comparator Decorator used to gracefully compare null and non-null values. In most cases, passing a null to a Comparator results in a NullPointerException, as (in the general case) null is not part of a class' strict ordering. However, in many applications, null objects must be included in an ordering. This wrapper can be used to shield an underlying Comparator from dealing with where in the ordering null values should fall.
A flag is provided that determines whether nulls are less than non-nulls, (the default case) or greater than non-nulls. When comparing two values, this comparator determines if either argument is null: if both are null, then 0 is returned (ie, all nulls are considered equal). If neither argument is null, then both arguments are passed to the wrapped comparator. If one argument is null, then a positive or negative integer is returned, depending on which argument was null and the setting of the flag.
Constructor Summary | |
---|---|
NullComparator(java.util.Comparator<T> comp)
Builds a NullComparator that uses the given comparator to compare pairs of non-null values. |
|
NullComparator(java.util.Comparator<T> comp,
boolean flag)
Builds a NullComparator that uses the given comparator to compare pairs of non-null values, and uses the flag to determine if non-null values appear before non-null values in the resulting ordering. |
Method Summary | |
---|---|
int |
compare(T x,
T y)
|
java.util.Comparator<T> |
getComparator()
Returns the comparator used to compare pairs of non-null values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Comparator |
---|
equals |
Constructor Detail |
---|
public NullComparator(java.util.Comparator<T> comp)
public NullComparator(java.util.Comparator<T> comp, boolean flag)
Method Detail |
---|
public java.util.Comparator<T> getComparator()
public int compare(T x, T y)
compare
in interface java.util.Comparator<T>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |