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
|
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)
);
}
}
|