T
- 被比较的对象public class NullComparator<T> extends Object implements Comparator<T>, Serializable
null
友好的比较器包装,如果nullGreater,则null
> non-null,否则反之。null
,则为相等,返回0。null
,则使用传入的比较器排序。null
,则看被比较的两个对象是否都实现了Comparable
实现则调用Comparable.compareTo(Object)
。
如果两者至少一个未实现,则视为所有元素相等。Modifier and Type | Field and Description |
---|---|
protected Comparator<T> |
comparator |
protected boolean |
nullGreater |
Constructor and Description |
---|
NullComparator(boolean nullGreater,
Comparator<? super T> comparator)
构造
|
Modifier and Type | Method and Description |
---|---|
int |
compare(T a,
T b) |
protected int |
doCompare(T a,
T b)
不检查
null 的比较方法用户可自行重写此方法自定义比较方式 |
Comparator<T> |
thenComparing(Comparator<? super T> other) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
protected final boolean nullGreater
protected final Comparator<T> comparator
public NullComparator(boolean nullGreater, Comparator<? super T> comparator)
nullGreater
- 是否null
最大,排在最后comparator
- 实际比较器public int compare(T a, T b)
compare
in interface Comparator<T>
public Comparator<T> thenComparing(Comparator<? super T> other)
thenComparing
in interface Comparator<T>
Copyright © 2024. All rights reserved.