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
package com.walker.common;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
 
/**
 * 通用上下级关系对象
 *
 * @author 时克英
 */
public class LinkedItem<I, P, C> {
    // 当前节点
    private I item;
    // 父节点
    private P parent;
    // 子节点
    private List<C> children;
 
    /**
     * 默认构造函数
     */
    public LinkedItem() {
    }
 
    /**
     * 根据当前节点构造对象
     *
     * @param item 当前对象
     */
    public LinkedItem(I item) {
        this.item = item;
    }
 
    /**
     * 根据当前节点和父节点构造对象
     *
     * @param item   当前节点
     * @param parent 父节点
     */
    public LinkedItem(I item, P parent) {
        this.item = item;
        this.parent = parent;
    }
 
    /**
     * 根据当前节点、父节点、子节点信息构造对象
     *
     * @param item     当前节点
     * @param parent   父节点对象
     * @param children 子节点信息
     */
    public LinkedItem(I item, P parent, List<C> children) {
        this.item = item;
        this.parent = parent;
        this.children = children;
    }
 
    /**
     * 增加子节点信息,
     *
     * @param child 子节点
     */
    public void addChild(C child) {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        this.children.add(child);
    }
 
    /**
     * 将所有的childs增加到当前节点
     *
     * @param childs 子节点集合
     */
    public void addChildren(Collection<C> childs) {
        if (this.children == null && (childs != null && childs.size() > 0)) {
            this.children = new ArrayList<>();
            this.children.addAll(childs);
        }
    }
 
    public I getItem() {
        return item;
    }
 
    public void setItem(I item) {
        this.item = item;
    }
 
    public P getParent() {
        return parent;
    }
 
    public void setParent(P parent) {
        this.parent = parent;
    }
 
    public List<C> getChildren() {
        return children;
    }
 
    public void setChildren(List<C> children) {
        this.children = children;
    }
}