summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/IncrementalBackupFeedback.java
blob: 696ee024c832b373ec933df1998b6f2ffe208d32 (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
package com.keuin.kbackupfabric.operation.backup.feedback;

import com.keuin.kbackupfabric.backup.incremental.manager.IncCopyResult;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class IncrementalBackupFeedback implements BackupFeedback {
    private final boolean success;
    private final IncCopyResult copyResult;
    // if the backup failed because of an exception, set this.
    // Otherwise, this should be null.
    private final Throwable throwable;

    public IncrementalBackupFeedback(boolean success, @Nullable IncCopyResult copyResult) {
        this.success = success;
        this.copyResult = copyResult;
        this.throwable = null;
    }

    /**
     * Create a failed backup feedback caused by an exception.
     *
     * @param t the exception.
     */
    public IncrementalBackupFeedback(Throwable t) {
        Objects.requireNonNull(t);
        this.success = false;
        this.copyResult = null;
        this.throwable = t;
    }

    @Override
    public boolean isSuccess() {
        return success;
    }

    public IncCopyResult getCopyResult() {
        return copyResult;
    }

    @Override
    public String getFeedback() {
        if (success && copyResult != null)
            return copyResult.toString();
        else
            return (throwable == null) ? "No further information." : (throwable.getLocalizedMessage());
    }
}