类 NullSafeComparator<T>
- java.lang.Object
- org.springframework.util.comparator.NullSafeComparator<T>
- 所有已实现的接口:
Comparator<T>
public class NullSafeComparator<T> extends Object implements 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.- 从以下版本开始:
- 1.2.2
- 作者:
- Keith Donald, Juergen Hoeller
- 另请参阅:
Comparable
字段概要
字段 修饰符和类型 字段 说明 static NullSafeComparator
NULLS_HIGH
A shared default instance of this comparator, treating nulls higher than non-null objects.static NullSafeComparator
NULLS_LOW
A shared default instance of this comparator, treating nulls lower than non-null objects.
构造器概要
构造器 构造器 说明 NullSafeComparator(Comparator<T> comparator, boolean nullsLow)
Create a NullSafeComparator that sortsnull
based on the provided flag, decorating the given Comparator.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 int
compare(T o1, T o2)
boolean
equals(Object obj)
int
hashCode()
String
toString()
从接口继承的方法 java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
字段详细资料
NULLS_LOW
public static final NullSafeComparator NULLS_LOW
A shared default instance of this comparator, treating nulls lower than non-null objects.
NULLS_HIGH
public static final NullSafeComparator NULLS_HIGH
A shared default instance of this comparator, treating nulls higher than non-null objects.
构造器详细资料
NullSafeComparator
public NullSafeComparator(Comparator<T> comparator, boolean nullsLow)
Create a NullSafeComparator that sortsnull
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.
- 参数:
comparator
- the comparator to use when comparing two non-null objectsnullsLow
- whether to treat nulls lower or higher than non-null objects