cn.woodwhales.common.business.chinese.ChineseDataTool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of woodwhales-common Show documentation
Show all versions of woodwhales-common Show documentation
https://github.com/woodwhales
package cn.woodwhales.common.business.chinese;
import com.ibm.icu.text.Collator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import static java.util.Collections.emptyList;
import static org.apache.commons.collections4.CollectionUtils.isEmpty;
/**
* @author woodwhales
* 2020-12-07 22:19
*/
public class ChineseDataTool {
public static final Collator collator = com.ibm.icu.text.Collator.getInstance(com.ibm.icu.util.ULocale.SIMPLIFIED_CHINESE);
/**
* 根据 dataList 进行中文字段排序
* @param dataList 原始数据
* @param stringFunction 中文排序接口
* @param 数据集合泛型
* @return 已排序的结果集
*/
public static List sortedList(List dataList, Function stringFunction) {
if(isEmpty(dataList)) {
return emptyList();
}
List> chineseDataContainerList = ChineseDataContainer.build(dataList, stringFunction);
return chineseDataContainerList.stream()
.sorted(ChineseDataContainer::compare)
.map(ChineseDataContainer::getData)
.collect(Collectors.toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy