/*
  i-net software provides programming examples for illustration only, without warranty
  either expressed or implied, including, but not limited to, the implied warranties
  of merchantability and/or fitness for a particular purpose. This programming example
  assumes that you are familiar with the programming language being demonstrated and
  the tools used to create and debug procedures. i-net software support professionals
  can help explain the functionality of a particular procedure, but they will not modify
  these examples to provide added functionality or construct procedures to meet your
  specific needs.
  © i-net software 2011
*/
 
package samples;
 
import java.util.ArrayList;
import java.util.List;
 
import com.inet.pdfc.results.IDifference;
import com.inet.pdfc.results.IPageResult;
import com.inet.pdfc.results.IReportResult;
import com.inet.pdfc.results.IResultHandler;
 
 
/**
 * This is an example of a silent result handler that provides only the information whether the files are identical or not.:
 */
public class SilentResultHandler implements IResultHandler {
    private List<IReportResult> allResults = new ArrayList<IReportResult>();
 
    /**
     * Initiates the custom handler
     */
    public SilentResultHandler() { 
 
    }
 
    /**
     * {@inheritDoc}
     */
    public void addResult( IReportResult result ) {
        allResults.add(result);
    }
 
    /**
     * {@inheritDoc}
     */
    public void finish() {
 
    }
 
    /**
     * Returns the number of differences detected by comparing files.
     * @param reportIndex   index of the files (0- based)
     * @return   number of differences discovered.
     */
    public int getDifferenceCount( int reportIndex ) {
        int reportDiffs = 0;
        IReportResult reportResult = allResults.get( reportIndex );
        List<IPageResult> pageResults = reportResult.getPageResults();
        for( IPageResult pageResult : pageResults ) {
            List<IDifference> differences = pageResult.getDifferences();
            reportDiffs += differences.size();
        }    
        return reportDiffs;
    }
 
    /**
     * Returns true if no differences found
     * @param reportIndex   index of the files (0- based)
     * @return  true if there were no differences detected.    
     */
    public boolean isFilesIdentical( int reportIndex ) {
        return getDifferenceCount(reportIndex) == 0;
    }   
}
 

© Copyright 1996 - 2012, i-net software; All Rights Reserved.