| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
package net.sourceforge.cobertura.coveragedata; |
| 23 | |
|
| 24 | |
import java.io.Serializable; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
public class JumpData implements BranchCoverageData, Comparable, Serializable, |
| 34 | |
HasBeenInstrumented |
| 35 | |
{ |
| 36 | |
private static final long serialVersionUID = 8; |
| 37 | |
|
| 38 | |
private int conditionNumber; |
| 39 | |
|
| 40 | |
private long trueHits; |
| 41 | |
|
| 42 | |
private long falseHits; |
| 43 | |
|
| 44 | |
JumpData(int conditionNumber) |
| 45 | |
{ |
| 46 | |
super(); |
| 47 | |
this.conditionNumber = conditionNumber; |
| 48 | |
this.trueHits = 0L; |
| 49 | |
this.falseHits = 0L; |
| 50 | |
} |
| 51 | |
|
| 52 | |
public int compareTo(Object o) |
| 53 | |
{ |
| 54 | |
if (!o.getClass().equals(JumpData.class)) |
| 55 | |
return Integer.MAX_VALUE; |
| 56 | |
return this.conditionNumber - ((JumpData) o).conditionNumber; |
| 57 | |
} |
| 58 | |
|
| 59 | |
void touchBranch(boolean branch) |
| 60 | |
{ |
| 61 | |
if (branch) |
| 62 | |
{ |
| 63 | |
this.trueHits++; |
| 64 | |
} |
| 65 | |
else |
| 66 | |
{ |
| 67 | |
this.falseHits++; |
| 68 | |
} |
| 69 | |
} |
| 70 | |
|
| 71 | |
public int getConditionNumber() |
| 72 | |
{ |
| 73 | |
return this.conditionNumber; |
| 74 | |
} |
| 75 | |
|
| 76 | |
public long getTrueHits() |
| 77 | |
{ |
| 78 | |
return this.trueHits; |
| 79 | |
} |
| 80 | |
|
| 81 | |
public long getFalseHits() |
| 82 | |
{ |
| 83 | |
return this.falseHits; |
| 84 | |
} |
| 85 | |
|
| 86 | |
public double getBranchCoverageRate() |
| 87 | |
{ |
| 88 | |
return ((double) getNumberOfCoveredBranches()) / getNumberOfValidBranches(); |
| 89 | |
} |
| 90 | |
|
| 91 | |
public boolean equals(Object obj) |
| 92 | |
{ |
| 93 | |
if (this == obj) |
| 94 | |
return true; |
| 95 | |
if ((obj == null) || !(obj.getClass().equals(this.getClass()))) |
| 96 | |
return false; |
| 97 | |
|
| 98 | |
JumpData branchData = (JumpData) obj; |
| 99 | |
return (this.trueHits == branchData.trueHits) |
| 100 | |
&& (this.falseHits == branchData.falseHits) |
| 101 | |
&& (this.conditionNumber == branchData.conditionNumber); |
| 102 | |
} |
| 103 | |
|
| 104 | |
public int hashCode() |
| 105 | |
{ |
| 106 | |
return this.conditionNumber; |
| 107 | |
} |
| 108 | |
|
| 109 | |
public int getNumberOfCoveredBranches() |
| 110 | |
{ |
| 111 | |
return ((trueHits > 0) ? 1 : 0) + ((falseHits > 0) ? 1: 0); |
| 112 | |
} |
| 113 | |
|
| 114 | |
public int getNumberOfValidBranches() |
| 115 | |
{ |
| 116 | |
return 2; |
| 117 | |
} |
| 118 | |
|
| 119 | |
public void merge(BranchCoverageData coverageData) |
| 120 | |
{ |
| 121 | |
JumpData jumpData = (JumpData) coverageData; |
| 122 | |
this.trueHits += jumpData.trueHits; |
| 123 | |
this.falseHits += jumpData.falseHits; |
| 124 | |
} |
| 125 | |
|
| 126 | |
} |