Class FileVersionComparator
- java.lang.Object
-
- org.syncany.database.FileVersionComparator
-
public class FileVersionComparator extends java.lang.Object
The file version comparator is a helper class to compareFileVersion
s with each other, or compareFileVersion
s to localFile
s.It captures the
FileVersionComparator.FileProperties
of two files or file versions and compares them using the variouscompare*
-methods. A comparison returns a set ofFileVersionComparator.FileChange
s, each of which identifies a certain attribute change (e.g. checksum changed, name changed). A file can be considered equal if the returned set ofFileVersionComparator.FileChange
s 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileVersionComparator.FileChange
static class
FileVersionComparator.FileProperties
static class
FileVersionComparator.FileVersionComparison
-
Constructor Summary
Constructors Constructor Description FileVersionComparator(java.io.File rootFolder, java.lang.String checksumAlgorithm)
Creates a new file version comparator helper class.
-
Method Summary
-
-
-
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. ThechecksumAlgorithm
is used for calculate and compare file checksums. Both are used if a localFile
is compared to aFileVersion
.- Parameters:
rootFolder
- Base folder to determine a relative path tochecksumAlgorithm
- Digest algorithm for checksum calculation, e.g. "SHA1" or "MD5"
-
-
Method Detail
-
compare
public FileVersionComparator.FileVersionComparison compare(FileVersion expectedFileVersion, FileVersion actualFileVersion)
Compares twoFileVersion
s to each other and returns aFileVersionComparator.FileVersionComparison
object.- Parameters:
expectedFileVersion
- The expected file version (that is compared to the actual file version)actualFileVersion
- The actual file version (that is compared to the expected file version)- Returns:
- Returns a file version comparison object, indicating if there are differences between the file versions
-
compare
public FileVersionComparator.FileVersionComparison compare(FileVersion expectedFileVersion, java.io.File actualFile, boolean actualFileForceChecksum)
Compares aFileVersion
with a localFile
and returns aFileVersionComparator.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 totrue
.- 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 aFileVersion
with a localFile
and returns aFileVersionComparator.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 totrue
.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 setactualFileForceChecksum
- 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(FileVersionComparator.FileProperties expectedFileProperties, FileVersionComparator.FileProperties actualFileProperties, boolean compareChecksums)
-
captureFileProperties
public FileVersionComparator.FileProperties captureFileProperties(java.io.File file, FileContent.FileChecksum knownChecksum, boolean forceChecksum)
-
captureFileProperties
public FileVersionComparator.FileProperties captureFileProperties(FileVersion fileVersion)
-
-