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