当前位置:网站首页>树形结构构造示例代码
树形结构构造示例代码
2022-08-02 20:36:00 【jsxztshaohaibo】
/**
* 构造树形结构
* @param resourceList
* @return
*/
public List<RResource> buildResourceTreeInfo(List<RResource> resourceList) {
List<RResource> result = new ArrayList<>();
Map<String,RResource> record = new HashMap<>();
for (RResource resource : resourceList) {
if (RResource.TOP_LEVEL_NODE.equals(resource.getParentId())) {//TOP_LEVEL_NODE=0
resource.setChildren(new ArrayList<>());
result.add(resource);
}
record.put(resource.getId(), resource);
}
for (RResource resource : resourceList) {
if (StringUtils.isNotBlank(resource.getParentId()) &&!RResource.TOP_LEVEL_NODE.equals(resource.getParentId())) {//TOP_LEVEL_NODE=0
RResource parent = record.get(resource.getParentId());
if (parent != null) {
parent.getChildren().add(resource);
}
}
}
return result;
}边栏推荐
猜你喜欢

Bee 事务注解 @Tran 使用实例

callback prototype __proto__

2018HBCPC个人题解

The software testing process specification is what?Specific what to do?

Digital twins help visualize the construction of smart cities

模糊查询like用法实例(Bee)

美国爱荷华州立大学| Improving Distantly Supervised Relation Extraction by Natural Language Inference(通过自然语言推理改进远程监督关系提取)

如何成为一名正义黑客?你应该学习什么?

【模型压缩】实例分析量化原理

OP analysis and design
随机推荐
解道8-编程技术5
.NET performance optimization - you should set initial size for collection types
传感器工作原理
Common tools and test methods for interface testing (Introduction)
C# Monitor class
Geoip2 - golang golang source code analysis
Vscode快速入门、 插件安装、插件位置、修改vscode默认引用插件的路径、在命令行总配置code、快捷键
DataGrip 安装教程 详细版
[C题目]力扣138. 复制带随机指针的链表
广东省数字经济发展指引 1.0之建成数据安全保障体系
快速构建电脑软件系统 、超好用经典的网页推荐汇总
Wiring diagrams of switches, motors, circuit breakers, thermocouples, and meters
什么是幂等
【流媒体】推流与拉流简介
人尽皆知的云原生,到底是大势所趋还是过度炒作?
性能测试 - 理论
并发与并行
OP analysis and design
数字孪生助力智慧城市可视化建设
X 2 Earn必须依靠旁氏启动?GameFi的出路在哪?(下)