Class BooleanComparator
- All Implemented Interfaces:
- Serializable,- Comparator<Boolean>
Comparator for Boolean objects that can sort either
 true or false first.- Since:
- 3.0
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionCreates aBooleanComparatorthat sortsfalsevalues beforetruevalues.BooleanComparator(boolean trueFirst) Creates aBooleanComparatorthat sorts<em>trueFirst</em>values before!<em>trueFirst</em>values.
- 
Method SummaryModifier and TypeMethodDescriptionstatic BooleanComparatorbooleanComparator(boolean trueFirst) Returns a BooleanComparator instance that sorts<em>trueFirst</em>values before!<em>trueFirst</em>values.intbooleanReturnstrueiff that Object is aComparatorwhose ordering is known to be equivalent to mine.static BooleanComparatorGets a BooleanComparator instance that sortsfalsevalues beforetruevalues.static BooleanComparatorGets a BooleanComparator instance that sortstruevalues beforefalsevalues.inthashCode()Implement a hash code for this comparator that is consistent withequals.booleanReturnstrueiff I sorttruevalues beforefalsevalues.Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparatorreversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
- 
Constructor Details- 
BooleanComparatorpublic BooleanComparator()Creates aBooleanComparatorthat sortsfalsevalues beforetruevalues.Equivalent to BooleanComparator(false).Please use the static factory instead whenever possible. 
- 
BooleanComparatorCreates aBooleanComparatorthat sorts<em>trueFirst</em>values before!<em>trueFirst</em>values.Please use the static factories instead whenever possible. - Parameters:
- trueFirst- when- true, sort- trueboolean values before- false
 
 
- 
- 
Method Details- 
booleanComparatorReturns a BooleanComparator instance that sorts<em>trueFirst</em>values before!<em>trueFirst</em>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- Booleans before- false
- Returns:
- a singleton BooleanComparator instance
- Since:
- 4.0
 
- 
getFalseFirstComparatorGets a BooleanComparator instance that sortsfalsevalues beforetruevalues.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
 
- 
getTrueFirstComparatorGets a BooleanComparator instance that sortstruevalues beforefalsevalues.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
 
- 
compare- Specified by:
- comparein interface- Comparator<Boolean>
- 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
 
- 
equalsReturnstrueiff that Object is aComparatorwhose ordering is known to be equivalent to mine.This implementation returns trueiff<em>that</em>is aBooleanComparatorwhose value ofsortsTrueFirst()is equal to mine.- Specified by:
- equalsin interface- Comparator<Boolean>
- Overrides:
- equalsin class- Object
- Parameters:
- object- the object to compare to
- Returns:
- true if equal
 
- 
hashCode
- 
sortsTrueFirstReturnstrueiff I sorttruevalues beforefalsevalues. In other words, returnstrueiffcompare(Boolean.FALSE,Boolean.TRUE)returns a positive value.- Returns:
- the trueFirst flag
 
 
-