diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-06-22 11:47:21 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2021-06-22 11:47:21 +0200 |
commit | 033ca455c429af74c27037db184470f7dcf02f21 (patch) | |
tree | 2b941d791669383d24ab73954587d96fe402bd58 /filedistribution/src/main/java/com/yahoo/vespa | |
parent | 98e925d48b4e685ad88604d0a574b00f232ec3a9 (diff) |
Make DownloadStatus immutable
Diffstat (limited to 'filedistribution/src/main/java/com/yahoo/vespa')
-rw-r--r-- | filedistribution/src/main/java/com/yahoo/vespa/filedistribution/Downloads.java | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/Downloads.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/Downloads.java index ba5693a1efb..eab6cd39352 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/Downloads.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/Downloads.java @@ -30,11 +30,7 @@ public class Downloads { public DownloadStatuses downloadStatuses() { return downloadStatuses; } void setDownloadStatus(FileReference fileReference, double completeness) { - Optional<Downloads.DownloadStatus> downloadStatus = downloadStatuses.get(fileReference); - if (downloadStatus.isPresent()) - downloadStatus.get().setProgress(completeness); - else - downloadStatuses.add(fileReference, completeness); + downloadStatuses.put(fileReference, completeness); } void completedDownloading(FileReference fileReference, File file) { @@ -50,11 +46,11 @@ public class Downloads { void add(FileReferenceDownload fileReferenceDownload) { downloads.put(fileReferenceDownload.fileReference(), fileReferenceDownload); - downloadStatuses.add(fileReferenceDownload.fileReference()); + downloadStatuses.put(fileReferenceDownload.fileReference()); } void remove(FileReference fileReference) { - downloadStatuses.get(fileReference).ifPresent(d -> d.setProgress(0.0)); + downloadStatuses.get(fileReference).ifPresent(d -> new DownloadStatus(d.fileReference(), 0.0)); downloads.remove(fileReference); } @@ -82,11 +78,11 @@ public class Downloads { private final Map<FileReference, DownloadStatus> downloadStatus = Collections.synchronizedMap(new HashMap<>()); - void add(FileReference fileReference) { - add(fileReference, 0.0); + void put(FileReference fileReference) { + put(fileReference, 0.0); } - void add(FileReference fileReference, double progress) { + void put(FileReference fileReference, double progress) { downloadStatus.put(fileReference, new DownloadStatus(fileReference, progress)); if (downloadStatus.size() > maxEntries) { Map.Entry<FileReference, DownloadStatus> oldest = @@ -112,7 +108,7 @@ public class Downloads { static class DownloadStatus { private final FileReference fileReference; - private double progress; // between 0 and 1 + private final double progress; // between 0 and 1 private final Instant created; DownloadStatus(FileReference fileReference, double progress) { @@ -129,14 +125,6 @@ public class Downloads { return progress; } - public void setProgress(double progress) { - this.progress = progress; - } - - public void finished() { - setProgress(1.0); - } - public Instant created() { return created; } |