当前位置: 首页 > news >正文

kotlin list集合树

kotlin list集合树


记录一下

data class AreaSchemaManageDto(var id: Long? = null,var pid: Long? = null,var label: String? = null,var children: MutableList<AreaSchemaManageDto>? = null
) : Serializable {
}

逻辑

  fun getAll(): List<AreaSchemaManageDto> {val list: List<AreaSchemaManageDto> = transaction {AreaSchemaManageDao.all().map { it.toModelDto() }}//最终树val treeList: MutableList<AreaSchemaManageDto> = mutableListOf()//获取根节点val rootList = list.stream().filter { dto -> dto.pid == 0L }.collect(Collectors.toList())//寻找子节点rootList.forEach { treeList.add(findChildren(it, list)) }return treeList}/*** 寻找子节点*/private fun findChildren(tree: AreaSchemaManageDto, list: List<AreaSchemaManageDto>): AreaSchemaManageDto {list.stream().filter { node -> tree.id == node.pid }.collect(Collectors.toList()).forEach { node ->if (tree.children == null) {tree.children = mutableListOf()}tree.children!!.add(findChildren(node, list))}return tree}
http://www.lryc.cn/news/97922.html

相关文章:

  • 基于Autoencoder自编码的64QAM星座图整形调制解调通信系统性能matlab仿真
  • 【Spring】Spring 总览
  • 微软、OpenAI用上“数据永动机” 合成数据是晨曦还是暮光?
  • 简单认识Redis 数据库的高可用
  • 超级实用!,掌握这9个鲜为人知的CSS属性
  • 深圳国际新能源及智能网联汽车全产业博览会今年10月举办
  • 【具有非线性反馈的LTI系统识别】针对反馈非线性的LTI系统,提供非线性辨识方案(SimulinkMatlab代码实现)
  • Stable diffusion 和 Midjourney 怎么选?
  • c++网络编程
  • 【沁恒蓝牙mesh】数据收发接口与应用层模型传递
  • Java类关系之代理(代理模式)
  • java: 无法访问redis.clients.jedis.JedisPoolConfig
  • 基于java中学教务管理系统设计与实现
  • vscode设置java -Xmx最大堆内存
  • 组件开发系列--Apache Commons Chain
  • 60 # http 的基本概念
  • 云计算迎来中场战役,MaaS或将成为弯道超车“新赛点”
  • 最新基于Citespace、vosviewer、R语言的文献计量学可视化分析技术及全流程文献可视化SCI论文高效写作方法
  • Hive调优集锦(2)
  • 一文谈谈Git
  • 嵌入式数据库之SQLite
  • idea下tomcat运行乱码问题解决方法
  • 人工智能TensorFlow MNIST手写数字识别——实战篇
  • Vue 本地应用-计数器
  • 深入了解HTTP代理在网络爬虫与SEO实践中的角色
  • 使用docker搭建nacos
  • flask中的常用装饰器
  • SQL基础语法 | 增删改查、分组、排序、limit
  • QT: 用定时器完成闹钟的实现
  • Boyer-Moore 投票算法