From 4a1d885afa7217b47d6183488c3dc6537cef05b6 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 23 Jan 2021 14:10:32 +0800 Subject: Version 1.4.6 (preview): added metadata for incremental backup (need integrated test and display implementation) --- .../backup/incremental/manager/IncCopyResult.java | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java') diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java new file mode 100644 index 0000000..6011ea5 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncCopyResult.java @@ -0,0 +1,105 @@ +package com.keuin.kbackupfabric.backup.incremental.manager; + +import com.keuin.kbackupfabric.backup.BackupFilesystemUtil; + +import java.util.Objects; + +/** + * Returned by `addObjectCollection` in IncrementalBackupStorageManager. + * Immutable. + */ +public class IncCopyResult { + + private final int totalFiles; + private final int filesCopied; + private final long bytesCopied; + private final long bytesTotal; + + public static final IncCopyResult ZERO = new IncCopyResult(0, 0, 0, 0); + + public IncCopyResult(int totalFiles, int filesCopied, long bytesCopied, long bytesTotal) { + this.totalFiles = totalFiles; + this.filesCopied = filesCopied; + this.bytesCopied = bytesCopied; + this.bytesTotal = bytesTotal; + } + + /** + * Get total files in the collection, containing reused files. + * + * @return file count. + */ + public int getTotalFiles() { + return totalFiles; + } + + /** + * Get new files added to the base. + * + * @return file count. + */ + public int getFilesCopied() { + return filesCopied; + } + + /** + * Get total bytes of new files added to the base. + * + * @return bytes. + */ + public long getBytesCopied() { + return bytesCopied; + } + + /** + * Get total bytes of all files in the collection. This equals to copied_files_bytes + reused_files_bytes. + * + * @return bytes. + */ + public long getBytesTotal() { + return bytesTotal; + } + + /** + * Add with another AddResult. + * + * @param a object. + * @return the add result. + */ + public IncCopyResult addWith(IncCopyResult a) { + Objects.requireNonNull(a); + return new IncCopyResult( + totalFiles + a.totalFiles, + filesCopied + a.filesCopied, + bytesCopied + a.bytesCopied, + bytesTotal + a.bytesTotal + ); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + IncCopyResult that = (IncCopyResult) o; + return totalFiles == that.totalFiles && + filesCopied == that.filesCopied && + bytesCopied == that.bytesCopied && + bytesTotal == that.bytesTotal; + } + + @Override + public int hashCode() { + return Objects.hash(totalFiles, filesCopied, bytesCopied, bytesTotal); + } + + @Override + public String toString() { + return String.format( + "Files copied: %d (%s in size, totally %d files). Total file tree size: %s.", + filesCopied, + BackupFilesystemUtil.getFriendlyFileSizeString(bytesCopied), + totalFiles, + BackupFilesystemUtil.getFriendlyFileSizeString(bytesTotal) + ); + } +} -- cgit v1.2.3