public class

NullSafeComparator

extends Object
implements Comparator<T>
java.lang.Object
   ↳ org.springframework.util.comparator.NullSafeComparator<T>

Class Overview

A Comparator that will safely compare nulls to be lower or higher than other objects. Can decorate a given Comparator or work on Comparables.

See Also

Summary

Fields
public static final NullSafeComparator NULLS_HIGH A shared default instance of this comparator, treating nulls higher than non-null objects.
public static final NullSafeComparator NULLS_LOW A shared default instance of this comparator, treating nulls lower than non-null objects.
Public Constructors
NullSafeComparator(Comparator<T> comparator, boolean nullsLow)
Create a NullSafeComparator that sorts null based on the provided flag, decorating the given Comparator.
Public Methods
int compare(T o1, T o2)
boolean equals(Object obj)
int hashCode()
String toString()
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Comparator

Fields

public static final NullSafeComparator NULLS_HIGH

Also: SpringCore

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

public static final NullSafeComparator NULLS_LOW

Also: SpringCore

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

Public Constructors

public NullSafeComparator (Comparator<T> comparator, boolean nullsLow)

Also: SpringCore

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

Public Methods

public int compare (T o1, T o2)

Also: SpringCore

public boolean equals (Object obj)

public int hashCode ()

public String toString ()