yangys
2024-04-02 1a77b1a7c072b136925d6d73c4d8f017ca016e3a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.qianwen.core.tool.node.basic;
 
import java.util.ArrayList;
import java.util.List;
 
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/node/basic/TreeUtil.class */
public final class TreeUtil {
    private TreeUtil() {
        throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
    }
 
    public static <T extends TreeNode> List<T> build(List<T> treeNodes, Object root) {
        List<T> trees = new ArrayList<>();
        for (T treeNode : treeNodes) {
            if (root.equals(treeNode.getParentId())) {
                trees.add(treeNode);
            }
            for (T it : treeNodes) {
                if (it.getParentId().equals(treeNode.getId())) {
                    if (treeNode.getChildren() == null) {
                        treeNode.setChildren(new ArrayList());
                    }
                    treeNode.add(it);
                }
            }
        }
        return trees;
    }
 
    public static <T extends TreeNode> List<T> buildByRecursive(List<T> treeNodes, Object root) {
        ArrayList arrayList = new ArrayList();
        for (T treeNode : treeNodes) {
            if (root.equals(treeNode.getParentId())) {
                arrayList.add(findChildren(treeNode, treeNodes));
            }
        }
        return arrayList;
    }
 
    /* JADX WARN: Multi-variable type inference failed */
    public static <T extends TreeNode> T findChildren(T treeNode, List<T> treeNodes) {
        for (T it : treeNodes) {
            if (treeNode.getId().equals(it.getParentId())) {
                if (treeNode.getChildren() == null) {
                    treeNode.setChildren(new ArrayList());
                }
                treeNode.add(findChildren(it, treeNodes));
            }
        }
        return treeNode;
    }
}