Package de.redsix.pdfcompare
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 SubclassCompareResultWithExpectedAndActual
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Integer,ImageWithDimension>diffImagesprotected Environmentenvironmentprotected booleanhasDifferenceInExclusionprotected booleanisEqual
-
Constructor Summary
Constructors Constructor Description CompareResultImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactualOnly()protected 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)voidexpectedOnly()Collection<PageArea>getDifferences()Gives a PageArea, that shows the area of a page, where differences where found.StringgetDifferencesJson()Converts the result of theCompareResult.getDifferences()method to an exclusions JSON format.intgetNumberOfPages()Gives that total number of pages in the result.Map<Integer,Double>getPageDiffsInPercent()Gives a map of the difference percentages per page.Collection<Integer>getPagesWithDifferences()Gives a collection of all the pages, that have a difference.booleanhasDifferenceInExclusion()Allows to check for differences in excluded areas.protected booleanhasImages()checks, whether this CompareResult has stored images.booleanhasOnlyActual()Only true, when there was no expected document at all.booleanhasOnlyExpected()Only true, when there was no actual document at all.booleanhasOnlyOneDoc()Shows, whether one of the two document to comapre was missing or unreadable.booleanisEqual()Returns, whether the compared documents are equal or not.booleanisNotEqual()The inverse of isEqual()protected booleankeepImages()voidnoPagesFound()voidsetEnvironment(Environment environment)booleanwriteTo(OutputStream outputStream)Write the result Pdf to an OutputStream.booleanwriteTo(String filename)Write the result Pdf to a file.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.redsix.pdfcompare.ResultCollector
done
-
-
-
-
Field Detail
-
environment
protected Environment environment
-
diffImages
protected final Map<Integer,ImageWithDimension> diffImages
-
isEqual
protected boolean isEqual
-
hasDifferenceInExclusion
protected boolean hasDifferenceInExclusion
-
-
Method Detail
-
writeTo
public boolean writeTo(String filename)
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
public boolean writeTo(OutputStream outputStream)
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
public Collection<PageArea> 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
public String 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
public Collection<Integer> 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
public Map<Integer,Double> 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
public void setEnvironment(Environment environment)
-
-