org.apache.commons.collections.comparators
public final class BooleanComparator extends Object implements Comparator, Serializable
Since: Commons Collections 3.0
Version: $Revision: 1.14 $ $Date: 2004/05/16 11:56:47 $
Constructor Summary | |
---|---|
BooleanComparator()
Creates a BooleanComparator that sorts
false values before true values.
| |
BooleanComparator(boolean trueFirst)
Creates a BooleanComparator that sorts
trueFirst values before
!trueFirst values.
|
Method Summary | |
---|---|
int | compare(Object obj1, Object obj2)
Compares two arbitrary Objects.
|
int | compare(Boolean b1, Boolean b2)
Compares two non- null Boolean objects
according to the value of {@link #trueFirst}.
|
boolean | equals(Object object)
Returns true iff that Object is
is a {@link 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
{@link #equals(Object) equals}.
|
boolean | sortsTrueFirst()
Returns true iff
I sort true values before
false values. |
BooleanComparator
that sorts
false
values before true
values.
Equivalent to {@link #BooleanComparator(boolean) BooleanComparator(false)}.
Please use the static factory instead whenever possible.
BooleanComparator
that sorts
trueFirst
values before
!trueFirst
values.
Please use the static factories instead whenever possible.
Parameters: trueFirst when true
, sort
true
boolean values before false
Boolean
, this method is equivalent to
{@link #compare(Boolean,Boolean) compare((Boolean)obj1,(Boolean)obj2)}.
When either argument is not a Boolean
, this methods throws
a {@link ClassCastException}.
Parameters: obj1 the first object to compare obj2 the second object to compare
Returns: negative if obj1 is less, positive if greater, zero if equal
Throws: ClassCastException when either argument is not Boolean
null
Boolean
objects
according to the value of {@link #trueFirst}.
Parameters: b1 the first boolean to compare b2 the second boolean to compare
Returns: negative if obj1 is less, positive if greater, zero if equal
Throws: NullPointerException when either argument null
true
iff that Object is
is a {@link Comparator} whose ordering is known to be
equivalent to mine.
This implementation returns true
iff that
is a {@link BooleanComparator}
whose {@link #trueFirst} value is equal to mine.
Parameters: object the object to compare to
Returns: true if equal
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.
Parameters: trueFirst when true
, sort
true
Boolean
s before false
Returns: a singleton BooleanComparator instance
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.
Returns: the false first singleton BooleanComparator
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.
Returns: the true first singleton BooleanComparator
Returns: a hash code for this comparator.
true
iff
I sort true
values before
false
values. In other words,
returns true
iff
{@link #compare(Boolean,Boolean) compare(Boolean.FALSE,Boolean.TRUE)}
returns a positive value.
Returns: the trueFirst flag