1 23 24 package net.sourceforge.cobertura.coveragedata; 25 26 import java.io.Serializable ; 27 28 36 public class LineData 37 implements Comparable , CoverageData, HasBeenInstrumented, Serializable 38 { 39 private static final long serialVersionUID = 4; 40 41 private long hits; 42 private boolean isBranch; 43 private final int lineNumber; 44 private String methodDescriptor; 45 private String methodName; 46 47 LineData(int lineNumber) 48 { 49 this(lineNumber, null, null); 50 } 51 52 LineData(int lineNumber, String methodName, String methodDescriptor) 53 { 54 this.hits = 0; 55 this.isBranch = false; 56 this.lineNumber = lineNumber; 57 this.methodName = methodName; 58 this.methodDescriptor = methodDescriptor; 59 } 60 61 64 public int compareTo(Object o) 65 { 66 if (!o.getClass().equals(LineData.class)) 67 return Integer.MAX_VALUE; 68 return this.lineNumber - ((LineData)o).lineNumber; 69 } 70 71 public boolean equals(Object obj) 72 { 73 if (this == obj) 74 return true; 75 if ((obj == null) || !(obj.getClass().equals(this.getClass()))) 76 return false; 77 78 LineData lineData = (LineData)obj; 79 return (this.hits == lineData.hits) 80 && (this.isBranch == lineData.isBranch) 81 && (this.lineNumber == lineData.lineNumber) 82 && (this.methodDescriptor.equals(lineData.methodDescriptor)) 83 && (this.methodName.equals(lineData.methodName)); 84 } 85 86 public double getBranchCoverageRate() 87 { 88 return (!isBranch || (getHits() > 0)) ? 1 : 0; 89 } 90 91 public long getHits() 92 { 93 return hits; 94 } 95 96 public double getLineCoverageRate() 97 { 98 return (getHits() > 0) ? 1 : 0; 99 } 100 101 public int getLineNumber() 102 { 103 return lineNumber; 104 } 105 106 public String getMethodDescriptor() 107 { 108 return methodDescriptor; 109 } 110 111 public String getMethodName() 112 { 113 return methodName; 114 } 115 116 public int getNumberOfCoveredBranches() 117 { 118 return (isBranch() && (getHits() > 0)) ? 1 : 0; 119 } 120 121 public int getNumberOfCoveredLines() 122 { 123 return (getHits() > 0) ? 1 : 0; 124 } 125 126 public int getNumberOfValidBranches() 127 { 128 return (isBranch()) ? 1 : 0; 129 } 130 131 public int getNumberOfValidLines() 132 { 133 return 1; 134 } 135 136 public int hashCode() 137 { 138 return this.lineNumber; 139 } 140 141 public boolean isBranch() 142 { 143 return isBranch; 144 } 145 146 public void merge(CoverageData coverageData) 147 { 148 LineData lineData = (LineData)coverageData; 149 this.hits += lineData.hits; 150 this.isBranch |= lineData.isBranch(); 151 if (lineData.methodName != null) 152 this.methodName = lineData.methodName; 153 if (lineData.methodDescriptor != null) 154 this.methodDescriptor = lineData.methodDescriptor; 155 } 156 157 void setBranch(boolean isBranch) 158 { 159 this.isBranch = isBranch; 160 } 161 162 void setMethodNameAndDescriptor(String name, String descriptor) 163 { 164 this.methodName = name; 165 this.methodDescriptor = descriptor; 166 } 167 168 void touch() 169 { 170 this.hits++; 171 } 172 173 } 174 | Popular Tags |