Class BooleanComparator
- All Implemented Interfaces:
Serializable
,Comparator<Boolean>
Comparator
for Boolean
objects that can sort either
true or false first.- Since:
- 3.0
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates aBooleanComparator
that sortsfalse
values beforetrue
values.BooleanComparator
(boolean trueFirst) Creates aBooleanComparator
that sorts<i>trueFirst</i>
values before!<i>trueFirst</i>
values. -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleanComparator
booleanComparator
(boolean trueFirst) Returns a BooleanComparator instance that sorts<i>trueFirst</i>
values before!<i>trueFirst</i>
values.int
boolean
Returnstrue
iff that Object is aComparator
whose ordering is known to be equivalent to mine.static BooleanComparator
Returns a BooleanComparator instance that sortsfalse
values beforetrue
values.static BooleanComparator
Returns a BooleanComparator instance that sortstrue
values beforefalse
values.int
hashCode()
Implement a hash code for this comparator that is consistent withequals
.boolean
Returnstrue
iff I sorttrue
values beforefalse
values.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
BooleanComparator
public BooleanComparator()Creates aBooleanComparator
that sortsfalse
values beforetrue
values.Equivalent to
BooleanComparator(false)
.Please use the static factory instead whenever possible.
-
BooleanComparator
Creates aBooleanComparator
that sorts<i>trueFirst</i>
values before!<i>trueFirst</i>
values.Please use the static factories instead whenever possible.
- Parameters:
trueFirst
- whentrue
, sorttrue
boolean values beforefalse
-
-
Method Details
-
booleanComparator
Returns a BooleanComparator instance that sorts<i>trueFirst</i>
values before!<i>trueFirst</i>
values.Clients are encouraged to use the value returned from this method instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple BooleanComparators may be used in the same virtual machine.
- Parameters:
trueFirst
- whentrue
, sorttrue
Boolean
s beforefalse
- Returns:
- a singleton BooleanComparator instance
- Since:
- 4.0
-
getFalseFirstComparator
Returns a BooleanComparator instance that sortsfalse
values beforetrue
values.Clients are encouraged to use the value returned from this method instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple BooleanComparators may be used in the same virtual machine.
- Returns:
- the false first singleton BooleanComparator
-
getTrueFirstComparator
Returns a BooleanComparator instance that sortstrue
values beforefalse
values.Clients are encouraged to use the value returned from this method instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple BooleanComparators may be used in the same virtual machine.
- Returns:
- the true first singleton BooleanComparator
-
compare
- Specified by:
compare
in interfaceComparator<Boolean>
- Parameters:
b1
- the first boolean to compareb2
- the second boolean to compare- Returns:
- negative if obj1 is less, positive if greater, zero if equal
- Throws:
NullPointerException
- when either argumentnull
-
equals
Returnstrue
iff that Object is aComparator
whose ordering is known to be equivalent to mine.This implementation returns
true
iff<i>that</i>
is aBooleanComparator
whose value ofsortsTrueFirst()
is equal to mine.- Specified by:
equals
in interfaceComparator<Boolean>
- Overrides:
equals
in classObject
- Parameters:
object
- the object to compare to- Returns:
- true if equal
-
hashCode
Implement a hash code for this comparator that is consistent withequals
. -
sortsTrueFirst
Returnstrue
iff I sorttrue
values beforefalse
values. In other words, returnstrue
iffcompare(Boolean.FALSE,Boolean.TRUE)
returns a positive value.- Returns:
- the trueFirst flag
-