mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
feat(5.4.1): 增加TreeConvert
增加TreeConvert,方便的构建树形数据结构
This commit is contained in:
parent
a92d442c26
commit
145b8cc6ca
@ -11,7 +11,8 @@ import java.util.List;
|
||||
* 树转换测试
|
||||
*/
|
||||
public class TreeConvertTest {
|
||||
|
||||
//
|
||||
private static final String ROOT = "0";
|
||||
// 子父级测试数据
|
||||
private List<Dept> parentChildMaterials = Arrays.asList(
|
||||
new Dept("00000001", "0", "xxx公司"),
|
||||
@ -38,12 +39,22 @@ public class TreeConvertTest {
|
||||
@Test
|
||||
public void testParentChild() {
|
||||
List<Dept> tree = TreeConvert.convert(parentChildMaterials, Dept.class,
|
||||
root -> "0".equals(root.getParentId()),
|
||||
// TreeConvertTest::rootDecide
|
||||
root -> ROOT.equals(root.getParentId()),
|
||||
// TreeConvertTest::leafDecide
|
||||
(root, leaf) -> leaf.getParentId().equals(root.getDeptId())
|
||||
);
|
||||
Assert.assertEquals("0", tree.get(0).getParentId());
|
||||
Assert.assertEquals(ROOT, tree.get(0).getParentId());
|
||||
}
|
||||
|
||||
// 静态抽象
|
||||
public static boolean rootDecide(Dept root) {
|
||||
return ROOT.equals(root.getDeptId());
|
||||
}
|
||||
// 静态抽象
|
||||
public static boolean leafDecide(Dept root, Dept leaf) {
|
||||
return leaf.getParentId().equals(root.getDeptId());
|
||||
}
|
||||
// 排序号测试
|
||||
@Test
|
||||
public void testSortNo() {
|
||||
@ -54,7 +65,7 @@ public class TreeConvertTest {
|
||||
!leaf.getSortNo().equals(root.getSortNo()) &&
|
||||
leaf.getSortNo().length() - root.getSortNo().length() == 2
|
||||
);
|
||||
Assert.assertEquals("0", tree.get(0).getParentId());
|
||||
Assert.assertEquals("00", tree.get(0).getSortNo());
|
||||
}
|
||||
|
||||
// 测试实体类
|
||||
|
Loading…
x
Reference in New Issue
Block a user