shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.walker.infrastructure.tree;
 
import java.util.ArrayList;
import java.util.List;
 
public class TreeNode implements Comparable<TreeNode> {
 
    private long id;
    private String label;
    private long parentId = 0;
    private List<TreeNode> children = null;
    private Object source = null;
 
    public String getCode() {
        return code;
    }
 
    public void setCode(String code) {
        this.code = code;
    }
 
    // 2023-07-13
    private String code;
 
    public TreeNode(long id, String label, List<TreeNode> children, long parentId){
        this.id = id;
        this.label = label;
        this.children = children;
        this.parentId = parentId;
    }
    public TreeNode(long id, String label, List<TreeNode> children, long parentId, String code){
        this.id = id;
        this.label = label;
        this.children = children;
        this.parentId = parentId;
        this.code = code;
    }
 
    public void addChild(TreeNode node) {
        if(node != null){
            if(children == null){
                this.children = new ArrayList<>(8);
            }
            if(!this.children.contains(node)){
                this.children.add(node);
            }
        }
    }
 
    public Object getSource() {
        return source;
    }
 
    public void setSource(Object source) {
        this.source = source;
    }
 
    public long getId() {
        return id;
    }
 
    public void setId(long id) {
        this.id = id;
    }
 
    public String getLabel() {
        return label;
    }
 
    public void setLabel(String label) {
        this.label = label;
    }
 
    public long getParentId() {
        return parentId;
    }
 
    public void setParentId(long parentId) {
        this.parentId = parentId;
    }
 
    public List<TreeNode> getChildren() {
        return children;
    }
 
    public void setChildren(List<TreeNode> children) {
        this.children = children;
    }
 
    public void cloneProperties(TreeNode node) {
        this.id = node.getId();
        this.label = node.getLabel();
        this.source = node.getSource();
//        this.order = node.getOrder();
    }
 
    @Override
    public int hashCode(){
        return (int)this.id;
    }
 
    @Override
    public boolean equals(Object obj){
        if(obj == null){
            return false;
        }
        if(obj instanceof TreeNode){
            TreeNode treeNode = (TreeNode) obj;
            if(treeNode.id == this.id){
                return true;
            }
        }
        return false;
    }
 
    @Override
    public String toString(){
        return new StringBuilder("[id=").append(this.id)
                .append(", label=").append(this.label)
                .append(", children=").append(this.children)
                .append(", parentId=").append(this.parentId)
                .append("]").toString();
    }
 
    @Override
    public int compareTo(TreeNode o) {
        return 0;
    }
}