Coverage Report - net.sourceforge.cobertura.coveragedata.JumpData
 
Classes in this File Line Coverage Branch Coverage Complexity
JumpData
N/A
N/A
1.583
 
 1  
 /*
 2  
  * Cobertura - http://cobertura.sourceforge.net/
 3  
  *
 4  
  * Copyright (C) 2006 Jiri Mares
 5  
  *
 6  
  * Cobertura is free software; you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published
 8  
  * by the Free Software Foundation; either version 2 of the License,
 9  
  * or (at your option) any later version.
 10  
  *
 11  
  * Cobertura is distributed in the hope that it will be useful, but
 12  
  * WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 14  
  * General Public License for more details.
 15  
  *
 16  
  * You should have received a copy of the GNU General Public License
 17  
  * along with Cobertura; if not, write to the Free Software
 18  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 19  
  * USA
 20  
  */
 21  
 
 22  
 package net.sourceforge.cobertura.coveragedata;
 23  
 
 24  
 import java.io.Serializable;
 25  
 
 26  
 /**
 27  
  * <p>
 28  
  * This class implements HasBeenInstrumented so that when cobertura instruments
 29  
  * itself, it will omit this class. It does this to avoid an infinite recursion
 30  
  * problem because instrumented classes make use of this class.
 31  
  * </p>
 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  
 }