summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental/serializer/SavedIncBackupV1.java
blob: e34efdb46512ef5959c48fa50fb13336209c4fd2 (plain)
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
package com.keuin.kbackupfabric.backup.incremental.serializer;

import com.keuin.kbackupfabric.backup.BackupFilesystemUtil;
import com.keuin.kbackupfabric.backup.incremental.ObjectCollection2;
import com.keuin.kbackupfabric.util.DateUtil;

import java.io.Serializable;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

public class SavedIncBackupV1 implements SavedIncrementalBackup, Serializable {

    private static final long serialVersionUID = 5798490056955510205L;
    private final ObjectCollection2 objectCollection2;
    private final String backupName;
    private final ZonedDateTime backupTime;
    private final long totalSizeBytes;
    private final long increasedSizeBytes;
    private final int filesAdded;
    private final int totalFiles;
    // this field is depreciated and kept only for serialization compatibility
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");

    public SavedIncBackupV1(ObjectCollection2 objectCollection2, String backupName, ZonedDateTime backupTime, long totalSizeBytes, long increasedSizeBytes, int filesAdded, int totalFiles) {
        this.totalFiles = totalFiles;
        Objects.requireNonNull(objectCollection2);
        Objects.requireNonNull(backupName);
        Objects.requireNonNull(backupTime);
        this.objectCollection2 = objectCollection2;
        this.backupName = backupName;
        this.backupTime = backupTime;
        this.totalSizeBytes = totalSizeBytes;
        this.increasedSizeBytes = increasedSizeBytes;
        this.filesAdded = filesAdded;
    }

    @Override
    public ObjectCollection2 getObjectCollection() {
        return objectCollection2;
    }

    @Override
    public String getBackupName() {
        return backupName;
    }

    @Override
    public ZonedDateTime getBackupTime() {
        return backupTime;
    }

    @Override
    public int getFilesAdded() {
        return filesAdded;
    }

    @Override
    public long getTotalSizeBytes() {
        return totalSizeBytes;
    }

    @Override
    public long getIncreasedSizeBytes() {
        return increasedSizeBytes;
    }

    public int getTotalFiles() {
        return totalFiles;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SavedIncBackupV1 that = (SavedIncBackupV1) o;
        return totalSizeBytes == that.totalSizeBytes &&
                increasedSizeBytes == that.increasedSizeBytes &&
                filesAdded == that.filesAdded &&
                totalFiles == that.totalFiles &&
                objectCollection2.equals(that.objectCollection2) &&
                backupName.equals(that.backupName) &&
                backupTime.equals(that.backupTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(objectCollection2, backupName, backupTime, totalSizeBytes, increasedSizeBytes, filesAdded, totalFiles);
    }

    @Override
    public String toString() {
        return String.format(
                "%s, created at %s, files: %d (total size: %s), copied size: %s, files added: %d",
                backupName,
                DateUtil.getString(backupTime),
                totalFiles,
                BackupFilesystemUtil.getFriendlyFileSizeString(totalSizeBytes),
                BackupFilesystemUtil.getFriendlyFileSizeString(increasedSizeBytes),
                filesAdded
        );
    }
}