Class CompareResultImpl

java.lang.Object
de.redsix.pdfcompare.CompareResultImpl
All Implemented Interfaces:
CompareResult, ResultCollector
Direct Known Subclasses:
AbstractCompareResultWithSwap, CompareResultWithExpectedAndActual

public class CompareResultImpl extends Object implements ResultCollector, CompareResult
A CompareResult tracks the differences, that result from a comparison. The CompareResult only stores the diffImages, for lower memory consumption. If you also need the expected and actual Image, please use the Subclass CompareResultWithExpectedAndActual
  • Field Details

    • environment

      protected Environment environment
    • diffImages

      protected final Map<Integer,ImageWithDimension> diffImages
    • isEqual

      protected boolean isEqual
    • hasDifferenceInExclusion

      protected boolean hasDifferenceInExclusion
  • Constructor Details

    • CompareResultImpl

      public CompareResultImpl()
  • Method Details

    • writeTo

      public boolean writeTo(String filename)
      Description copied from interface: CompareResult
      Write the result Pdf to a file. Warning: This will remove the diffImages from memory! Writing can only be done once. When no diff images are present, nothing is written.
      Specified by:
      writeTo in interface CompareResult
      Parameters:
      filename - without pdf-Extension
      Returns:
      a boolean indicating, whether the comparison is equal. When true, the files are equal.
    • writeTo

      public boolean writeTo(OutputStream outputStream)
      Description copied from interface: CompareResult
      Write the result Pdf to an OutputStream. Warning: This will remove the diffImages from memory! Writing can only be done once. When no diff images are present, nothing is written. The given OutputStream will be closed when this method returns.
      Specified by:
      writeTo in interface CompareResult
      Parameters:
      outputStream - to write the pdfFile to.
      Returns:
      a boolean indicating, whether the comparison is equal. When true, the files are equal.
    • hasImages

      protected boolean hasImages()
      checks, whether this CompareResult has stored images.
      Returns:
      true, when images are stored in this CompareResult
    • addImagesToDocument

      protected void addImagesToDocument(org.apache.pdfbox.pdmodel.PDDocument document) throws IOException
      Throws:
      IOException
    • addImagesToDocument

      protected void addImagesToDocument(org.apache.pdfbox.pdmodel.PDDocument document, Map<Integer,ImageWithDimension> images) throws IOException
      Throws:
      IOException
    • addPageToDocument

      protected void addPageToDocument(org.apache.pdfbox.pdmodel.PDDocument document, ImageWithDimension image) throws IOException
      Throws:
      IOException
    • keepImages

      protected boolean keepImages()
    • addPage

      public void addPage(PageDiffCalculator diffCalculator, int pageIndex, ImageWithDimension expectedImage, ImageWithDimension actualImage, ImageWithDimension diffImage)
      Specified by:
      addPage in interface ResultCollector
    • noPagesFound

      public void noPagesFound()
      Specified by:
      noPagesFound in interface ResultCollector
    • isEqual

      public boolean isEqual()
      Description copied from interface: CompareResult
      Returns, whether the compared documents are equal or not. Documents are also equal, when differences are only in excluded areas.
      Specified by:
      isEqual in interface CompareResult
      Returns:
      true, when no differences are found.
    • isNotEqual

      public boolean isNotEqual()
      Description copied from interface: CompareResult
      The inverse of isEqual()
      Specified by:
      isNotEqual in interface CompareResult
      Returns:
      true, when differences are found.
    • hasDifferenceInExclusion

      public boolean hasDifferenceInExclusion()
      Description copied from interface: CompareResult
      Allows to check for differences in excluded areas.
      Specified by:
      hasDifferenceInExclusion in interface CompareResult
      Returns:
      true, when there where differences in excluded areas.
    • hasOnlyExpected

      public boolean hasOnlyExpected()
      Description copied from interface: CompareResult
      Only true, when there was no actual document at all.
      Specified by:
      hasOnlyExpected in interface CompareResult
      Returns:
      true, when the actual document was missing or not readable.
    • hasOnlyActual

      public boolean hasOnlyActual()
      Description copied from interface: CompareResult
      Only true, when there was no expected document at all.
      Specified by:
      hasOnlyActual in interface CompareResult
      Returns:
      true, when the expected document was missing or not readable.
    • hasOnlyOneDoc

      public boolean hasOnlyOneDoc()
      Description copied from interface: CompareResult
      Shows, whether one of the two document to comapre was missing or unreadable.
      Specified by:
      hasOnlyOneDoc in interface CompareResult
      Returns:
      true, when only an ectual or an expected document was found or readable, but not both.
    • getNumberOfPages

      public int getNumberOfPages()
      Description copied from interface: CompareResult
      Gives that total number of pages in the result. This includes pages with differences. When the setting addEqualPagesToResult is set to true, the pages without differences are also counted.
      Specified by:
      getNumberOfPages in interface CompareResult
      Returns:
      total number of pages in the result
    • getDifferences

      public Collection<PageArea> getDifferences()
      Description copied from interface: CompareResult
      Gives a PageArea, that shows the area of a page, where differences where found. There is only one PageArea per page, which contains all differences of the page.
      Specified by:
      getDifferences in interface CompareResult
      Returns:
      a collection of PageAreas, where differences where found.
    • getDifferencesJson

      public String getDifferencesJson()
      Description copied from interface: CompareResult
      Converts the result of the CompareResult.getDifferences() method to an exclusions JSON format.
      Specified by:
      getDifferencesJson in interface CompareResult
      Returns:
      a JSON string with exclusion areas.
    • getPagesWithDifferences

      public Collection<Integer> getPagesWithDifferences()
      Description copied from interface: CompareResult
      Gives a collection of all the pages, that have a difference. The first page of a document is page 1.
      Specified by:
      getPagesWithDifferences in interface CompareResult
      Returns:
      collection of page numbers, that have a difference
    • getPageDiffsInPercent

      public Map<Integer,Double> getPageDiffsInPercent()
      Description copied from interface: CompareResult
      Gives a map of the difference percentages per page.
      Specified by:
      getPageDiffsInPercent in interface CompareResult
      Returns:
      difference percentages mapped to the page index.
    • expectedOnly

      public void expectedOnly()
    • actualOnly

      public void actualOnly()
    • setEnvironment

      public void setEnvironment(Environment environment)