1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
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 copiedFiles;
private final long copiedBytes;
private final long totalBytes;
public static final IncCopyResult ZERO = new IncCopyResult(0, 0, 0, 0);
public IncCopyResult(int totalFiles, int copiedFiles, long copiedBytes, long totalBytes) {
this.totalFiles = totalFiles;
this.copiedFiles = copiedFiles;
this.copiedBytes = copiedBytes;
this.totalBytes = totalBytes;
}
/**
* 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 getCopiedFiles() {
return copiedFiles;
}
/**
* Get total bytes of new files added to the base.
*
* @return bytes.
*/
public long getCopiedBytes() {
return copiedBytes;
}
/**
* Get total bytes of all files in the collection. This equals to copied_files_bytes + reused_files_bytes.
*
* @return bytes.
*/
public long getTotalBytes() {
return totalBytes;
}
/**
* 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,
copiedFiles + a.copiedFiles,
copiedBytes + a.copiedBytes,
totalBytes + a.totalBytes
);
}
@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 &&
copiedFiles == that.copiedFiles &&
copiedBytes == that.copiedBytes &&
totalBytes == that.totalBytes;
}
@Override
public int hashCode() {
return Objects.hash(totalFiles, copiedFiles, copiedBytes, totalBytes);
}
@Override
public String toString() {
return String.format(
"File(s) added: %d (%s in size, totally %d files). Total backup-ed files size: %s (%.2f%% reused)",
copiedFiles,
BackupFilesystemUtil.getFriendlyFileSizeString(copiedBytes),
totalFiles,
BackupFilesystemUtil.getFriendlyFileSizeString(totalBytes),
(1 - 1.0f * copiedBytes / totalBytes) * 100
);
}
}
|