![JAR search and dependency download from the Maven repository](/logo.png)
net.sf.sanity4j.model.coverage.Coverage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
The newest version!
package net.sf.sanity4j.model.coverage;
import java.util.HashMap;
import java.util.Map;
/**
* Coverage information for a project.
*
* @author Yiannis Paschalidis
* @since Sanity4J 1.0
*/
public class Coverage extends AbstractCoverage
{
/** PackageCoverages keyed by package name. */
private final Map packagesByName = new HashMap();
/**
* Retrieves the coverage information for the given package.
*
* @param packageName the package name.
* @return the coverage for the given package, or null if there isn't any.
*/
public PackageCoverage getPackageCoverage(final String packageName)
{
return packagesByName.get(packageName);
}
/**
* Retrieves the coverage information for the given class.
*
* @param className the fully qualified class name.
* @return the coverage for the given class, or null if there isn't any.
*/
public ClassCoverage getClassCoverage(final String className)
{
String packageName = null;
int dotIndex = className.lastIndexOf('.');
if (dotIndex != -1)
{
packageName = className.substring(0, dotIndex);
}
PackageCoverage packageCoverage = getPackageCoverage(packageName);
if (packageCoverage != null)
{
return packageCoverage.getClassCoverage(className);
}
return null;
}
/**
* Adds package coverage.
* @param coverage the package coverage to add.
*/
public void addPackage(final PackageCoverage coverage)
{
packagesByName.put(coverage.getPackageName(), coverage);
}
/**
* @return the number of executable lines in this package.
*/
public int getLineCount()
{
int count = 0;
for (PackageCoverage coverage : packagesByName.values())
{
count += coverage.getLineCount();
}
return count;
}
/**
* @return the number of covered lines in this package.
*/
public int getCoveredLineCount()
{
int count = 0;
for (PackageCoverage coverage : packagesByName.values())
{
count += coverage.getCoveredLineCount();
}
return count;
}
/**
* @return the number of branches in this package.
*/
public int getBranchCount()
{
int count = 0;
for (PackageCoverage coverage : packagesByName.values())
{
count += coverage.getBranchCount();
}
return count;
}
/**
* @return the number of covered branches in this package.
*/
public int getCoveredBranchCount()
{
int count = 0;
for (PackageCoverage coverage : packagesByName.values())
{
count += coverage.getCoveredBranchCount();
}
return count;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy