Class TreeUtil

java.lang.Object
top.tangyh.basic.utils.TreeUtil

public final class TreeUtil extends Object
list列表 转换成tree列表 Created by Ace on 2017/6/12.
Author:
zuihou
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    TreeUtil.FsNodeParser<T extends cn.hutool.core.lang.tree.TreeNode<E>,E>
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Long
    默认的父id
    static final String
    默认的树节点 分隔符
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends cn.hutool.core.lang.tree.TreeNode<Long>>
    List<cn.hutool.core.lang.tree.Tree<Long>>
    build(List<T> list)
    构建 根节点存储null,节点ID类型为Long 的树
    static <T extends cn.hutool.core.lang.tree.TreeNode<Long>>
    List<cn.hutool.core.lang.tree.Tree<Long>>
    build(List<T> list, cn.hutool.core.lang.tree.parser.NodeParser<T,Long> nodeParser)
    构建 根节点存储 rootId,节点ID类型为Long 的树
    static <T extends cn.hutool.core.lang.tree.TreeNode<Long>>
    List<cn.hutool.core.lang.tree.Tree<Long>>
    build(List<T> list, cn.hutool.core.lang.tree.TreeNodeConfig treeNodeConfig)
    构建 根节点存储null,节点ID类型为Long 的树
    static <T extends cn.hutool.core.lang.tree.TreeNode<E>, E>
    List<cn.hutool.core.lang.tree.Tree<E>>
    build(List<T> list, E rootId)
    构建 根节点存储 rootId,节点ID类型为Long 的树
    static <T extends cn.hutool.core.lang.tree.TreeNode<E>, E>
    List<cn.hutool.core.lang.tree.Tree<E>>
    build(List<T> list, E rootId, cn.hutool.core.lang.tree.TreeNodeConfig treeNodeConfig)
    构建 根节点存储 rootId,节点ID类型为Long 的树
    static <E extends TreeEntity<E, ? extends Serializable>>
    List<E>
    buildTree(Collection<E> treeList)
    构建Tree结构
    static String
     
    static Long
    getTopNodeId(String treePath)
     
    static String
    getTreePath(String parentTreePath, Long parentId)
     
    static boolean
    判断id是否为根节点

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TREE_SPLIT

      public static final String TREE_SPLIT
      默认的树节点 分隔符
      See Also:
    • DEF_PARENT_ID

      public static final Long DEF_PARENT_ID
      默认的父id
  • Method Details

    • getTreePath

      public static String getTreePath(String parentTreePath, Long parentId)
    • buildTreePath

      public static String buildTreePath(Long id)
    • isRoot

      public static boolean isRoot(Long id)
      判断id是否为根节点
      Parameters:
      id -
      Returns:
    • buildTree

      public static <E extends TreeEntity<E, ? extends Serializable>> List<E> buildTree(Collection<E> treeList)
      构建Tree结构
      Parameters:
      treeList - 待转换的集合
      Returns:
      树结构
    • getTopNodeId

      public static Long getTopNodeId(String treePath)
    • build

      public static <T extends cn.hutool.core.lang.tree.TreeNode<Long>> List<cn.hutool.core.lang.tree.Tree<Long>> build(List<T> list)
      构建 根节点存储null,节点ID类型为Long 的树
      Type Parameters:
      T - 转换的实体 为数据源里的对象类型
      Parameters:
      list - 源数据集合; 必须继承TreeNode
      Returns:
      List
    • build

      public static <T extends cn.hutool.core.lang.tree.TreeNode<Long>> List<cn.hutool.core.lang.tree.Tree<Long>> build(List<T> list, cn.hutool.core.lang.tree.TreeNodeConfig treeNodeConfig)
      构建 根节点存储null,节点ID类型为Long 的树
      Type Parameters:
      T - 转换的实体 为数据源里的对象类型
      Parameters:
      list - 源数据集合; 必须继承TreeNode
      treeNodeConfig - 配置
      Returns:
      List
    • build

      public static <T extends cn.hutool.core.lang.tree.TreeNode<E>, E> List<cn.hutool.core.lang.tree.Tree<E>> build(List<T> list, E rootId)
      构建 根节点存储 rootId,节点ID类型为Long 的树
      Type Parameters:
      T - 转换的实体 为数据源里的对象类型
      E - ID类型
      Parameters:
      list - 源数据集合; 必须继承TreeNode
      rootId - 最顶层父id值 一般为 0 或 null 之类
      Returns:
      List
    • build

      public static <T extends cn.hutool.core.lang.tree.TreeNode<E>, E> List<cn.hutool.core.lang.tree.Tree<E>> build(List<T> list, E rootId, cn.hutool.core.lang.tree.TreeNodeConfig treeNodeConfig)
      构建 根节点存储 rootId,节点ID类型为Long 的树
      Type Parameters:
      T - 转换的实体 为数据源里的对象类型
      E - ID类型
      Parameters:
      list - 源数据集合; 必须继承TreeNode
      rootId - 最顶层父id值 一般为 0 或 null 之类
      treeNodeConfig - 配置
      Returns:
      List
    • build

      public static <T extends cn.hutool.core.lang.tree.TreeNode<Long>> List<cn.hutool.core.lang.tree.Tree<Long>> build(List<T> list, cn.hutool.core.lang.tree.parser.NodeParser<T,Long> nodeParser)
      构建 根节点存储 rootId,节点ID类型为Long 的树
      Type Parameters:
      T - 转换的实体 为数据源里的对象类型
      Parameters:
      list - 源数据集合; 必须继承TreeNode
      nodeParser - 解析器
      Returns:
      List