Package org.aoju.bus.core.compare
Class NullCompare<T>
java.lang.Object
org.aoju.bus.core.compare.NullCompare<T>
- Type Parameters:
T- 被比较的对象
- All Implemented Interfaces:
Serializable,Comparator<T>
- Direct Known Subclasses:
FuncCompare
null友好的比较器包装,如果nullGreater,则null > non-null,否则反之 如果二者皆为null,则为相等,返回0
如果二者都非null,则使用传入的比较器排序
传入比较器为null,则看被比较的两个对象是否都实现了Comparable实现则调用Comparable.compareTo(Object) 如果两者至少一个未实现,则视为所有元素相等- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintprotected int不检查null的比较方法 用户可自行重写此方法自定义比较方式reversed()thenComparing(Comparator<? super T> other) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
nullGreater
protected final boolean nullGreater -
comparator
-
-
Constructor Details
-
NullCompare
构造- Parameters:
nullGreater- 是否null最大,排在最后comparator- 实际比较器
-
-
Method Details
-
compare
- Specified by:
comparein interfaceComparator<T>
-
thenComparing
- Specified by:
thenComparingin interfaceComparator<T>
-
reversed
- Specified by:
reversedin interfaceComparator<T>
-
doCompare
-