1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statsvn.input;
24
25 import java.util.Date;
26
27 /**
28 * Container for all information contained in one SVN revision.
29 *
30 * @author Richard Cyganiak <richard@cyganiak.de> *
31 * @author Gunter Mussbacher <gunterm@site.uottawa.ca>
32 * @author Jason Kealey <jkealey@shade.ca>
33 *
34 * @version $Id: RevisionData.java 351 2008-03-28 18:46:26Z benoitx $
35 */
36 public class RevisionData {
37 private String revisionNumber;
38
39 private Date date;
40
41 private String loginName;
42
43 private boolean stateExp = false;
44
45 private boolean stateDead = false;
46
47 private boolean stateAdded = false;
48
49 private boolean hasNoLines = true;
50
51 private int linesAdded;
52
53 private int linesRemoved;
54
55 private String comment = "";
56
57 private String copyfromPath;
58
59 private String copyfromRevision;
60
61 public RevisionData() {
62 }
63
64 /**
65 * @return Returns the loginName.
66 */
67 public String getLoginName() {
68 return loginName;
69 }
70
71 /**
72 * @param authorName
73 * The loginName to set.
74 */
75 public void setLoginName(final String authorName) {
76 this.loginName = authorName;
77 }
78
79 /**
80 * @return Returns the date.
81 */
82 public Date getDate() {
83 return date != null ? new Date(date.getTime()) : null;
84 }
85
86 /**
87 * @param date
88 * The date to set.
89 */
90 public void setDate(final Date date) {
91 if (date != null) {
92 this.date = new Date(date.getTime());
93 } else {
94 this.date = null;
95 }
96 }
97
98 /**
99 * @return Returns the linesAdded.
100 */
101 public int getLinesAdded() {
102 return linesAdded;
103 }
104
105 /**
106 * @return Returns the linesRemoved.
107 */
108 public int getLinesRemoved() {
109 return linesRemoved;
110 }
111
112 /**
113 * Checks if the revision contains numbers for the added and removed lines.
114 *
115 * @return true if the revision contains numbers for the added and removed lines
116 */
117 public boolean hasNoLines() {
118 return hasNoLines;
119 }
120
121 /**
122 * Sets the number of added and removed lines.
123 *
124 * @param added
125 * The number of added lines
126 * @param removed
127 * The number of removed lines
128 */
129 public void setLines(final int added, final int removed) {
130 this.linesAdded = added;
131 this.linesRemoved = removed;
132 hasNoLines = false;
133 }
134
135 /**
136 * @return Returns the revisionNumber.
137 */
138 public String getRevisionNumber() {
139 return revisionNumber;
140 }
141
142 /**
143 * Sets the revision number.
144 *
145 * @param revision
146 * The revision number
147 */
148 public void setRevisionNumber(final String revision) {
149 this.revisionNumber = revision;
150 }
151
152 /**
153 * Is this revision a deletion?
154 *
155 * @param isDead
156 * <tt>true</tt> if revision is a deletion.
157 */
158 public void setStateDead(final boolean isDead) {
159 stateDead = isDead;
160 }
161
162 /**
163 * Is the revision exposed. This is CVS speak for any "live" revisionNumber, that is, if this is the current revisionNumber, then a file exists in the
164 * working copy.
165 *
166 * New in StatSVN: We use it to mean this revision is not a deletion revision. (modify, add or replace)
167 *
168 * @param isExposed
169 * <tt>true</tt> true if the revision is not a deletion.
170 */
171 public void setStateExp(final boolean isExposed) {
172 stateExp = isExposed;
173 }
174
175 /**
176 * Is this revision an addition?
177 *
178 * New in StatSVN: This is no longer a still exists in working copy. We use it to mean this revision is not a deletion revision.
179 *
180 * @param isAdded
181 */
182 public void setStateAdded(final boolean isAdded) {
183 stateAdded = isAdded;
184 }
185
186 /**
187 * @return Returns the comment.
188 */
189 public String getComment() {
190 return comment;
191 }
192
193 /**
194 * @param comment
195 * The comment to set.
196 */
197 public void setComment(final String comment) {
198 this.comment = comment;
199 }
200
201 /**
202 * Returns <tt>true</tt> if this revisionNumber is the removal of a file.
203 *
204 * @return <tt>true</tt> if this revisionNumber deletes the file.
205 *
206 */
207 public boolean isDeletion() {
208 return stateDead;
209 }
210
211 /**
212 * Returns <tt>true</tt> if this revisionNumber is a normal change.
213 *
214 * New in StatSVN: This was isChangeOrRestore before.
215 *
216 * @return <tt>true</tt> if this is a normal change or a restore.
217 */
218 public boolean isChange() {
219
220 return stateExp && !stateAdded;
221 }
222
223 /**
224 * Returns <tt>true</tt> if this revisionNumber is the creation of a new file or a restore.. The distinction between these two cases can be made by
225 * looking at the previous (in time, not log order) revisionNumber. If it was a deletion, then this revisionNumber is a restore.
226 *
227 * New in StatSVN: This was isCreation before.
228 *
229 * @return <tt>true</tt> if this is the creation of a new file.
230 */
231 public boolean isCreationOrRestore() {
232
233 return stateExp && stateAdded;
234 }
235
236 /**
237 * Returns <tt>true</tt> if this is an Exp ("exposed"?) revisionNumber. This is CVS speak for any "live" revisionNumber, that is, if this is the current
238 * revisionNumber, then a file exists in the working copy.
239 *
240 * New in StatSVN: We use it to mean this revision is not a deletion revision. (modify, add or replace)
241 *
242 * @return <tt>true</tt> if this is an Exp revisionNumber
243 */
244 public boolean isStateExp() {
245 return stateExp;
246 }
247
248 /**
249 * Returns <tt>true</tt> if this is a dead revisionNumber. If this is the current revisionNumber, then the file does not exist in the working copy.
250 *
251 * @return <tt>true</tt> if this is a dead revisionNumber
252 */
253 public boolean isStateDead() {
254 return stateDead;
255 }
256
257 /**
258 * Returns the current revision data in string format.
259 */
260 public String toString() {
261 return "RevisionData " + revisionNumber;
262 }
263
264 /**
265 * Returns a new instance of the RevisionData, with the same fields as the current one.
266 *
267 * @return the clone
268 */
269 public RevisionData createCopy() {
270 final RevisionData copy = new RevisionData(revisionNumber, date, stateExp, stateDead, stateAdded, hasNoLines, linesAdded, linesRemoved);
271 copy.setComment(comment);
272 copy.setLoginName(loginName);
273 return copy;
274 }
275
276 /**
277 * Private constructor used by (@link #clone())
278 *
279 * @param revisionNumber
280 * the revision number
281 * @param date
282 * the revision date
283 * @param stateExp
284 * if this were the current revision, would the file still be live (not-dead)
285 * @param stateDead
286 * is this a deletion revision
287 * @param stateAdded
288 * is this an addition revision
289 * @param hasNoLines
290 * have we set the line counts?
291 * @param linesAdded
292 * number of lines added
293 * @param linesRemoved
294 * number of lines removed
295 */
296 private RevisionData(final String revisionNumber, final Date date, final boolean stateExp, final boolean stateDead, final boolean stateAdded,
297 final boolean hasNoLines, final int linesAdded, final int linesRemoved) {
298 super();
299 this.revisionNumber = revisionNumber;
300 this.date = date;
301 this.stateExp = stateExp;
302 this.stateDead = stateDead;
303 this.hasNoLines = hasNoLines;
304 this.linesAdded = linesAdded;
305 this.linesRemoved = linesRemoved;
306 this.stateAdded = stateAdded;
307 }
308
309 public String getCopyfromPath() {
310 return copyfromPath;
311 }
312
313 public void setCopyfromPath(final String copyfromPath) {
314 this.copyfromPath = copyfromPath;
315 }
316
317 public String getCopyfromRevision() {
318 return copyfromRevision;
319 }
320
321 public void setCopyfromRevision(final String copyfromRevision) {
322 this.copyfromRevision = copyfromRevision;
323 }
324
325 }