Class Report

  • All Implemented Interfaces:
    Serializable, Iterable<Issue>

    public class Report
    extends Object
    implements Iterable<Issue>, Serializable
    A report contains a set of unique issues: 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 builder class.

    Author:
    Ullrich Hafner
    See Also:
    Serialized Form
    • Constructor Detail

      • Report

        public Report()
        Creates an empty Report.
      • Report

        public Report​(String id,
                      String name)
        Creates an empty Report with the specified ID and name.
        Parameters:
        id - the ID of the report
        name - a human-readable name for the report
      • Report

        public Report​(String id,
                      String name,
                      String originReportFile)
        Creates an empty Report with 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 report
        name - a human-readable name for the report
        originReportFile - the specified source file * that is the origin of the issues.
      • Report

        public Report​(Report... reports)
        Creates a new Report that is an aggregation of the specified reports. 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 new Report that is an aggregation of the specified reports. 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 the DEFAULT_ID will 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 report
        originName - 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 the DEFAULT_ID will 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 this Report (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 method getDuplicatesSize().
        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 method getDuplicatesSize().
        Parameters:
        issue - the first issue to append
        additionalIssues - 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 method getDuplicatesSize().
        Parameters:
        issues - the issues to append
        Returns:
        this
        See Also:
        add(Issue)
      • addAll

        public Report addAll​(Report... reports)
        Appends the specified reports to 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 sequential Stream of Issue instances.
        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:
        true if this report is empty, false otherwise
        See Also:
        isNotEmpty()
      • isNotEmpty

        public boolean isNotEmpty()
        Returns whether this report is not empty.
        Returns:
        true if this report is not empty, false otherwise
        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 on equals(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 specified severity.
        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 specified Severity.
        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 an Issue
      • 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:
        true if the number of modules is greater than 1, false otherwise
      • 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:
        true if the number of packages is greater than 1, false otherwise
      • 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:
        true if the number of folders is greater than 1, false otherwise
      • 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:
        true if the number of affected files is greater than 1, false otherwise
      • 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:
        true if the number of categories is greater than 1, false otherwise
      • 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:
        true if the number of types is greater than 1, false otherwise
      • 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:
        true if the number of tools is greater than 1, false otherwise
      • 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:
        true if the number of severities is greater than 1, false otherwise
      • 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 of Report for 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 string
        args - 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 string
        args - 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 log
        format - A format string
        args - 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:
        true if there are error messages, false otherwise
      • equals

        public boolean equals​(@CheckForNull
                              Object o)
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getNameOfOrigin

        public String getNameOfOrigin​(String origin)
        Returns a human-readable name for the specified origin of 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 counter
        value - 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:
        true if the counter has been set, false otherwise