public final class BooleanComparator extends Objectimplements Comparator <Boolean >, Serializable
Comparator for
Boolean objects that can sort either true or false first.
getTrueFirstComparator(),
getFalseFirstComparator(),
booleanComparator(boolean),
Serialized Form
| Constructor and Description |
|---|
BooleanComparator()
Creates a
BooleanComparator that sorts
false values before
true values.
|
BooleanComparator(boolean trueFirst)
Creates a
BooleanComparator that sorts
trueFirst values before
!trueFirst values.
|
| Modifier and Type | Method and Description |
|---|---|
static BooleanComparator |
booleanComparator(boolean trueFirst)
Returns a BooleanComparator instance that sorts
trueFirst values before
!trueFirst values.
|
int |
compare(Boolean
|
boolean |
equals(Object
Returns
true iff
that Object is is a
Comparator whose ordering is known to be equivalent to mine.
|
static BooleanComparator |
getFalseFirstComparator()
Returns a BooleanComparator instance that sorts
false values before
true values.
|
static BooleanComparator |
getTrueFirstComparator()
Returns a BooleanComparator instance that sorts
true values before
false values.
|
int |
hashCode()
Implement a hash code for this comparator that is consistent with
equals.
|
boolean |
sortsTrueFirst()
Returns
true iff I sort
true values before
false values.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic BooleanComparator()
BooleanComparator that sorts
false values before
true values.
Equivalent to BooleanComparator(false).
Please use the static factory instead whenever possible.
public BooleanComparator(boolean trueFirst)
BooleanComparator that sorts
trueFirst values before
!trueFirst values.
Please use the static factories instead whenever possible.
trueFirst - when
true, sort
true boolean values before
false
public static BooleanComparatorgetTrueFirstComparator()
true values before
false 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.
public static BooleanComparatorgetFalseFirstComparator()
false values before
true 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.
public static BooleanComparatorbooleanComparator(boolean trueFirst)
trueFirst values before
!trueFirst 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.
trueFirst - when
true, sort
true
Booleans before
false
public int compare(Booleanb1, Boolean b2)
compare in interface
Comparator<Boolean>
b1 - the first boolean to compare
b2 - the second boolean to compare
NullPointerException - when either argument
null
public int hashCode()
equals.
public boolean equals(Objectobject)
true iff
that Object is is a
Comparator whose ordering is known to be equivalent to mine.
This implementation returns true iff that is a BooleanComparator whose value of sortsTrueFirst() is equal to mine.
equals in interface
Comparator<Boolean>
equals in class
Object
object - the object to compare to
public boolean sortsTrueFirst()
true iff I sort
true values before
false values. In other words, returns
true iff
compare(Boolean.FALSE,Boolean.TRUE) returns a positive value.