1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.file.model;
17
18 import java.util.List;
19
20 import org.kuali.common.util.Assert;
21
22 import com.google.common.collect.ImmutableList;
23
24 public final class Repository implements Comparable<Repository> {
25
26 public Repository(String name, List<RepoFile> files) {
27 Assert.noBlanks(name);
28 Assert.noNulls(files);
29 this.name = name;
30 this.files = ImmutableList.copyOf(files);
31 this.size = getTotalSize(files);
32 }
33
34 @Override
35 public int compareTo(Repository other) {
36 return Double.compare(size, other.getSize());
37 }
38
39 private long getTotalSize(List<RepoFile> files) {
40 long size = 0;
41 for (RepoFile file : files) {
42 size += file.getSize();
43 }
44 return size;
45 }
46
47 private final String name;
48 private final List<RepoFile> files;
49 private final long size;
50
51 public String getName() {
52 return name;
53 }
54
55 public List<RepoFile> getFiles() {
56 return files;
57 }
58
59 public long getSize() {
60 return size;
61 }
62
63 }