org.jcoderz.phoenix.report
Class FileSummary

java.lang.Object
  extended by org.jcoderz.phoenix.report.FileSummary
All Implemented Interfaces:
Comparable<FileSummary>

public final class FileSummary
extends Object
implements Comparable<FileSummary>

This class encapsulates all finding information collected for a file or a group of files.

This class also allows to perform the magic quality calculation for the data collected in the summary.

Author:
Andreas Mandel

Constructor Summary
FileSummary()
          Creates a new empty file summary object used to summarize findings for classes in all packages.
FileSummary(String packagename)
          Creates a new empty file summary object used to summarize findings for classes in in the given package.
FileSummary(String className, String packagename, String reportfile, int linesOfCode, boolean withCoverage)
          Creates a new empty file summary object used to summarize findings for the given class in the given package with link to the file and code information.
 
Method Summary
 void add(File file)
          Adds the counters from the given file to this summary.
 void add(FileSummary other)
          Add the counters of an other FileSummary to this one.
 void addCoveredLine()
          Increments the counter of covered lines.
 void addViolation(Severity severity)
          Increments the counter for the given severity in this summary.
static float calculateQuality(int loc, int[] violations)
          Calculates the quality as percentage represented as float.
static float calculateQuality(int loc, int info, int warning, int error, int coverage, int filtered, int codestyle, int design, int cpd)
          Calculates the quality percentage scored for the code.
 int compareTo(FileSummary o)
          
 String getClassName()
           
 int getCoverage()
           
 float getCoverageAsFloat()
          Get the coverage percentage in double precision.
 String getCoverageAsString()
          Returns the coverage as user string.
 String getCoverageBar()
          Generates a string containing xhtml code that renders to a bar that can be used as component of a web page to represent the amount of covered code.
 String getFullClassName()
           
 String getHtmlLink()
           
 int getLinesOfCode()
           
 int getNotCoveredLinesOfCode()
           
 int getNumberOfFiles()
           
 int getNumberOfFindings()
          All findings that are between Severity.INFO and Severity.ERROR but not Severity.COVERAGE are counted.
 String getPackage()
           
 String getPercentBar()
          Generates a string containing xhtml code that renders to a percentage bar that can be used as component of a web page.
 int getQuality()
          Returns the magic quality as percentage int.
 float getQualityAsFloat()
          Returns the magic quality as percentage float.
 int getViolations(Severity severity)
          Returns the number of violations for the given severity.
 boolean isWithCoverage()
          Returns true if this summary contains coverage data.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileSummary

public FileSummary()
Creates a new empty file summary object used to summarize findings for classes in all packages.


FileSummary

public FileSummary(String packagename)
Creates a new empty file summary object used to summarize findings for classes in in the given package.

Parameters:
packagename - name of the package where this summary is used for.

FileSummary

public FileSummary(String className,
                   String packagename,
                   String reportfile,
                   int linesOfCode,
                   boolean withCoverage)
Creates a new empty file summary object used to summarize findings for the given class in the given package with link to the file and code information.

Parameters:
className - the name of the class (without package information).
packagename - the name of the package where the class resides in.
reportfile - the name of the file where the html report stored.
linesOfCode - the number of lines in the file.
withCoverage - true if coverage information is available.
Method Detail

calculateQuality

public static float calculateQuality(int loc,
                                     int[] violations)
Calculates the quality as percentage represented as float.

Parameters:
loc - total number of lines of code. This is also the maximum that might be returned by this method.
violations - the array holding the violations of the severity related to the position in the array. The elements of the array are NOT modified.
Returns:
the quality as percentage represented as float.

calculateQuality

public static float calculateQuality(int loc,
                                     int info,
                                     int warning,
                                     int error,
                                     int coverage,
                                     int filtered,
                                     int codestyle,
                                     int design,
                                     int cpd)
Calculates the quality percentage scored for the code. Maximum returned is 100 the minimum is 0.

Parameters:
loc - total number of lines of code. This is also the maximum that might be returned by this method.
info - number of info level findings.
warning - number of warning level findings.
error - number of error level findings.
coverage - number of coverage level findings.
filtered - number of filtered level findings.
codestyle - number of codestyle level findings.
design - number of design level findings.
cpd - number of cpd level findings.
Returns:
the unweighed quality score.

getClassName

public String getClassName()
Returns:
the name of the class (without package information).

getPackage

public String getPackage()
Returns:
the name of the package.

getNumberOfFiles

public int getNumberOfFiles()
Returns:
the number of files summarized in this file summary.

toString

public String toString()

Overrides:
toString in class Object

add

public void add(FileSummary other)
Add the counters of an other FileSummary to this one.

Parameters:
other - the FileSummary be added.

add

public void add(File file)
Adds the counters from the given file to this summary.

Parameters:
file - the data to be added.

isWithCoverage

public boolean isWithCoverage()
Returns true if this summary contains coverage data.

Returns:
true if this summary contains coverage data.

addCoveredLine

public void addCoveredLine()
Increments the counter of covered lines.


addViolation

public void addViolation(Severity severity)
Increments the counter for the given severity in this summary.

Parameters:
severity - the severity of the counter to be incremented.

getFullClassName

public String getFullClassName()
Returns:
the full class name including package declaration.

getHtmlLink

public String getHtmlLink()
Returns:
the report file associated to this FileSummary.

getLinesOfCode

public int getLinesOfCode()
Returns:
the number of lines of code.

getQuality

public int getQuality()
Returns the magic quality as percentage int. The maximum quality code gets a score of 100. The lowest score possible is 0.

Returns:
the magic quality as percentage int (0-100).

getQualityAsFloat

public float getQualityAsFloat()
Returns the magic quality as percentage float. The maximum quality code gets a score of 100. The lowest score possible is 0.

Returns:
the magic quality as percentage float (0.0-100.0).

getPercentBar

public String getPercentBar()
Generates a string containing xhtml code that renders to a percentage bar that can be used as component of a web page.

Returns:
a string containing xhtml.

getCoverageBar

public String getCoverageBar()
Generates a string containing xhtml code that renders to a bar that can be used as component of a web page to represent the amount of covered code.

Returns:
a string containing xhtml.

getViolations

public int getViolations(Severity severity)
Returns the number of violations for the given severity.

Parameters:
severity - the severity to check.
Returns:
the number of violations for the given severity

getCoverageAsFloat

public float getCoverageAsFloat()
Get the coverage percentage in double precision.

Returns:
the coverage percentage in double precision.

getCoverageAsString

public String getCoverageAsString()
Returns the coverage as user string.

Returns:
the coverage as user string.

getCoverage

public int getCoverage()
Returns:
the coverage percentage as int.

getNotCoveredLinesOfCode

public int getNotCoveredLinesOfCode()
Returns:
the number of not covered lines of code.

getNumberOfFindings

public int getNumberOfFindings()
All findings that are between Severity.INFO and Severity.ERROR but not Severity.COVERAGE are counted.

Returns:
the number of violations summed up in this summary.

compareTo

public int compareTo(FileSummary o)

Specified by:
compareTo in interface Comparable<FileSummary>


Copyright 2007 The jCoderZ Project.