View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }