Class SpdxSnippetComparer


  • public class SpdxSnippetComparer
    extends SpdxItemComparer
    Compares two SPDX snippets. The compare(snippetA, snippetB) method will perform the comparison and store the results. isDifferenceFound() will return true of any differences were found.
    Author:
    Gary O'Neall
    • Constructor Detail

      • SpdxSnippetComparer

        public SpdxSnippetComparer​(Map<org.spdx.library.model.v2.SpdxDocument,​Map<org.spdx.library.model.v2.SpdxDocument,​Map<String,​String>>> extractedLicenseIdMap)
        Parameters:
        extractedLicenseIdMap - map of all extracted license IDs for any SPDX documents to be added to the comparer
    • Method Detail

      • addDocumentSnippet

        public void addDocumentSnippet​(org.spdx.library.model.v2.SpdxDocument spdxDocument,
                                       org.spdx.library.model.v2.SpdxSnippet snippet)
                                throws SpdxCompareException,
                                       org.spdx.core.InvalidSPDXAnalysisException
        Add a snippet to the comparer and performs the comparison to any existing documents
        Parameters:
        spdxDocument - document containing the package
        snippet - snippet to be added
        Throws:
        org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing errors
        SpdxCompareException
      • getSnippetFromFileDifference

        public SpdxFileDifference getSnippetFromFileDifference​(org.spdx.library.model.v2.SpdxDocument docA,
                                                               org.spdx.library.model.v2.SpdxDocument docB)
                                                        throws SpdxCompareException
        Get any file difference for the Spdx Snippet From File between the two SPDX documents If the fileName is different, they are considered unique files and the getUniqueSnippetFromFile should be called to obtain the unique file
        Parameters:
        docA - A document to compare
        docB - B document to compare
        Returns:
        the file difference or null if there is no file difference
        Throws:
        SpdxCompareException
      • isSnippetFromFilesEquals

        public boolean isSnippetFromFilesEquals()
                                         throws SpdxCompareException
        The snippetFromFiles can be true if there are some unique snippetFromFiles or differences between the snippetFromFiles (or both)
        Returns:
        the snippetFromFilesEquals
        Throws:
        SpdxCompareException
      • getUniqueSnippetFromFile

        public org.spdx.library.model.v2.SpdxFile getUniqueSnippetFromFile​(org.spdx.library.model.v2.SpdxDocument docA,
                                                                           org.spdx.library.model.v2.SpdxDocument docB)
                                                                    throws SpdxCompareException
        Get an SpdxFile that only exists in docA but not docB
        Parameters:
        docA - A document to compare
        docB - B document to compare
        Returns:
        an SpdxFile that only exists in docA but not docB
        Throws:
        SpdxCompareException
      • getNumSnippets

        public int getNumSnippets()
        Returns:
        Total number of snippets
      • getDocSnippet

        public org.spdx.library.model.v2.SpdxSnippet getDocSnippet​(org.spdx.library.model.v2.SpdxDocument spdxDocument)
        Parameters:
        spdxDocument - document containing the snippet
        Returns:
        snippet in the spdxDocument