mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
feat: comparator for chinese pinyin
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package cn.hutool.core.comparator;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CompareUtilTest {
|
||||
|
||||
@Test
|
||||
@@ -13,4 +18,21 @@ public class CompareUtilTest {
|
||||
compare = CompareUtil.compare(null, "a", false);
|
||||
Assert.assertTrue(compare < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comparingPinyin() {
|
||||
List<String> list = new ArrayList<>();
|
||||
Collections.addAll(list, "成都", "北京", "上海", "深圳");
|
||||
|
||||
List<String> ascendingOrderResult = ListUtil.of("北京", "成都", "上海", "深圳");
|
||||
List<String> descendingOrderResult = ListUtil.of("深圳", "上海", "成都", "北京");
|
||||
|
||||
// 正序
|
||||
list.sort(CompareUtil.comparingPinyin(e -> e));
|
||||
Assert.assertEquals(list, ascendingOrderResult);
|
||||
|
||||
// 反序
|
||||
list.sort(CompareUtil.comparingPinyin(e -> e, true));
|
||||
Assert.assertEquals(list, descendingOrderResult);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user