public final class BooleanComparator
extends java.lang.Object
implements java.util.Comparator, java.io.Serializable
Comparator
for Boolean
objects that can sort either
true or false first.
getTrueFirstComparator()
,
getFalseFirstComparator()
,
getBooleanComparator(boolean)
,
Serialized FormConstructor 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 |
---|---|
int |
compare(java.lang.Boolean b1,
java.lang.Boolean b2)
|
int |
compare(java.lang.Object obj1,
java.lang.Object obj2)
Compares two arbitrary Objects.
|
boolean |
equals(java.lang.Object object)
Returns
true iff that Object is
is a Comparator whose ordering is known to be
equivalent to mine. |
static BooleanComparator |
getBooleanComparator(boolean trueFirst)
Returns a BooleanComparator instance that sorts
trueFirst values before
!trueFirst values. |
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. |
public 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 BooleanComparator getTrueFirstComparator()
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 BooleanComparator getFalseFirstComparator()
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 BooleanComparator getBooleanComparator(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
Boolean
s before false
public int compare(java.lang.Object obj1, java.lang.Object obj2)
Boolean
, this method is equivalent to
compare((Boolean)obj1,(Boolean)obj2)
.
When either argument is not a Boolean
, this methods throws
a ClassCastException
.compare
in interface java.util.Comparator
obj1
- the first object to compareobj2
- the second object to comparejava.lang.ClassCastException
- when either argument is not Boolean
public int compare(java.lang.Boolean b1, java.lang.Boolean b2)
b1
- the first boolean to compareb2
- the second boolean to comparejava.lang.NullPointerException
- when either argument null
public int hashCode()
equals
.hashCode
in class java.lang.Object
public boolean equals(java.lang.Object object)
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 java.util.Comparator
equals
in class java.lang.Object
object
- the object to compare topublic 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.Copyright © 2010 - 2020 Adobe. All Rights Reserved