⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.comparators

Class BooleanComparator

java.lang.Object
|
+--org.apache.commons.collections.comparators.BooleanComparator

All Implemented Interfaces:
Comparator, Serializable


public final class BooleanComparator
extends java.lang.Object
implements Comparator, Serializable

A Comparator for Boolean objects.
Since:
Commons Collections 3.0
Author:
Rodney Waldhoff
See Also:
getTrueFirstComparator
getFalseFirstComparator
getBooleanComparator

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 o1, Object o2)

Compares two arbitrary Objects.

int

compare(Boolean b1, Boolean b2)

Compares two non-nullBooleans according to the value of #sortsTrueFirst.

boolean

equals(Object that)

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 equals.

boolean

sortsTrueFirst()

Returns true iff I sort true values before false values.

Constructor Details

BooleanComparator

public BooleanComparator()

Creates a BooleanComparator that sorts false values before true values. Equivalent to BooleanComparator(boolean) BooleanComparator(false).


BooleanComparator

public BooleanComparator(boolean trueFirst)

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

Parameters:
trueFirst - when true, sort trueBooleans before falseBooleans.

Method Details

compare

public int compare(Boolean b1, Boolean b2)

Compares two non-nullBooleans according to the value of sortsTrueFirst.

Parameters:
b1
b2
Throws:
- when either argument null

compare

public int compare(Object o1, Object o2)

Compares two arbitrary Objects. When both arguments are Boolean, this method is equivalent to compare(Boolean,Boolean) compare((Boolean)o1,(Boolean)o2). When either argument is not a Boolean, this methods throws a ClassCastException.

Parameters:
o1
o2
Throws:
- when either argument is not a Boolean

equals

public boolean equals(Object that)

Parameters:
that

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.

Parameters:
trueFirst - when true, sort trueBooleans before falseBooleans.
Returns:
a cached 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.


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.


hashCode

public int hashCode()

Returns:
a hash code for this comparator.

sortsTrueFirst

public boolean sortsTrueFirst()