当前位置:网站首页>树形结构构造示例代码
树形结构构造示例代码
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;
}边栏推荐
猜你喜欢
随机推荐
C# Barrier class
Li Mu hands-on learning deep learning V2-bert and code implementation
Helm基础知识
X 2 Earn必须依靠旁氏启动?GameFi的出路在哪?(下)
js如何获取浏览器缩放比例
Bee 事务注解 @Tran 使用实例
封装和包、访问修饰权限
[C题目]力扣1. 两数之和
一款免费的容器安全 SaaS 平台使用记录
Bena's life cycle
【21天学习挑战赛】冒泡排序与插入排序
C语言中变量在内存中的保存与访问
开关、电机、断路器、电热偶、电表接线图大全
汉源高科千兆4光4电工业级网管型智能环网冗余以太网交换机防浪涌防雷导轨式安装
Digital twins help visualize the construction of smart cities
iframe------------frame-
A brief discussion on the transformation of .NET legacy applications
C# Monitor类
正则表达式
[C题目]力扣142. 环形链表 II







