| 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.
|