1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.statcvs.model;
21
22 import java.util.Date;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.SortedSet;
26 import java.util.TreeSet;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class Repository {
42 private final SortedSet files = new TreeSet();
43 private final SortedSet authors = new TreeSet();
44 private final SortedSet revisions = new TreeSet();
45 private Directory root = null;
46 private Date firstDate = null;
47 private Date lastDate = null;
48 private List commits;
49 private SortedSet symbolicNames = new TreeSet();
50 private final SymbolicName head = new SymbolicName("@");
51
52
53
54
55
56 public void addFile(final VersionedFile file) {
57 files.add(file);
58 final Iterator it = file.getRevisions().iterator();
59 while (it.hasNext()) {
60 final Revision revision = (Revision) it.next();
61 revisions.add(revision);
62 if (revision.getAuthor() != null) {
63 authors.add(revision.getAuthor());
64 }
65 adjustStartAndEndDate(revision.getDate());
66 }
67 if (root == null) {
68 initRoot();
69 }
70 if (!file.isDead()) {
71 this.head.addRevision(file.getLatestRevision());
72 }
73 }
74
75
76
77
78
79
80
81
82 public void setCommits(final List commits) {
83 this.commits = commits;
84 }
85
86
87
88
89
90
91 public List getCommits() {
92 return commits;
93 }
94
95
96
97
98
99
100
101 public Date getLastDate() {
102 return lastDate;
103 }
104
105
106
107
108
109
110
111 public Date getFirstDate() {
112 return firstDate;
113 }
114
115
116
117
118
119 public int getCurrentLOC() {
120 int result = 0;
121 final Iterator it = files.iterator();
122 while (it.hasNext()) {
123 final VersionedFile file = (VersionedFile) it.next();
124 result += file.getCurrentLinesOfCode();
125 }
126 return result;
127 }
128
129
130
131
132
133 public SortedSet getFiles() {
134 return files;
135 }
136
137
138
139
140
141 public boolean isEmpty() {
142 return (files.isEmpty());
143 }
144
145
146
147
148
149
150
151 public SortedSet getRevisions() {
152 return revisions;
153 }
154
155
156
157
158
159
160 public SortedSet getDirectories() {
161 return getRoot().getSubdirectoriesRecursive();
162 }
163
164
165
166
167
168
169 public Directory getRoot() {
170 return root;
171 }
172
173
174
175
176
177 public void setSymbolicNames(final SortedSet symbolicNames) {
178 this.symbolicNames = symbolicNames;
179 }
180
181
182
183
184
185 public SortedSet getSymbolicNames() {
186 return symbolicNames;
187 }
188
189
190
191
192 public SymbolicName getHead() {
193 return this.head;
194 }
195
196
197
198
199 public String toString() {
200 final StringBuffer result = new StringBuffer();
201 final Iterator it = files.iterator();
202 VersionedFile cf = null;
203 while (it.hasNext()) {
204 cf = (VersionedFile) it.next();
205 result.append(cf.toString()).append("\n");
206 }
207 return result.toString();
208 }
209
210
211
212
213
214
215 public SortedSet getAuthors() {
216 return authors;
217 }
218
219 private void initRoot() {
220 if (files.isEmpty()) {
221 return;
222 }
223 final VersionedFile file = (VersionedFile) files.first();
224 Directory dir = file.getDirectory();
225 while (!dir.isRoot()) {
226 dir = dir.getParent();
227 }
228 root = dir;
229 }
230
231 private void adjustStartAndEndDate(final Date revisionDate) {
232 if (revisionDate == null) {
233 return;
234 }
235 if (firstDate == null || firstDate.compareTo(revisionDate) > 0) {
236 firstDate = revisionDate;
237 }
238 if (lastDate == null || lastDate.compareTo(revisionDate) < 0) {
239 lastDate = revisionDate;
240 }
241 }
242 }