zoukankan      html  css  js  c++  java
  • tree 树状构建

    /*package ch.util;
    
    import com.trm.model.func.FunctionTree;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    
    public class FunctionUtil {
        public static List<FunctionTree> createTreeMenus(List<FunctionTree> trees) {
            List<FunctionTree> treeMenus = null;
            if (null != trees && !trees.isEmpty()) {
                // 创建根节点
                FunctionTree root = new FunctionTree();
    
                // 组装Map数据
                Map<String, FunctionTree> dataMap = new HashMap<String, FunctionTree>();
                for (FunctionTree tree : trees) {
                    dataMap.put(tree.getServiceCode(), tree);
                }
    
                // 组装树形结构
                Set<Map.Entry<String, FunctionTree>> entrySet = dataMap.entrySet();
                for (Map.Entry<String, FunctionTree> entry : entrySet) {
                    FunctionTree tree = entry.getValue();
                    if (null == tree.getParentFlag() || "0".equals(tree.getParentFlag())) {
                        root.getChildren().add(tree);
                    } else {
                        dataMap.get(tree.getParentFlag()).getChildren().add(tree);
                    }
                }
                root.sortChildren();
                treeMenus = root.getChildren();
            }
            return treeMenus;
        }
    }
    */
  • 相关阅读:
    bind函数
    尾置返回类型
    lambda表达式
    C++谓词
    capacity和size
    容器操作可能会使迭代器失效
    特殊的forward_list操作
    向顺序容器添加元素
    swap与assign
    迭代器
  • 原文地址:https://www.cnblogs.com/chengyangyang/p/10487335.html
Copyright © 2011-2022 走看看