Package de.redsix.pdfcompare
Class CompareResultImpl
java.lang.Object
de.redsix.pdfcompare.CompareResultImpl
- All Implemented Interfaces:
CompareResult,ResultCollector
- Direct Known Subclasses:
AbstractCompareResultWithSwap,CompareResultWithExpectedAndActual
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<Integer,ImageWithDimension> protected Environmentprotected booleanprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidaddImagesToDocument(org.apache.pdfbox.pdmodel.PDDocument document) protected voidaddImagesToDocument(org.apache.pdfbox.pdmodel.PDDocument document, Map<Integer, ImageWithDimension> images) voidaddPage(PageDiffCalculator diffCalculator, int pageIndex, ImageWithDimension expectedImage, ImageWithDimension actualImage, ImageWithDimension diffImage) protected voidaddPageToDocument(org.apache.pdfbox.pdmodel.PDDocument document, ImageWithDimension image) voidGives a PageArea, that shows the area of a page, where differences where found.Converts the result of theCompareResult.getDifferences()method to an exclusions JSON format.intGives that total number of pages in the result.Gives a map of the difference percentages per page.Gives a collection of all the pages, that have a difference.booleanAllows to check for differences in excluded areas.protected booleanchecks, whether this CompareResult has stored images.booleanOnly true, when there was no expected document at all.booleanOnly true, when there was no actual document at all.booleanShows, whether one of the two document to comapre was missing or unreadable.booleanisEqual()Returns, whether the compared documents are equal or not.booleanThe inverse of isEqual()protected booleanvoidvoidsetEnvironment(Environment environment) booleanwriteTo(OutputStream outputStream) Write the result Pdf to an OutputStream.booleanWrite the result Pdf to a file.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.redsix.pdfcompare.ResultCollector
done
-
Field Details
-
environment
-
diffImages
-
isEqual
protected boolean isEqual -
hasDifferenceInExclusion
protected boolean hasDifferenceInExclusion
-
-
Constructor Details
-
CompareResultImpl
public CompareResultImpl()
-
-
Method Details
-
writeTo
Description copied from interface:CompareResultWrite 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:
writeToin interfaceCompareResult- Parameters:
filename- without pdf-Extension- Returns:
- a boolean indicating, whether the comparison is equal. When true, the files are equal.
-
writeTo
Description copied from interface:CompareResultWrite 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:
writeToin interfaceCompareResult- 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:
addPagein interfaceResultCollector
-
noPagesFound
public void noPagesFound()- Specified by:
noPagesFoundin interfaceResultCollector
-
isEqual
public boolean isEqual()Description copied from interface:CompareResultReturns, whether the compared documents are equal or not. Documents are also equal, when differences are only in excluded areas.- Specified by:
isEqualin interfaceCompareResult- Returns:
- true, when no differences are found.
-
isNotEqual
public boolean isNotEqual()Description copied from interface:CompareResultThe inverse of isEqual()- Specified by:
isNotEqualin interfaceCompareResult- Returns:
- true, when differences are found.
-
hasDifferenceInExclusion
public boolean hasDifferenceInExclusion()Description copied from interface:CompareResultAllows to check for differences in excluded areas.- Specified by:
hasDifferenceInExclusionin interfaceCompareResult- Returns:
- true, when there where differences in excluded areas.
-
hasOnlyExpected
public boolean hasOnlyExpected()Description copied from interface:CompareResultOnly true, when there was no actual document at all.- Specified by:
hasOnlyExpectedin interfaceCompareResult- Returns:
- true, when the actual document was missing or not readable.
-
hasOnlyActual
public boolean hasOnlyActual()Description copied from interface:CompareResultOnly true, when there was no expected document at all.- Specified by:
hasOnlyActualin interfaceCompareResult- Returns:
- true, when the expected document was missing or not readable.
-
hasOnlyOneDoc
public boolean hasOnlyOneDoc()Description copied from interface:CompareResultShows, whether one of the two document to comapre was missing or unreadable.- Specified by:
hasOnlyOneDocin interfaceCompareResult- 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:CompareResultGives 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:
getNumberOfPagesin interfaceCompareResult- Returns:
- total number of pages in the result
-
getDifferences
Description copied from interface:CompareResultGives 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:
getDifferencesin interfaceCompareResult- Returns:
- a collection of PageAreas, where differences where found.
-
getDifferencesJson
Description copied from interface:CompareResultConverts the result of theCompareResult.getDifferences()method to an exclusions JSON format.- Specified by:
getDifferencesJsonin interfaceCompareResult- Returns:
- a JSON string with exclusion areas.
-
getPagesWithDifferences
Description copied from interface:CompareResultGives a collection of all the pages, that have a difference. The first page of a document is page 1.- Specified by:
getPagesWithDifferencesin interfaceCompareResult- Returns:
- collection of page numbers, that have a difference
-
getPageDiffsInPercent
Description copied from interface:CompareResultGives a map of the difference percentages per page.- Specified by:
getPageDiffsInPercentin interfaceCompareResult- Returns:
- difference percentages mapped to the page index.
-
expectedOnly
public void expectedOnly() -
actualOnly
public void actualOnly() -
setEnvironment
-