1 |
| package net.sourceforge.pmd.dfa.report; |
2 |
| |
3 |
| import java.util.ArrayList; |
4 |
| |
5 |
| public abstract class AbstractReportNode { |
6 |
| private ArrayList childNodes = new ArrayList(); |
7 |
| private AbstractReportNode parentNode = null; |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| private int numberOfViolations; |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| public abstract boolean equalsNode(AbstractReportNode arg0); |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
0
| public AbstractReportNode getFirstChild() {
|
24 |
0
| if (this.isLeaf()) {
|
25 |
0
| return null;
|
26 |
| } |
27 |
0
| return (AbstractReportNode) this.childNodes.get(0);
|
28 |
| } |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
0
| public AbstractReportNode getNextSibling() {
|
34 |
0
| if (this.parentNode == null) {
|
35 |
0
| return null;
|
36 |
| } |
37 |
0
| int index = this.parentNode.getChildIndex(this);
|
38 |
0
| if (index < 0) {
|
39 |
0
| return null;
|
40 |
| } |
41 |
0
| if (index >= this.parentNode.childNodes.size() - 1) {
|
42 |
0
| return null;
|
43 |
| } |
44 |
0
| return (AbstractReportNode) this.parentNode.childNodes.get(index + 1);
|
45 |
| } |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
0
| private int getChildIndex(AbstractReportNode child) {
|
51 |
0
| for (int i = 0; i < this.childNodes.size(); i++) {
|
52 |
0
| if (this.childNodes.get(i).equals(child)) {
|
53 |
0
| return i;
|
54 |
| } |
55 |
| } |
56 |
0
| return -1;
|
57 |
| } |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
1092
| public void addFirst(AbstractReportNode child) {
|
63 |
1092
| this.childNodes.add(0, child);
|
64 |
1092
| child.parentNode = this;
|
65 |
| } |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
2651
| public void add(AbstractReportNode child) {
|
71 |
2651
| this.childNodes.add(child);
|
72 |
2651
| child.parentNode = this;
|
73 |
| } |
74 |
| |
75 |
0
| public void addNumberOfViolation(int number) {
|
76 |
0
| this.numberOfViolations += number;
|
77 |
| } |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
0
| public int getNumberOfViolations() {
|
83 |
0
| return numberOfViolations;
|
84 |
| } |
85 |
| |
86 |
| |
87 |
| |
88 |
0
| public void childrenAccept(ReportVisitor visitor) {
|
89 |
0
| for (int i = 0; i < childNodes.size(); i++) {
|
90 |
0
| AbstractReportNode node = (AbstractReportNode) childNodes.get(i);
|
91 |
0
| node.accept(visitor);
|
92 |
| } |
93 |
| } |
94 |
| |
95 |
0
| public void accept(ReportVisitor visitor) {
|
96 |
0
| visitor.visit(this);
|
97 |
| } |
98 |
| |
99 |
46078
| public AbstractReportNode getChildAt(int arg0) {
|
100 |
46078
| if (arg0 >= 0 && arg0 <= this.childNodes.size() - 1) {
|
101 |
46078
| return (AbstractReportNode) this.childNodes.get(arg0);
|
102 |
| } |
103 |
0
| return null;
|
104 |
| } |
105 |
| |
106 |
49821
| public int getChildCount() {
|
107 |
49821
| return this.childNodes.size();
|
108 |
| } |
109 |
| |
110 |
0
| public AbstractReportNode getParent() {
|
111 |
0
| return this.parentNode;
|
112 |
| } |
113 |
| |
114 |
0
| public boolean isLeaf() {
|
115 |
0
| return this.childNodes.isEmpty();
|
116 |
| } |
117 |
| |
118 |
| } |