001: /*
002: * Cobertura - http://cobertura.sourceforge.net/
003: *
004: * Copyright (C) 2006 Jiri Mares
005: *
006: * Cobertura is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published
008: * by the Free Software Foundation; either version 2 of the License,
009: * or (at your option) any later version.
010: *
011: * Cobertura is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with Cobertura; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: */
021:
022: package net.sourceforge.cobertura.coveragedata;
023:
024: import java.io.Serializable;
025:
026: /**
027: * <p>
028: * This class implements HasBeenInstrumented so that when cobertura instruments
029: * itself, it will omit this class. It does this to avoid an infinite recursion
030: * problem because instrumented classes make use of this class.
031: * </p>
032: */
033: public class JumpData implements BranchCoverageData, Comparable,
034: Serializable, HasBeenInstrumented {
035: private static final long serialVersionUID = 8;
036:
037: private int conditionNumber;
038:
039: private long trueHits;
040:
041: private long falseHits;
042:
043: JumpData(int conditionNumber) {
044: super ();
045: this .conditionNumber = conditionNumber;
046: this .trueHits = 0L;
047: this .falseHits = 0L;
048: }
049:
050: public int compareTo(Object o) {
051: if (!o.getClass().equals(JumpData.class))
052: return Integer.MAX_VALUE;
053: return this .conditionNumber - ((JumpData) o).conditionNumber;
054: }
055:
056: void touchBranch(boolean branch) {
057: if (branch) {
058: this .trueHits++;
059: } else {
060: this .falseHits++;
061: }
062: }
063:
064: public int getConditionNumber() {
065: return this .conditionNumber;
066: }
067:
068: public long getTrueHits() {
069: return this .trueHits;
070: }
071:
072: public long getFalseHits() {
073: return this .falseHits;
074: }
075:
076: public double getBranchCoverageRate() {
077: return ((double) getNumberOfCoveredBranches())
078: / getNumberOfValidBranches();
079: }
080:
081: public boolean equals(Object obj) {
082: if (this == obj)
083: return true;
084: if ((obj == null) || !(obj.getClass().equals(this .getClass())))
085: return false;
086:
087: JumpData branchData = (JumpData) obj;
088: return (this .trueHits == branchData.trueHits)
089: && (this .falseHits == branchData.falseHits)
090: && (this .conditionNumber == branchData.conditionNumber);
091: }
092:
093: public int hashCode() {
094: return this .conditionNumber;
095: }
096:
097: public int getNumberOfCoveredBranches() {
098: return ((trueHits > 0) ? 1 : 0) + ((falseHits > 0) ? 1 : 0);
099: }
100:
101: public int getNumberOfValidBranches() {
102: return 2;
103: }
104:
105: public void merge(BranchCoverageData coverageData) {
106: JumpData jumpData = (JumpData) coverageData;
107: this.trueHits += jumpData.trueHits;
108: this.falseHits += jumpData.falseHits;
109: }
110:
111: }
|