mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
a55aed6a5a
commit
794a67bd1a
@ -231,9 +231,14 @@ public class TreeUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MapTree<T> parent = node.getParent();
|
MapTree<T> parent = node.getParent();
|
||||||
|
CharSequence name;
|
||||||
while (null != parent) {
|
while (null != parent) {
|
||||||
result.add(parent.getName());
|
name = parent.getName();
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
|
if(null != name || null != parent){
|
||||||
|
// issue#I795IN,根节点的null不加入
|
||||||
|
result.add(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
47
hutool-core/src/test/java/org/dromara/hutool/core/tree/IssueI795INTest.java
Executable file
47
hutool-core/src/test/java/org/dromara/hutool/core/tree/IssueI795INTest.java
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||||
|
* Hutool is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.dromara.hutool.core.tree;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class IssueI795INTest {
|
||||||
|
|
||||||
|
static List<TreeNode<Long>> all_menu=new ArrayList<>();
|
||||||
|
static {
|
||||||
|
/*
|
||||||
|
* root
|
||||||
|
* /module-A
|
||||||
|
* /module-A-menu-1
|
||||||
|
* /module-B
|
||||||
|
* /module-B-menu-1
|
||||||
|
* /module-B-menu-2
|
||||||
|
*/
|
||||||
|
all_menu.add(new TreeNode<>(1L, 0L, "root", 0L));
|
||||||
|
all_menu.add(new TreeNode<>(2L,1L,"module-A",0L));
|
||||||
|
all_menu.add(new TreeNode<>(3L,1L,"module-B",0L));
|
||||||
|
all_menu.add(new TreeNode<>(4L,2L,"module-A-menu-1",0L));
|
||||||
|
all_menu.add(new TreeNode<>(5L,3L,"module-B-menu-1",0L));
|
||||||
|
all_menu.add(new TreeNode<>(6L,3L,"module-B-menu-2",0L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getParentsNameTest() {
|
||||||
|
final MapTree<Long> tree = TreeUtil.buildSingle(all_menu, 0L);
|
||||||
|
final MapTree<Long> chid = tree.getChildren().get(0).getChildren().get(0).getChildren().get(0);
|
||||||
|
Assertions.assertEquals("[module-A-menu-1, module-A, root]", chid.getParentsName(true).toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user