net.sourceforge.cobertura.coveragedata
Class ClassData

java.lang.Object
  extended by net.sourceforge.cobertura.coveragedata.CoverageDataContainer
      extended by net.sourceforge.cobertura.coveragedata.ClassData
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, CoverageData, HasBeenInstrumented

public class ClassData
extends CoverageDataContainer
implements java.lang.Comparable, HasBeenInstrumented

ProjectData information is typically serialized to a file. An instance of this class records coverage information for a single class that has been instrumented.

This class implements HasBeenInstrumented so that when cobertura instruments itself, it will omit this class. It does this to avoid an infinite recursion problem because instrumented classes make use of this class.

See Also:
Serialized Form

Field Summary
private  java.util.Map branches
          Each key is a line number in this class, stored as an Integer object.
private  boolean containsInstrumentationInfo
           
private  java.util.Set methodNamesAndDescriptors
           
private  java.lang.String name
           
private static long serialVersionUID
           
private  java.lang.String sourceFileName
           
 
Fields inherited from class net.sourceforge.cobertura.coveragedata.CoverageDataContainer
children, lock
 
Constructor Summary
ClassData(java.lang.String name)
           
 
Method Summary
 LineData addLine(int lineNumber, java.lang.String methodName, java.lang.String methodDescriptor)
           
 void addLineJump(int lineNumber, int branchNumber)
           
 void addLineSwitch(int lineNumber, int switchNumber, int[] keys)
           
 void addLineSwitch(int lineNumber, int switchNumber, int min, int max)
           
 int compareTo(java.lang.Object o)
          This is required because we implement Comparable.
 boolean containsInstrumentationInfo()
           
 boolean equals(java.lang.Object obj)
          Returns true if the given object is an instance of the ClassData class, and it contains the same data as this class.
 java.lang.String getBaseName()
           
 double getBranchCoverageRate(java.lang.String methodNameAndDescriptor)
           
 java.util.Collection getBranches()
           
 LineData getLineCoverage(int lineNumber)
           
 double getLineCoverageRate(java.lang.String methodNameAndDescriptor)
           
private  LineData getLineData(int lineNumber)
           
 java.util.SortedSet getLines()
           
 java.util.Collection getLines(java.lang.String methodNameAndDescriptor)
           
 java.util.Set getMethodNamesAndDescriptors()
           
 java.lang.String getName()
           
 int getNumberOfCoveredBranches()
           
 int getNumberOfValidBranches()
           
 java.lang.String getPackageName()
           
 java.lang.String getSourceFileName()
          Return the name of the file containing this class.
 boolean hasBranch(int lineNumber)
           
 int hashCode()
          It is highly recommended that classes extending this class override this hashCode method and generate a more effective hash code.
 boolean isValidSourceLineNumber(int lineNumber)
          Determine if a given line number is a valid line of code.
 void merge(CoverageData coverageData)
          Merge some existing instrumentation with this instrumentation.
 void removeLine(int lineNumber)
           
 void setContainsInstrumentationInfo()
           
 void setSourceFileName(java.lang.String sourceFileName)
           
 void touch(int lineNumber)
          Increment the number of hits for a particular line of code.
 void touchJump(int lineNumber, int branchNumber, boolean branch)
          Increments the number of hits for particular hit counter of particular branch on particular line number.
 void touchSwitch(int lineNumber, int switchNumber, int branch)
          Increments the number of hits for particular hit counter of particular switch branch on particular line number.
 
Methods inherited from class net.sourceforge.cobertura.coveragedata.CoverageDataContainer
getBothLocks, getBranchCoverageRate, getChild, getLineCoverageRate, getNumberOfChildren, getNumberOfCoveredLines, getNumberOfValidLines
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

branches

private java.util.Map branches
Each key is a line number in this class, stored as an Integer object. Each value is information about the line, stored as a LineData object.


containsInstrumentationInfo

private boolean containsInstrumentationInfo

methodNamesAndDescriptors

private java.util.Set methodNamesAndDescriptors

name

private java.lang.String name

sourceFileName

private java.lang.String sourceFileName
Constructor Detail

ClassData

public ClassData(java.lang.String name)
Parameters:
name - In the format "net.sourceforge.cobertura.coveragedata.ClassData"
Method Detail

addLine

public LineData addLine(int lineNumber,
                        java.lang.String methodName,
                        java.lang.String methodDescriptor)

compareTo

public int compareTo(java.lang.Object o)
This is required because we implement Comparable.

Specified by:
compareTo in interface java.lang.Comparable

containsInstrumentationInfo

public boolean containsInstrumentationInfo()

equals

public boolean equals(java.lang.Object obj)
Returns true if the given object is an instance of the ClassData class, and it contains the same data as this class.

Overrides:
equals in class CoverageDataContainer
Parameters:
obj - An object to test for equality.
Returns:
True if the objects are equal.

getBaseName

public java.lang.String getBaseName()

getBranchCoverageRate

public double getBranchCoverageRate(java.lang.String methodNameAndDescriptor)
Returns:
The branch coverage rate for a particular method.

getBranches

public java.util.Collection getBranches()

getLineCoverage

public LineData getLineCoverage(int lineNumber)
Parameters:
lineNumber - The source code line number.
Returns:
The coverage of the line

getLineCoverageRate

public double getLineCoverageRate(java.lang.String methodNameAndDescriptor)
Returns:
The line coverage rate for particular method

getLineData

private LineData getLineData(int lineNumber)

getLines

public java.util.SortedSet getLines()

getLines

public java.util.Collection getLines(java.lang.String methodNameAndDescriptor)

getMethodNamesAndDescriptors

public java.util.Set getMethodNamesAndDescriptors()
Returns:
The method name and descriptor of each method found in the class represented by this instrumentation.

getName

public java.lang.String getName()

getNumberOfValidBranches

public int getNumberOfValidBranches()
Specified by:
getNumberOfValidBranches in interface CoverageData
Overrides:
getNumberOfValidBranches in class CoverageDataContainer
Returns:
The number of branches in this class.

getNumberOfCoveredBranches

public int getNumberOfCoveredBranches()
Specified by:
getNumberOfCoveredBranches in interface CoverageData
Overrides:
getNumberOfCoveredBranches in class CoverageDataContainer
See Also:
CoverageData.getNumberOfCoveredBranches()

getPackageName

public java.lang.String getPackageName()

getSourceFileName

public java.lang.String getSourceFileName()
Return the name of the file containing this class. If this class' sourceFileName has not been set (for whatever reason) then this method will attempt to infer the name of the source file using the class name.

Returns:
The name of the source file, for example net/sourceforge/cobertura/coveragedata/ClassData.java

hashCode

public int hashCode()
Description copied from class: CoverageDataContainer
It is highly recommended that classes extending this class override this hashCode method and generate a more effective hash code.

Overrides:
hashCode in class CoverageDataContainer

hasBranch

public boolean hasBranch(int lineNumber)
Returns:
True if the line contains at least one condition jump (branch)

isValidSourceLineNumber

public boolean isValidSourceLineNumber(int lineNumber)
Determine if a given line number is a valid line of code.

Returns:
True if the line contains executable code. False if the line is empty, or a comment, etc.

addLineJump

public void addLineJump(int lineNumber,
                        int branchNumber)

addLineSwitch

public void addLineSwitch(int lineNumber,
                          int switchNumber,
                          int[] keys)

addLineSwitch

public void addLineSwitch(int lineNumber,
                          int switchNumber,
                          int min,
                          int max)

merge

public void merge(CoverageData coverageData)
Merge some existing instrumentation with this instrumentation.

Specified by:
merge in interface CoverageData
Overrides:
merge in class CoverageDataContainer
Parameters:
coverageData - Some existing coverage data.

removeLine

public void removeLine(int lineNumber)

setContainsInstrumentationInfo

public void setContainsInstrumentationInfo()

setSourceFileName

public void setSourceFileName(java.lang.String sourceFileName)

touch

public void touch(int lineNumber)
Increment the number of hits for a particular line of code.

Parameters:
lineNumber - the line of code to increment the number of hits.

touchJump

public void touchJump(int lineNumber,
                      int branchNumber,
                      boolean branch)
Increments the number of hits for particular hit counter of particular branch on particular line number.

Parameters:
lineNumber - The line of code where the branch is
branchNumber - The branch on the line to change the hit counter
branch - The hit counter (true or false)

touchSwitch

public void touchSwitch(int lineNumber,
                        int switchNumber,
                        int branch)
Increments the number of hits for particular hit counter of particular switch branch on particular line number.

Parameters:
lineNumber - The line of code where the branch is
switchNumber - The switch on the line to change the hit counter
branch - The hit counter