spring-framework / org.springframework.util.comparator / NullSafeComparator

NullSafeComparator

open class NullSafeComparator<T : Any> : Comparator<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.

Author
Keith Donald

Author
Juergen Hoeller

Since
1.2.2

See Also
Comparable

Constructors

<init>

NullSafeComparator(comparator: Comparator<T>, nullsLow: Boolean)

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.

Properties

NULLS_HIGH

static val NULLS_HIGH: NullSafeComparator<Any>

A shared default instance of this comparator, treating nulls higher than non-null objects.

NULLS_LOW

static val NULLS_LOW: NullSafeComparator<Any>

A shared default instance of this comparator, treating nulls lower than non-null objects.

Functions

compare

open fun compare(o1: T, o2: T): Int

equals

open fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String