Class NullComparator<E>
java.lang.Object
org.apache.commons.collections4.comparators.NullComparator<E>
- Type Parameters:
- E- the type of objects compared by this comparator
- All Implemented Interfaces:
- Serializable,- Comparator<E>
A Comparator that will compare nulls to be either lower or higher than
 other objects.
- Since:
- 2.0
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct an instance that sortsnullhigher than any non-nullobject it is compared with.NullComparator(boolean nullsAreHigh) Construct an instance that sortsnullhigher or lower than any non-nullobject it is compared with.NullComparator(Comparator<? super E> nonNullComparator) Construct an instance that sortsnullhigher than any non-nullobject it is compared with.NullComparator(Comparator<? super E> nonNullComparator, boolean nullsAreHigh) Construct an instance that sortsnullhigher or lower than any non-nullobject it is compared with.
- 
Method SummaryModifier and TypeMethodDescriptionintPerform a comparison between two objects.booleanDetermines whether the specified object represents a comparator that is equal to this comparator.inthashCode()Implement a hash code for this comparator that is consistent withequals(Object).Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparatorreversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
- 
Constructor Details- 
NullComparatorpublic NullComparator()Construct an instance that sortsnullhigher than any non-nullobject it is compared with. When comparing two non-nullobjects, theComparableComparatoris used.
- 
NullComparatorConstruct an instance that sortsnullhigher or lower than any non-nullobject it is compared with. When comparing two non-nullobjects, theComparableComparatoris used.- Parameters:
- nullsAreHigh- a- truevalue indicates that- nullshould be compared as higher than a non-- nullobject. A- falsevalue indicates that- nullshould be compared as lower than a non-- nullobject.
 
- 
NullComparatorConstruct an instance that sortsnullhigher than any non-nullobject it is compared with. When comparing two non-nullobjects, the specifiedComparatoris used.- Parameters:
- nonNullComparator- the comparator to use when comparing two non-- nullobjects. This argument cannot be- null
- Throws:
- NullPointerException- if- nonNullComparatoris- null
 
- 
NullComparatorConstruct an instance that sortsnullhigher or lower than any non-nullobject it is compared with. When comparing two non-nullobjects, the specifiedComparatoris used.- Parameters:
- nonNullComparator- the comparator to use when comparing two non-- nullobjects. This argument cannot be- null
- nullsAreHigh- a- truevalue indicates that- nullshould be compared as higher than a non-- nullobject. A- falsevalue indicates that- nullshould be compared as lower than a non-- nullobject.
- Throws:
- NullPointerException- if- nonNullComparatoris- null
 
 
- 
- 
Method Details- 
comparePerform a comparison between two objects. If both objects arenull, a0value is returned. If one object isnulland 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-nullobjects.- Specified by:
- comparein interface- Comparator<E>
- Parameters:
- o1- the first object to compare
- o2- the object to compare it to.
- Returns:
- -1if- o1is "lower" than (less than, before, etc.)- o2;- 1if- o1is "higher" than (greater than, after, etc.)- o2; or- 0if- o1and- o2are equal.
 
- 
equalsDetermines whether the specified object represents a comparator that is equal to this comparator.- Specified by:
- equalsin interface- Comparator<E>
- Overrides:
- equalsin class- Object
- Parameters:
- obj- the object to compare this comparator with.
- Returns:
- trueif the specified object is a NullComparator with equivalent- nullcomparison behavior (i.e.- nullhigh or low) and with equivalent underlying non-- nullobject comparators.
 
- 
hashCodeImplement a hash code for this comparator that is consistent withequals(Object).
 
-