public class TreeUtils extends Object
| 构造器和说明 |
|---|
TreeUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T,K> List<T> |
getListPassingBy(Collection<T> nodeList,
K rootKey,
@NotNull java.util.function.Function<T,K> getKey,
@NotNull java.util.function.Function<T,K> getParentKey)
根据上下级关系遍历沿途的节点(包含root节点)
|
static <T,K> T |
list2Tree(Collection<T> nodeList,
K rootKey,
@NotNull java.util.function.Function<T,K> getKey,
@NotNull java.util.function.Function<T,K> getParentKey,
@NotNull java.util.function.BiConsumer<T,List<T>> setChildList)
单列集合转树形结构
|
static List<cn.hutool.core.lang.tree.Tree<Object>> |
tree(List<TreePo> list,
String rootId)
将对象数据转树操作
|
static <T> List<T> |
tree2List(T root,
@NotNull java.util.function.Function<T,List<T>> getChildList)
树形结构转单列集合(会进行去重)
|
public static List<cn.hutool.core.lang.tree.Tree<Object>> tree(List<TreePo> list, String rootId)
list - 树节点集合rootId - 根节点idpublic static <T,K> T list2Tree(Collection<T> nodeList, @NotNull K rootKey, @NotNull @NotNull java.util.function.Function<T,K> getKey, @NotNull @NotNull java.util.function.Function<T,K> getParentKey, @NotNull @NotNull java.util.function.BiConsumer<T,List<T>> setChildList)
T - 节点类型K - key类型nodeList - 节点集合(需要有父级节点的标识)rootKey - 根节点标识getKey - 获取当前节点标识getParentKey - 获取父级节点标识setChildList - 记录子节点public static <T> List<T> tree2List(T root, @NotNull @NotNull java.util.function.Function<T,List<T>> getChildList)
T - 节点类型root - 根节点getChildList - 获取子节点集合public static <T,K> List<T> getListPassingBy(Collection<T> nodeList, @NotNull K rootKey, @NotNull @NotNull java.util.function.Function<T,K> getKey, @NotNull @NotNull java.util.function.Function<T,K> getParentKey)
T - 节点类型K - key类型nodeList - 节点集合(需要有父级节点的标识)rootKey - 根节点数据getKey - 获取当前节点标识getParentKey - 获取父级节点标识Copyright © 2022 jvs. All rights reserved.