Class BooleanComparator
- java.lang.Object
-
- org.apache.commons.collections.comparators.BooleanComparator
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.Comparator
@Deprecated(since="2021-04-30") public final class BooleanComparator extends java.lang.Object implements java.util.Comparator, java.io.Serializable
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.AComparator
forBoolean
objects that can sort either true or false first.- Since:
- Commons Collections 3.0
- See Also:
getTrueFirstComparator()
,getFalseFirstComparator()
,getBooleanComparator(boolean)
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BooleanComparator()
Deprecated.Creates aBooleanComparator
that sortsfalse
values beforetrue
values.BooleanComparator(boolean trueFirst)
Deprecated.Creates aBooleanComparator
that sortstrueFirst
values before!trueFirst
values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
compare(java.lang.Boolean b1, java.lang.Boolean b2)
Deprecated.int
compare(java.lang.Object obj1, java.lang.Object obj2)
Deprecated.Compares two arbitrary Objects.boolean
equals(java.lang.Object object)
Deprecated.Returnstrue
iff that Object is is aComparator
whose ordering is known to be equivalent to mine.static BooleanComparator
getBooleanComparator(boolean trueFirst)
Deprecated.Returns a BooleanComparator instance that sortstrueFirst
values before!trueFirst
values.static BooleanComparator
getFalseFirstComparator()
Deprecated.Returns a BooleanComparator instance that sortsfalse
values beforetrue
values.static BooleanComparator
getTrueFirstComparator()
Deprecated.Returns a BooleanComparator instance that sortstrue
values beforefalse
values.int
hashCode()
Deprecated.Implement a hash code for this comparator that is consistent withequals
.boolean
sortsTrueFirst()
Deprecated.Returnstrue
iff I sorttrue
values beforefalse
values.
-
-
-
Constructor Detail
-
BooleanComparator
public BooleanComparator()
Deprecated.Creates aBooleanComparator
that sortsfalse
values beforetrue
values.Equivalent to
BooleanComparator(false)
.Please use the static factory instead whenever possible.
-
BooleanComparator
public BooleanComparator(boolean trueFirst)
Deprecated.Creates aBooleanComparator
that sortstrueFirst
values before!trueFirst
values.Please use the static factories instead whenever possible.
- Parameters:
trueFirst
- whentrue
, sorttrue
boolean values beforefalse
-
-
Method Detail
-
getTrueFirstComparator
public static BooleanComparator getTrueFirstComparator()
Deprecated.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
-
getFalseFirstComparator
public static BooleanComparator getFalseFirstComparator()
Deprecated.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
-
getBooleanComparator
public static BooleanComparator getBooleanComparator(boolean trueFirst)
Deprecated.Returns a BooleanComparator instance that sortstrueFirst
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
- whentrue
, sorttrue
Boolean
s beforefalse
- Returns:
- a singleton BooleanComparator instance
-
compare
public int compare(java.lang.Object obj1, java.lang.Object obj2)
Deprecated.Compares two arbitrary Objects. When both arguments areBoolean
, this method is equivalent tocompare((Boolean)obj1,(Boolean)obj2)
. When either argument is not aBoolean
, this methods throws aClassCastException
.- Specified by:
compare
in interfacejava.util.Comparator
- Parameters:
obj1
- the first object to compareobj2
- the second object to compare- Returns:
- negative if obj1 is less, positive if greater, zero if equal
- Throws:
java.lang.ClassCastException
- when either argument is notBoolean
-
compare
public int compare(java.lang.Boolean b1, java.lang.Boolean b2)
Deprecated.- 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:
java.lang.NullPointerException
- when either argumentnull
-
hashCode
public int hashCode()
Deprecated.Implement a hash code for this comparator that is consistent withequals
.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code for this comparator.
-
equals
public boolean equals(java.lang.Object object)
Deprecated.Returnstrue
iff that Object is is aComparator
whose ordering is known to be equivalent to mine.This implementation returns
true
iffthat
is aBooleanComparator
whose value ofsortsTrueFirst()
is equal to mine.- Specified by:
equals
in interfacejava.util.Comparator
- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- the object to compare to- Returns:
- true if equal
-
sortsTrueFirst
public boolean sortsTrueFirst()
Deprecated.Returnstrue
iff I sorttrue
values beforefalse
values. In other words, returnstrue
iffcompare(Boolean.FALSE,Boolean.TRUE)
returns a positive value.- Returns:
- the trueFirst flag
-
-