Package org.springframework.util.comparator

# Class BooleanComparator

java.lang.Object
org.springframework.util.comparator.BooleanComparator

All Implemented Interfaces:
  `Serializable`, `Comparator<Boolean>`

public class BooleanComparator extends Object implements Comparator<Boolean>, Serializable
A `Comparator` for `Boolean` objects that can sort either `true` or `false` first.

Since:
  1.2.2
Author:
  Keith Donald, Eugene Rabii
See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final BooleanComparator`
`TRUE_HIGH`
A shared default instance of this comparator, treating `true` higher than `false`.
`static final BooleanComparator`
`TRUE_LOW`
A shared default instance of this comparator, treating `true` lower than `false`.

## Constructor Summary

Constructors
Constructor
Description
`BooleanComparator(boolean trueLow)`
Create a BooleanComparator that sorts boolean values based on the provided flag.

## Method Summary

Modifier and Type
Method
Description
`int`
`compare(Boolean left, Boolean right)`
`boolean`
`equals(Object other)`
`int`
`hashCode()`
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Comparator

`reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

## Field Details

### TRUE_LOW

public static final BooleanComparator TRUE_LOW
A shared default instance of this comparator, treating `true` lower than `false`.

### TRUE_HIGH

public static final BooleanComparator TRUE_HIGH
A shared default instance of this comparator, treating `true` higher than `false`.

## Constructor Details

### BooleanComparator

public BooleanComparator(boolean trueLow)
Create a BooleanComparator that sorts boolean values based on the provided flag.

Alternatively, you can use the default shared instances: `BooleanComparator.TRUE_LOW` and `BooleanComparator.TRUE_HIGH`.

Parameters:
  `trueLow` - whether to treat true as lower or higher than false
See Also:
  - `TRUE_LOW`
  - `TRUE_HIGH`

## Method Details

### compare

public int compare(Boolean left, Boolean right)

Specified by:
  `compare` in interface `Comparator<Boolean>`

### equals

public boolean equals(@Nullable Object other)

Specified by:
  `equals` in interface `Comparator<Boolean>`
Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`