Class SpdxSnippetComparer

java.lang.Object
org.spdx.utility.compare.SpdxItemComparer
org.spdx.utility.compare.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 Details

    • 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 Details

    • 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
    • isDifferenceFound

      public boolean isDifferenceFound() throws SpdxCompareException
      Overrides:
      isDifferenceFound in class SpdxItemComparer
      Returns:
      the differenceFound
      Throws:
      SpdxCompareException - on compare errors
    • checkInProgress

      protected void checkInProgress() throws SpdxCompareException
      checks to make sure there is not a compare in progress
      Overrides:
      checkInProgress in class SpdxItemComparer
      Throws:
      SpdxCompareException - on compare errors
    • 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
    • isByteRangeEquals

      public boolean isByteRangeEquals() throws SpdxCompareException
      Returns:
      the byteRangeEquals
      Throws:
      SpdxCompareException
    • isLineRangeEquals

      public boolean isLineRangeEquals() throws SpdxCompareException
      Returns:
      the lineRangeEquals
      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
    • isNameEquals

      public boolean isNameEquals() throws SpdxCompareException
      Returns:
      the nameEquals
      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