Class NullComparator
- java.lang.Object
-
- org.apache.commons.collections.comparators.NullComparator
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.Comparator
@Deprecated(since="2021-04-30") public class NullComparator extends java.lang.Object implements java.util.Comparator, java.io.Serializable
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.A Comparator that will compare nulls to be either lower or higher than other objects.- Since:
- Commons Collections 2.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description NullComparator()
Deprecated.Construct an instance that sortsnull
higher than any non-null
object it is compared with.NullComparator(boolean nullsAreHigh)
Deprecated.Construct an instance that sortsnull
higher or lower than any non-null
object it is compared with.NullComparator(java.util.Comparator nonNullComparator)
Deprecated.Construct an instance that sortsnull
higher than any non-null
object it is compared with.NullComparator(java.util.Comparator nonNullComparator, boolean nullsAreHigh)
Deprecated.Construct an instance that sortsnull
higher or lower than any non-null
object it is compared with.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
compare(java.lang.Object o1, java.lang.Object o2)
Deprecated.Perform a comparison between two objects.boolean
equals(java.lang.Object obj)
Deprecated.Determines whether the specified object represents a comparator that is equal to this comparator.int
hashCode()
Deprecated.Implement a hash code for this comparator that is consistent withequals(Object)
.
-
-
-
Constructor Detail
-
NullComparator
public NullComparator()
Deprecated.Construct an instance that sortsnull
higher than any non-null
object it is compared with. When comparing two non-null
objects, theComparableComparator
is used.
-
NullComparator
public NullComparator(java.util.Comparator nonNullComparator)
Deprecated.Construct an instance that sortsnull
higher than any non-null
object it is compared with. When comparing two non-null
objects, the specifiedComparator
is used.- Parameters:
nonNullComparator
- the comparator to use when comparing two non-null
objects. This argument cannot benull
- Throws:
java.lang.NullPointerException
- ifnonNullComparator
isnull
-
NullComparator
public NullComparator(boolean nullsAreHigh)
Deprecated.Construct an instance that sortsnull
higher or lower than any non-null
object it is compared with. When comparing two non-null
objects, theComparableComparator
is used.- Parameters:
nullsAreHigh
- atrue
value indicates thatnull
should be compared as higher than a non-null
object. Afalse
value indicates thatnull
should be compared as lower than a non-null
object.
-
NullComparator
public NullComparator(java.util.Comparator nonNullComparator, boolean nullsAreHigh)
Deprecated.Construct an instance that sortsnull
higher or lower than any non-null
object it is compared with. When comparing two non-null
objects, the specifiedComparator
is used.- Parameters:
nonNullComparator
- the comparator to use when comparing two non-null
objects. This argument cannot benull
nullsAreHigh
- atrue
value indicates thatnull
should be compared as higher than a non-null
object. Afalse
value indicates thatnull
should be compared as lower than a non-null
object.- Throws:
java.lang.NullPointerException
- ifnonNullComparator
isnull
-
-
Method Detail
-
compare
public int compare(java.lang.Object o1, java.lang.Object o2)
Deprecated.Perform a comparison between two objects. If both objects arenull
, a0
value is returned. If one object isnull
and the other is not, the result is determined on whether the Comparator was constructed to have nulls as higher or lower than other objects. If neither object isnull
, an underlying comparator specified in the constructor (or the default) is used to compare the non-null
objects.- Specified by:
compare
in interfacejava.util.Comparator
- Parameters:
o1
- the first object to compareo2
- the object to compare it to.- Returns:
-1
ifo1
is "lower" than (less than, before, etc.)o2
;1
ifo1
is "higher" than (greater than, after, etc.)o2
; or0
ifo1
ando2
are equal.
-
hashCode
public int hashCode()
Deprecated.Implement a hash code for this comparator that is consistent withequals(Object)
.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code for this comparator.
-
equals
public boolean equals(java.lang.Object obj)
Deprecated.Determines whether the specified object represents a comparator that is equal to this comparator.- Specified by:
equals
in interfacejava.util.Comparator
- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare this comparator with.- Returns:
true
if the specified object is a NullComparator with equivalentnull
comparison behavior (i.e.null
high or low) and with equivalent underlying non-null
object comparators.
-
-