View Javadoc

1   /*
2   	StatCvs - CVS statistics generation 
3   	Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4   	http://statcvs.sf.net/
5       
6   	This library is free software; you can redistribute it and/or
7   	modify it under the terms of the GNU Lesser General Public
8   	License as published by the Free Software Foundation; either
9   	version 2.1 of the License, or (at your option) any later version.
10  
11  	This library is distributed in the hope that it will be useful,
12  	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  	Lesser General Public License for more details.
15  
16  	You should have received a copy of the GNU Lesser General Public
17  	License along with this library; if not, write to the Free Software
18  	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19      
20  	$RCSfile: RevisionData.java,v $
21  	$Date: 2008/04/02 11:22:15 $
22  */
23  package net.sf.statcvs.input;
24  
25  import java.util.Date;
26  
27  import net.sf.statcvs.util.CvsLogUtils;
28  
29  /**
30   * Container for all information contained in one CVS revisionNumber
31   * 
32   * @author Richard Cyganiak <richard@cyganiak.de>
33   * @version $Id: RevisionData.java,v 1.7 2008/04/02 11:22:15 benoitx Exp $
34   */
35  public class RevisionData {
36      private String revisionNumber;
37      private Date date;
38      private String loginName;
39      private boolean stateExp = false;
40      private boolean stateDead = false;
41      private boolean hasNoLines = true;
42      private int linesAdded;
43      private int linesRemoved;
44      private String comment;
45  
46      /**
47       * @return Returns the loginName.
48       */
49      public String getLoginName() {
50          return loginName;
51      }
52  
53      /**
54       * @param authorName The loginName to set.
55       */
56      public void setLoginName(final String authorName) {
57          this.loginName = authorName;
58      }
59  
60      /**
61       * @return Returns the date.
62       */
63      public Date getDate() {
64          return date;
65      }
66  
67      /**
68       * @param date The date to set.
69       */
70      public void setDate(final Date date) {
71          this.date = date;
72      }
73  
74      /**
75       * @return Returns the linesAdded.
76       */
77      public int getLinesAdded() {
78          return linesAdded;
79      }
80  
81      /**
82       * @return Returns the linesRemoved.
83       */
84      public int getLinesRemoved() {
85          return linesRemoved;
86      }
87  
88      /**
89       * Checks if the revision contains numbers for the added
90       * and removed lines.
91       * @return true if the revision contains numbers for the
92       * 		added and removed lines
93       */
94      public boolean hasNoLines() {
95          return hasNoLines;
96      }
97  
98      /**
99       * Sets the number of added and removed lines.
100      * @param added The number of added lines
101      * @param removed The number of removed lines
102      */
103     public void setLines(final int added, final int removed) {
104         this.linesAdded = added;
105         this.linesRemoved = removed;
106         hasNoLines = false;
107     }
108 
109     /**
110      * @return Returns the revisionNumber.
111      */
112     public String getRevisionNumber() {
113         return revisionNumber;
114     }
115 
116     /**
117      * Sets the revision number.
118      * @param revision The revision number
119      */
120     public void setRevisionNumber(final String revision) {
121         this.revisionNumber = revision;
122     }
123 
124     public void setStateDead() {
125         stateDead = true;
126     }
127 
128     public void setStateExp() {
129         stateExp = true;
130     }
131 
132     /**
133      * @return Returns the comment.
134      */
135     public String getComment() {
136         return comment;
137     }
138 
139     /**
140      * @param comment The comment to set.
141      */
142     public void setComment(final String comment) {
143         this.comment = comment;
144     }
145 
146     /**
147      * Returns <tt>true</tt> if this revisionNumber marks the adding of a new file
148      * on a subbranch. CVS creates a dead 1.1 revisionNumber on the trunk even if
149      * the file never gets merged into the trunk. If we evaluate the trunk,
150      * and the file doesn't have any other revisions on the trunk, then we
151      * ignore this revisionNumber.
152      *  
153      * @return <tt>true</tt> if this is the adding of a new file on a subbranch
154      */
155     public boolean isAddOnSubbranch() {
156         return stateDead && revisionNumber.equals("1.1");
157     }
158 
159     /**
160      * Returns <tt>true</tt> if this revisionNumber is the removal of a file.
161      * Any dead revisionNumber means that the file was removed. The only exception
162      * is a dead 1.1 revisionNumber, which is an add on a subbranch.
163      * 
164      * @return <tt>true</tt> if this revisionNumber deletes the file.
165      * @see #isAddOnSubbranch
166      */
167     public boolean isDeletion() {
168         return stateDead && !revisionNumber.equals("1.1");
169     }
170 
171     /**
172      * Returns <tt>true</tt> if this revisionNumber is a normal change, or if it
173      * restores a removed file. The distinction between these two cases
174      * can be made by looking at the previous (in time, not log order) revisionNumber.
175      * If it was a deletion, then this revisionNumber is a restore.
176      * 
177      * @return <tt>true</tt> if this is a normal change or a restore.
178      */
179     public boolean isChangeOrRestore() {
180         return stateExp && !hasNoLines;
181     }
182 
183     /**
184      * Returns <tt>true</tt> if this revisionNumber is the creation of a new file.
185      * 
186      * @return <tt>true</tt> if this is the creation of a new file.
187      */
188     public boolean isCreation() {
189         return stateExp && hasNoLines;
190     }
191 
192     /**
193      * Returns <tt>true</tt> if this revisionNumber is on the main branch.
194      * 
195      * @return <tt>true</tt> if this revisionNumber is on the main branch.
196      */
197     public boolean isOnTrunk() {
198         return CvsLogUtils.isOnMainBranch(revisionNumber);
199     }
200 
201     /**
202      * Returns <tt>true</tt> if this is an Exp revisionNumber.
203      * This is CVS speak for any "live" revisionNumber, that is, if this is
204      * the current revisionNumber, then a file exists in the working copy.
205      * 
206      * @return <tt>true</tt> if this is an Exp revisionNumber
207      */
208     public boolean isStateExp() {
209         return stateExp;
210     }
211 
212     /**
213      * Returns <tt>true</tt> if this is a dead revisionNumber. If this is the
214      * current revisionNumber, then the file does not exist in the working copy.
215      * 
216      * @return <tt>true</tt> if this is a dead revisionNumber
217      */
218     public boolean isStateDead() {
219         return stateDead;
220     }
221 
222     public String toString() {
223         return "RevisionData " + revisionNumber;
224     }
225 }