]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/acr/fs/SyncResult.java
1 package org
.argeo
.cms
.acr
.fs
;
3 import java
.time
.Instant
;
5 import java
.util
.TreeSet
;
7 /** Describes what happendend during a sync operation. */
8 public class SyncResult
<T
> {
9 private final Set
<T
> added
= new TreeSet
<>();
10 private final Set
<T
> modified
= new TreeSet
<>();
11 private final Set
<T
> deleted
= new TreeSet
<>();
12 private final Set
<Error
> errors
= new TreeSet
<>();
14 public Set
<T
> getAdded() {
18 public Set
<T
> getModified() {
22 public Set
<T
> getDeleted() {
26 public Set
<Error
> getErrors() {
30 public void addError(T sourcePath
, T targetPath
, Exception e
) {
31 Error error
= new Error(sourcePath
, targetPath
, e
);
35 public boolean noModification() {
36 return modified
.isEmpty() && deleted
.isEmpty() && added
.isEmpty();
40 public String
toString() {
42 return "No modification.";
43 StringBuffer sb
= new StringBuffer();
45 sb
.append("MOD ").append(p
).append('\n');
47 sb
.append("DEL ").append(p
).append('\n');
49 sb
.append("ADD ").append(p
).append('\n');
50 for (Error error
: errors
)
51 sb
.append(error
).append('\n');
55 public class Error
implements Comparable
<Error
> {
56 private final T sourcePath
;// if null this is a failed delete
57 private final T targetPath
;
58 private final Exception exception
;
59 private final Instant timestamp
= Instant
.now();
61 public Error(T sourcePath
, T targetPath
, Exception e
) {
63 this.sourcePath
= sourcePath
;
64 this.targetPath
= targetPath
;
68 public T
getSourcePath() {
72 public T
getTargetPath() {
76 public Exception
getException() {
80 public Instant
getTimestamp() {
85 public int compareTo(Error o
) {
86 return timestamp
.compareTo(o
.timestamp
);
90 public int hashCode() {
91 return timestamp
.hashCode();
95 public String
toString() {
96 return "ERR " + timestamp
+ (sourcePath
== null ?
"Deletion failed" : "Copy failed " + sourcePath
) + " "
97 + targetPath
+ " " + exception
.getMessage();