Package org.springframework.util.comparator

# Class NullSafeComparator<T>

java.lang.Object
org.springframework.util.comparator.NullSafeComparator<T>

Type Parameters:
  `T` - the type of objects that may be compared by this comparator

All Implemented Interfaces:
  `Comparator<T>`

@Deprecated(since="6.1") public class NullSafeComparator<T> extends Object implements Comparator<T>
Deprecated.
as of 6.1 in favor of `Comparator.nullsLast(java.util.Comparator<? super T>)` and `Comparator.nullsFirst(java.util.Comparator<? super T>)`
A Comparator that will safely compare nulls to be lower or higher than other objects. Can decorate a given Comparator or work on Comparables.

Since:
  1.2.2
Author:
  Keith Donald, Juergen Hoeller
See Also:
  - `Comparable`
  - `Comparators`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final NullSafeComparator`
`NULLS_HIGH`
Deprecated.
A shared default instance of this comparator, treating nulls higher than non-null objects.
`static final NullSafeComparator`
`NULLS_LOW`
Deprecated.
A shared default instance of this comparator, treating nulls lower than non-null objects.

## Constructor Summary

Constructors
Constructor
Description
`NullSafeComparator(Comparator<T> comparator, boolean nullsLow)`
Deprecated.
Create a NullSafeComparator that sorts `null` based on the provided flag, decorating the given Comparator.

## Method Summary

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

### 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

### NULLS_LOW

public static final NullSafeComparator NULLS_LOW
Deprecated.
A shared default instance of this comparator, treating nulls lower than non-null objects.

See Also:
  - `Comparators.nullsLow()`

### NULLS_HIGH

public static final NullSafeComparator NULLS_HIGH
Deprecated.
A shared default instance of this comparator, treating nulls higher than non-null objects.

See Also:
  - `Comparators.nullsHigh()`

## Constructor Details

### NullSafeComparator

public NullSafeComparator(Comparator<T> comparator, boolean nullsLow)
Deprecated.
Create a NullSafeComparator that sorts `null` based on the provided flag, decorating the given Comparator.

When comparing two non-null objects, the specified Comparator will be used. The given underlying Comparator must be able to handle the elements that this Comparator will be applied to.

Parameters:
  `comparator` - the comparator to use when comparing two non-null objects
  `nullsLow` - whether to treat nulls lower or higher than non-null objects

## Method Details

### compare

public int compare(@Nullable T left, @Nullable T right)
Deprecated.

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

### equals

public boolean equals(@Nullable Object other)
Deprecated.

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

### hashCode

public int hashCode()
Deprecated.

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()
Deprecated.

Overrides:
  `toString` in class `Object`