mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
PropertyComparator增加compareSelf构造重载
This commit is contained in:
@@ -6,9 +6,8 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
* Bean属性排序器<br>
|
||||
* 支持读取Bean多层次下的属性
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
* @param <T> 被比较的Bean
|
||||
* @author Looly
|
||||
*/
|
||||
public class PropertyComparator<T> extends FuncComparator<T> {
|
||||
private static final long serialVersionUID = 9157326766723846313L;
|
||||
@@ -25,10 +24,23 @@ public class PropertyComparator<T> extends FuncComparator<T> {
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param property 属性名
|
||||
* @param property 属性名
|
||||
* @param isNullGreater null值是否排在后(从小到大排序)
|
||||
*/
|
||||
public PropertyComparator(String property, boolean isNullGreater) {
|
||||
super(isNullGreater, (bean)-> BeanUtil.getProperty(bean, property));
|
||||
this(property, true, isNullGreater);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param property 属性名
|
||||
* @param compareSelf 在字段值相同情况下,是否比较对象本身。
|
||||
* 如果此项为{@code false},字段值比较后为0会导致对象被认为相同,可能导致被去重。
|
||||
* @param isNullGreater null值是否排在后(从小到大排序)
|
||||
* @since 5.8.28
|
||||
*/
|
||||
public PropertyComparator(String property, final boolean compareSelf, boolean isNullGreater) {
|
||||
super(isNullGreater, compareSelf, (bean) -> BeanUtil.getProperty(bean, property));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user