Package edu.hm.hafner.analysis
Class Report
- java.lang.Object
-
- edu.hm.hafner.analysis.Report
-
- All Implemented Interfaces:
Serializable,Iterable<Issue>
public class Report extends Object implements Iterable<Issue>, Serializable
A report contains a set of uniqueissues: it contains no duplicate elements, i.e. it models the mathematical set abstraction. This report provides a total ordering on its elements. I.e., the issues in this report are ordered by their index: the first added issue is at position 0, the second added issues is at position 1, and so on.Additionally, this report provides methods to find and filter issues based on different properties. In order to create issues use the provided
builderclass.- Author:
- Ullrich Hafner
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReport.IssueFilterBuilderBuilds a combined filter based on several include and exclude filters.static interfaceReport.IssuePrinterPrints a summary of anIssue.static classReport.StandardOutputPrinterPrints issues to the "standard" output stream.
-
Constructor Summary
Constructors Constructor Description Report()Creates an emptyReport.Report(Report... reports)Report(String id, String name)Creates an emptyReportwith the specified ID and name.Report(String id, String name, String originReportFile)Creates an emptyReportwith the specified ID and name.Report(Collection<? extends Report> reports)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Reportadd(Issue issue)Appends the specified issue to the end of this report.ReportaddAll(Issue issue, Issue... additionalIssues)Appends all of the specified issues to the end of this report, preserving the order of the array elements.ReportaddAll(Report... reports)Appends the specifiedreportsto this report.ReportaddAll(Collection<? extends Issue> issues)Appends all of the specified issues to the end of this report, preserving the order of the array elements.Reportcopy()Returns a shallow copy of this issue container.ReportcopyEmptyInstance()Returns a new empty issue container with the same properties as this container.booleanequals(Object o)Reportfilter(Predicate<? super Issue> criterion)Finds all issues that match the specified criterion.IssuefindById(UUID issueId)Returns the issue with the specified ID.Set<Issue>findByProperty(Predicate<? super Issue> criterion)Finds all issues that match the specified criterion.Collection<Issue>get()Returns the issues in this report.Issueget(int index)Returns the issue with the specified index.Set<String>getAbsolutePaths()Returns the absolute paths of the affected files for all issues.Set<String>getCategories()Returns the used categories for all issues.intgetCounter(String key)Returns the specified custom counter of this report.intgetDuplicatesSize()Returns the number of duplicates.StringgetEffectiveId()Returns the effective ID of this report.StringgetEffectiveName()Returns the effective ID of this report.List<String>getErrorMessages()Returns the error messages that have been reported since the creation of this set of issues.Set<String>getFiles()Returns the affected files for all issues.Set<String>getFolders()Returns the folders for all affected files of the issues.StringgetId()List<String>getInfoMessages()Returns the info messages that have been reported since the creation of this set of issues.Set<String>getModules()Returns the affected modules for all issues.StringgetName()StringgetNameOfOrigin(String origin)Returns a human-readable name for the specifiedoriginof this report.StringgetOriginReportFile()Set<String>getOriginReportFiles()Returns the names of all report files that are the origin for the issues of thisReport(and all contained sub-reports).Set<String>getPackages()Returns the affected packages for all issues.<T> Set<T>getProperties(Function<? super Issue,T> propertiesMapper)Returns the different values for a given property for all issues.<T> Map<T,Integer>getPropertyCount(Function<? super Issue,T> propertiesMapper)Returns the number of occurrences for every existing value of a given property for all issues.Set<Severity>getSeverities()Returns the severities of all issues.intgetSize()Returns the number of issues in this report.intgetSizeOf(Severity severity)Returns the number of issues with the specifiedSeverity.intgetSizeOf(String severity)Returns the number of issues with the specifiedseverity.Set<String>getTools()Returns the names of the tools that did report the issues.Set<String>getTypes()Returns the used types for all issues.Map<String,Report>groupByProperty(String propertyName)Groups issues by a specified property.booleanhasCategories()Returns whether this report contains issues with different categories.booleanhasCounter(String key)Returns whether the specified custom counter of this report is defined.booleanhasErrors()Returns whether error messages have been reported.booleanhasFiles()Returns whether this report contains more than one affected file.booleanhasFolders()Returns whether this report contains more than one folder with affected files.inthashCode()booleanhasModules()Returns whether this report contains affected files from more than one module.booleanhasPackages()Returns whether this report contains affected files from more than one package.booleanhasSeverities()Returns whether this report contains issues of different severities.booleanhasTools()Returns whether this report contains issues created by different tools.booleanhasTypes()Returns whether this report contains issues with different types.booleanisEmpty()Returns whether this report is empty.booleanisNotEmpty()Returns whether this report is not empty.Iterator<Issue>iterator()voidlogError(String format, Object... args)Logs the specified error message.voidlogException(Exception exception, String format, Object... args)Logs the specified exception.voidlogInfo(String format, Object... args)Logs the specified information message.voidprint(Report.IssuePrinter issuePrinter)Prints all issues of the report.protected ObjectreadResolve()Called after de-serialization to improve the memory usage and to initialize fields that have been introduced after the first release.voidsetCounter(String key, int value)Sets the specified custom counter for this report.voidsetOrigin(String originId, String originName)Sets the origin of all issues in this report.voidsetOriginReportFile(String originReportFile)intsize()Returns the number of issues in this container.Stream<Issue>stream()Creates a new sequentialStreamofIssueinstances.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
Report
public Report()
Creates an emptyReport.
-
Report
public Report(String id, String name)
Creates an emptyReportwith the specified ID and name.- Parameters:
id- the ID of the reportname- a human-readable name for the report
-
Report
public Report(String id, String name, String originReportFile)
Creates an emptyReportwith the specified ID and name. Link the report with the specified source file that is the origin of the issues.- Parameters:
id- the ID of the reportname- a human-readable name for the reportoriginReportFile- the specified source file * that is the origin of the issues.
-
Report
public Report(Report... reports)
Creates a newReportthat is an aggregation of the specifiedreports. The created report will contain the issues of all specified reports, in the same order. The properties of the specified reports will also be copied.- Parameters:
reports- the reports to append- See Also:
copyIssuesAndProperties(Report, Report)
-
Report
public Report(Collection<? extends Report> reports)
Creates a newReportthat is an aggregation of the specifiedreports. The created report will contain the issues of all specified reports, in the same order. The properties of the specified reports will also be copied.- Parameters:
reports- the initial set of issues- See Also:
copyIssuesAndProperties(Report, Report)
-
-
Method Detail
-
getId
public String getId()
-
getEffectiveId
public String getEffectiveId()
Returns the effective ID of this report. This ID is the unique ID of all containing sub-reports. If this ID is not unique, then theDEFAULT_IDwill be returned.- Returns:
- the effective ID of all sub-reports
-
getName
public String getName()
-
setOrigin
public void setOrigin(String originId, String originName)
Sets the origin of all issues in this report. Calling this method will associate all containing issues and issues in sub-reports using the specified ID and name.- Parameters:
originId- the ID of the reportoriginName- a human-readable name for the report
-
getEffectiveName
public String getEffectiveName()
Returns the effective ID of this report. This ID is the unique ID of all containing sub-reports. If this ID is not unique, then theDEFAULT_IDwill be returned.- Returns:
- the effective ID of all sub-reports
-
getOriginReportFile
public String getOriginReportFile()
-
setOriginReportFile
public void setOriginReportFile(String originReportFile)
-
getOriginReportFiles
public Set<String> getOriginReportFiles()
Returns the names of all report files that are the origin for the issues of thisReport(and all contained sub-reports).- Returns:
- the names of all report files
-
add
public Report add(Issue issue)
Appends the specified issue to the end of this report. Duplicates will be skipped (the number of skipped elements is available using the methodgetDuplicatesSize().- Parameters:
issue- the issue to append- Returns:
- this
-
addAll
public Report addAll(Issue issue, Issue... additionalIssues)
Appends all of the specified issues to the end of this report, preserving the order of the array elements. Duplicates will be skipped (the number of skipped elements is available using the methodgetDuplicatesSize().- Parameters:
issue- the first issue to appendadditionalIssues- the additional issue to append- Returns:
- this
- See Also:
add(Issue)
-
addAll
public Report addAll(Collection<? extends Issue> issues)
Appends all of the specified issues to the end of this report, preserving the order of the array elements. Duplicates will be skipped (the number of skipped elements is available using the methodgetDuplicatesSize().- Parameters:
issues- the issues to append- Returns:
- this
- See Also:
add(Issue)
-
addAll
public Report addAll(Report... reports)
Appends the specifiedreportsto this report. This report will then contain the issues of all specified reports, in the same order. The properties of the specified reports will also be copied.- Parameters:
reports- the reports to append- Returns:
- this
- See Also:
copyIssuesAndProperties(Report, Report)
-
readResolve
protected Object readResolve()
Called after de-serialization to improve the memory usage and to initialize fields that have been introduced after the first release.- Returns:
- this
-
findById
public Issue findById(UUID issueId)
Returns the issue with the specified ID.- Parameters:
issueId- the ID of the issue- Returns:
- the found issue
- Throws:
edu.hm.hafner.util.NoSuchElementException- if there is no such issue found
-
findByProperty
public Set<Issue> findByProperty(Predicate<? super Issue> criterion)
Finds all issues that match the specified criterion.- Parameters:
criterion- the filter criterion- Returns:
- the found issues
-
filter
public Report filter(Predicate<? super Issue> criterion)
Finds all issues that match the specified criterion.- Parameters:
criterion- the filter criterion- Returns:
- the found issues
-
stream
public Stream<Issue> stream()
Creates a new sequentialStreamofIssueinstances.- Returns:
- a new
Stream
-
get
public Collection<Issue> get()
Returns the issues in this report. This will include the issues of any sub-reports.- Returns:
- all issues in this report
-
get
public Issue get(int index)
Returns the issue with the specified index.- Parameters:
index- the index- Returns:
- the issue at the specified index
- Throws:
IndexOutOfBoundsException- if there is no element for the given index
-
size
public int size()
Returns the number of issues in this container.- Returns:
- total number of issues
-
isEmpty
public boolean isEmpty()
Returns whether this report is empty.- Returns:
trueif this report is empty,falseotherwise- See Also:
isNotEmpty()
-
isNotEmpty
public boolean isNotEmpty()
Returns whether this report is not empty.- Returns:
trueif this report is not empty,falseotherwise- See Also:
isEmpty()
-
getSize
public int getSize()
Returns the number of issues in this report.- Returns:
- total number of issues
-
getDuplicatesSize
public int getDuplicatesSize()
Returns the number of duplicates. Every issue that has been added to this report, but already is part of this report (based onequals(Object)) is counted as a duplicate. Duplicates are not stored in this report.- Returns:
- total number of duplicates
-
getSizeOf
public int getSizeOf(String severity)
Returns the number of issues with the specifiedseverity.- Parameters:
severity- the severity of the issues- Returns:
- total number of issues
-
getSizeOf
public int getSizeOf(Severity severity)
Returns the number of issues with the specifiedSeverity.- Parameters:
severity- the severity of the issues- Returns:
- total number of issues
-
print
public void print(Report.IssuePrinter issuePrinter)
Prints all issues of the report.- Parameters:
issuePrinter- prints a summary of anIssue
-
getModules
public Set<String> getModules()
Returns the affected modules for all issues.- Returns:
- the affected modules
-
hasModules
public boolean hasModules()
Returns whether this report contains affected files from more than one module.- Returns:
trueif the number of modules is greater than 1,falseotherwise
-
getPackages
public Set<String> getPackages()
Returns the affected packages for all issues.- Returns:
- the affected packages
-
hasPackages
public boolean hasPackages()
Returns whether this report contains affected files from more than one package.- Returns:
trueif the number of packages is greater than 1,falseotherwise
-
getFolders
public Set<String> getFolders()
Returns the folders for all affected files of the issues.- Returns:
- the affected packages
-
hasFolders
public boolean hasFolders()
Returns whether this report contains more than one folder with affected files.- Returns:
trueif the number of folders is greater than 1,falseotherwise
-
getAbsolutePaths
public Set<String> getAbsolutePaths()
Returns the absolute paths of the affected files for all issues.- Returns:
- the affected files
-
getFiles
public Set<String> getFiles()
Returns the affected files for all issues.- Returns:
- the affected files
-
hasFiles
public boolean hasFiles()
Returns whether this report contains more than one affected file.- Returns:
trueif the number of affected files is greater than 1,falseotherwise
-
getCategories
public Set<String> getCategories()
Returns the used categories for all issues.- Returns:
- the used categories
-
hasCategories
public boolean hasCategories()
Returns whether this report contains issues with different categories.- Returns:
trueif the number of categories is greater than 1,falseotherwise
-
getTypes
public Set<String> getTypes()
Returns the used types for all issues.- Returns:
- the used types
-
hasTypes
public boolean hasTypes()
Returns whether this report contains issues with different types.- Returns:
trueif the number of types is greater than 1,falseotherwise
-
getTools
public Set<String> getTools()
Returns the names of the tools that did report the issues.- Returns:
- the tools
-
hasTools
public boolean hasTools()
Returns whether this report contains issues created by different tools.- Returns:
trueif the number of tools is greater than 1,falseotherwise
-
getSeverities
public Set<Severity> getSeverities()
Returns the severities of all issues.- Returns:
- the severities
-
hasSeverities
public boolean hasSeverities()
Returns whether this report contains issues of different severities.- Returns:
trueif the number of severities is greater than 1,falseotherwise
-
getProperties
public <T> Set<T> getProperties(Function<? super Issue,T> propertiesMapper)
Returns the different values for a given property for all issues.- Type Parameters:
T- type of the property- Parameters:
propertiesMapper- the properties mapper that selects the property- Returns:
- the set of different values
- See Also:
getFiles()
-
getPropertyCount
public <T> Map<T,Integer> getPropertyCount(Function<? super Issue,T> propertiesMapper)
Returns the number of occurrences for every existing value of a given property for all issues.- Type Parameters:
T- type of the property- Parameters:
propertiesMapper- the properties mapper that selects the property to evaluate- Returns:
- a mapping of: property value to the number of issues for that value
- See Also:
getProperties(Function)
-
groupByProperty
public Map<String,Report> groupByProperty(String propertyName)
Groups issues by a specified property. Returns the results as a mapping of property values to a new set ofReportfor this value.- Parameters:
propertyName- the property to that selects the property to evaluate- Returns:
- a mapping of: property value to the number of issues for that value
- See Also:
getProperties(Function)
-
copy
public Report copy()
Returns a shallow copy of this issue container.- Returns:
- a new issue container that contains the same elements in the same order
-
copyEmptyInstance
public Report copyEmptyInstance()
Returns a new empty issue container with the same properties as this container. The new issue container is empty and does not contain issues.- Returns:
- a new issue container that contains the same properties but no issues
-
logInfo
@FormatMethod public void logInfo(String format, Object... args)
Logs the specified information message. Use this method to log any useful information when composing this report.- Parameters:
format- A format stringargs- Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero.- See Also:
getInfoMessages()
-
logError
@FormatMethod public void logError(String format, Object... args)
Logs the specified error message. Use this method to log any error when composing this report.- Parameters:
format- A format stringargs- Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero.- See Also:
getInfoMessages()
-
logException
@FormatMethod public void logException(Exception exception, String format, Object... args)
Logs the specified exception. Use this method to log any exception when composing this report.- Parameters:
exception- the exception to logformat- A format stringargs- Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero.- See Also:
getInfoMessages()
-
getInfoMessages
public List<String> getInfoMessages()
Returns the info messages that have been reported since the creation of this set of issues.- Returns:
- the info messages
-
getErrorMessages
public List<String> getErrorMessages()
Returns the error messages that have been reported since the creation of this set of issues.- Returns:
- the error messages
-
hasErrors
public boolean hasErrors()
Returns whether error messages have been reported.- Returns:
trueif there are error messages,falseotherwise
-
getNameOfOrigin
public String getNameOfOrigin(String origin)
Returns a human-readable name for the specifiedoriginof this report.- Parameters:
origin- the origin to get the human-readable name for- Returns:
- the name, or an empty string if no such name has been set
-
setCounter
public void setCounter(String key, int value)
Sets the specified custom counter for this report.- Parameters:
key- the unique key for this countervalue- the value to set
-
getCounter
public int getCounter(String key)
Returns the specified custom counter of this report.- Parameters:
key- the unique key for this counter- Returns:
- the value of the specified counter, or 0 if the counter has not been set or is undefined
-
hasCounter
public boolean hasCounter(String key)
Returns whether the specified custom counter of this report is defined.- Parameters:
key- the unique key for this counter- Returns:
trueif the counter has been set,falseotherwise
-
-