Class FileVersionComparator


  • public class FileVersionComparator
    extends java.lang.Object
    The file version comparator is a helper class to compare FileVersions with each other, or compare FileVersions to local Files.

    It captures the FileVersionComparator.FileProperties of two files or file versions and compares them using the various compare*-methods. A comparison returns a set of FileVersionComparator.FileChanges, each of which identifies a certain attribute change (e.g. checksum changed, name changed). A file can be considered equal if the returned set of FileVersionComparator.FileChanges is empty.

    The file version comparator distinguishes between cancelling tests and regular tests. Cancelling tests are implemented in performCancellingTests(). They represent significant changes in a file, for which further comparison would not make sense (e.g. new vs. deleted files or files vs. folders). If a cancelling test is not successful, other tests are not performed.

    • Constructor Detail

      • FileVersionComparator

        public FileVersionComparator​(java.io.File rootFolder,
                                     java.lang.String checksumAlgorithm)
        Creates a new file version comparator helper class.

        The rootFolder is needed to allow a comparison of the relative file path. The checksumAlgorithm is used for calculate and compare file checksums. Both are used if a local File is compared to a FileVersion.

        Parameters:
        rootFolder - Base folder to determine a relative path to
        checksumAlgorithm - Digest algorithm for checksum calculation, e.g. "SHA1" or "MD5"
    • Method Detail

      • compare

        public FileVersionComparator.FileVersionComparison compare​(FileVersion expectedFileVersion,
                                                                   java.io.File actualFile,
                                                                   boolean actualFileForceChecksum)
        Compares a FileVersion with a local File and returns a FileVersionComparator.FileVersionComparison object.

        If the actual file does not differ in size, it is necessary to calculate and compare the checksum of the local file to the file version to reliably determine if it has changed. Unless comparing the size and last modified date is enough, the actualFileForceChecksum parameter must be switched to true.

        Parameters:
        expectedFileVersion - The expected file version (that is compared to the actual file)
        actualFile - The actual file (that is compared to the expected file version)
        actualFileForceChecksum - Force a checksum comparison if necessary (if size does not differ)
        Returns:
        Returns a file version comparison object, indicating if there are differences between the file versions
      • compare

        public FileVersionComparator.FileVersionComparison compare​(FileVersion expectedLocalFileVersion,
                                                                   java.io.File actualLocalFile,
                                                                   FileContent.FileChecksum actualFileKnownChecksum,
                                                                   boolean actualFileForceChecksum)
        Compares a FileVersion with a local File and returns a FileVersionComparator.FileVersionComparison object.

        If the actual file does not differ in size, it is necessary to calculate and compare the checksum of the local file to the file version to reliably determine if it has changed. Unless comparing the size and last modified date is enough, the actualFileForceChecksum parameter must be switched to true.

        If the actualFileKnownChecksum parameter is set and a checksum comparison is necessary, this parameter is used to compare checksums. If not and force checksum is enabled, the checksum is calculated and compared.

        Parameters:
        expectedLocalFileVersion - The expected file version (that is compared to the actual file)
        actualLocalFile - The actual file (that is compared to the expected file version)
        actualFileKnownChecksum - If the checksum of the local file is known, it can be set
        actualFileForceChecksum - Force a checksum comparison if necessary (if size does not differ)
        Returns:
        Returns a file version comparison object, indicating if there are differences between the file versions