package com.izouma.awesomeadmin.util;

import com.izouma.awesomeadmin.dto.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class TreeUtils {
    public static void buildTree(List<TreeNode> trees, List<TreeNode> allNodes) {
        for (TreeNode treeNode : allNodes) {
            if ("0".equals(treeNode.getParentId())) {
                trees.add(treeNode);
            }

            for (TreeNode it : allNodes) {
                if (it.getParentId().equals(treeNode.getId())) {
                    if (treeNode.getChildren() == null) {
                        treeNode.setChildren(new ArrayList<>());
                    }
                    treeNode.getChildren().add(it);
                }
            }
        }
    }
}
