org.apache.commons.collections.comparators
Class BooleanComparator
java.lang.Objectorg.apache.commons.collections.comparators.BooleanComparator
- Comparator, Serializable
public final class BooleanComparator
extends java.lang.Object
implements Comparator, Serializable
A
Comparator for
Boolean objects that can sort either
true or false first.
$Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $BooleanComparator()- Creates a
BooleanComparator that sorts
false values before true values.
|
BooleanComparator(boolean trueFirst)- Creates a
BooleanComparator that sorts
trueFirst values before
!trueFirst values.
|
BooleanComparator
public BooleanComparator()
Creates a
BooleanComparator that sorts
false values before
true values.
Equivalent to
BooleanComparator(false).
Please use the static factory instead whenever possible.
BooleanComparator
public BooleanComparator(boolean trueFirst)
Creates a
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
compare
public int compare(Boolean b1,
Boolean b2) Compares two non-
null Boolean objects
according to the value of
sortsTrueFirst().
b1 - the first boolean to compareb2 - the second boolean to compare
- negative if obj1 is less, positive if greater, zero if equal
compare
public int compare(Object obj1,
Object obj2) Compares two arbitrary Objects.
When both arguments are
Boolean, this method is equivalent to
compare((Boolean)obj1,(Boolean)obj2).
When either argument is not a
Boolean, this methods throws
a
ClassCastException.
obj1 - the first object to compareobj2 - the second object to compare
- negative if obj1 is less, positive if greater, zero if equal
equals
public boolean equals(Object object)
Returns
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.
object - the object to compare to
getBooleanComparator
public static BooleanComparator getBooleanComparator(boolean trueFirst)
Returns a BooleanComparator instance that sorts
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
- a singleton BooleanComparator instance
getFalseFirstComparator
public static BooleanComparator getFalseFirstComparator()
Returns a BooleanComparator instance that sorts
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.
- the false first singleton BooleanComparator
getTrueFirstComparator
public static BooleanComparator getTrueFirstComparator()
Returns a BooleanComparator instance that sorts
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.
- the true first singleton BooleanComparator
hashCode
public int hashCode()
Implement a hash code for this comparator that is consistent with
equals.
- a hash code for this comparator.
sortsTrueFirst
public boolean sortsTrueFirst()
Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.