Top Description Fields Constructors Methods
org.apache.commons.collections4.comparators

public final Class BooleanComparator

extends Object
implements Comparator<Boolean>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.Comparator
Imports
java.io.Serializable, java.util.Comparator

A Comparator for Boolean objects that can sort either true or false first.
Since
3.0
See Also
getTrueFirstComparator(), getFalseFirstComparator(), booleanComparator(boolean)

Field Summary

Modifier and TypeField and Description
private static final BooleanComparator
FALSE_FIRST

Constant "false first" reference.

private static final long
serialVersionUID

Serialization version.

private static final BooleanComparator
TRUE_FIRST

Constant "true first" reference.

private boolean
trueFirst

true iff true values sort before false values.

Constructor Summary

AccessConstructor and Description
public
BooleanComparator()

Creates a BooleanComparator that sorts false values before true values.

public
BooleanComparator(final boolean
when true, sort true boolean values before false
trueFirst
)

Creates a BooleanComparator that sorts trueFirst values before !trueFirst values.

Method Summary

Modifier and TypeMethod and Description
public static BooleanComparator

Returns:

a singleton BooleanComparator instance
booleanComparator
(final boolean
when true, sort true Booleans before false
trueFirst
)

Returns a BooleanComparator instance that sorts trueFirst values before !trueFirst values.

public int

Returns:

negative if obj1 is less, positive if greater, zero if equal
compare
(final Boolean
the first boolean to compare
b1
,
final Boolean
the second boolean to compare
b2
)

Implements java.util.Comparator.compare.

Compares two non-null Boolean objects according to the value of sortsTrueFirst().
public boolean

Returns:

true if equal
equals
(final Object
the object to compare to
object
)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Returns true iff that Object is is a Comparator whose ordering is known to be equivalent to mine.
public static BooleanComparator

Returns:

the false first singleton BooleanComparator
getFalseFirstComparator
()

Returns a BooleanComparator instance that sorts false values before true values.

public static BooleanComparator

Returns:

the true first singleton BooleanComparator
getTrueFirstComparator
()

Returns a BooleanComparator instance that sorts true values before false values.

public int

Returns:

a hash code for this comparator.
hashCode
()

Overrides java.lang.Object.hashCode.

Implement a hash code for this comparator that is consistent with equals.
public boolean

Returns:

the trueFirst flag
sortsTrueFirst
()

Returns true iff I sort true values before false values.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

FALSE_FIRSTback to summary
private static final BooleanComparator FALSE_FIRST

Constant "false first" reference.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

TRUE_FIRSTback to summary
private static final BooleanComparator TRUE_FIRST

Constant "true first" reference.

trueFirstback to summary
private boolean trueFirst

true iff true values sort before false values.

Constructor Detail

BooleanComparatorback to summary
public BooleanComparator()

Creates a BooleanComparator that sorts false values before true values.

Equivalent to BooleanComparator(false).

Please use the static factory instead whenever possible.

BooleanComparatorback to summary
public BooleanComparator(final boolean trueFirst)

Creates a BooleanComparator that sorts trueFirst values before !trueFirst values.

Please use the static factories instead whenever possible.

Parameters
trueFirst:boolean

when true, sort true boolean values before false

Method Detail

booleanComparatorback to summary
public static BooleanComparator booleanComparator(final 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.

Parameters
trueFirst:boolean

when true, sort true Booleans before false

Returns:BooleanComparator

a singleton BooleanComparator instance

Since
4.0
compareback to summary
public int compare(final Boolean b1, final Boolean b2)

Implements java.util.Comparator.compare.

Compares two non-null Boolean objects according to the value of sortsTrueFirst().

Parameters
b1:Boolean

the first boolean to compare

b2:Boolean

the second boolean to compare

Returns:int

negative if obj1 is less, positive if greater, zero if equal

Annotations
@Override
Exceptions
NullPointerException:
when either argument null
equalsback to summary
public boolean equals(final Object object)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

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.

Parameters
object:Object

the object to compare to

Returns:boolean

true if equal

Annotations
@Override
getFalseFirstComparatorback to summary
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.

Returns:BooleanComparator

the false first singleton BooleanComparator

getTrueFirstComparatorback to summary
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.

Returns:BooleanComparator

the true first singleton BooleanComparator

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implement a hash code for this comparator that is consistent with equals.

Returns:int

a hash code for this comparator.

Annotations
@Override
sortsTrueFirstback to summary
public boolean sortsTrueFirst()

Returns true iff I sort true values before false values. In other words, returns true iff compare(Boolean.FALSE,Boolean.TRUE) returns a positive value.

Returns:boolean

the trueFirst flag