KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > changelog > RevisionsGroup


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.changelog;
22
23 import java.util.*;
24 import java.io.File JavaDoc;
25 import java.util.zip.*;
26
27 /**
28  *
29  * @author Milos Kleint, Raplh Krueger
30  */

31 public class RevisionsGroup {
32
33     public static final int SORTING_BY_DATE = 0;
34     public static final int SORTING_BY_FILE_NAME = 1;
35     public static final int SORTING_BY_TYPE = 2;
36
37     /** Holds value of property startingDate. */
38     private Date startingDate = null;
39
40     /** Holds value of property trailingDate. */
41     private Date trailingDate = null;
42
43     /** Holds value of property message. */
44     private String JavaDoc message = null;
45     
46     private List list;
47     
48     private long crcValue;
49     
50     /** Holds value of property user. */
51     private String JavaDoc user;
52     
53     /** Holds value of property commonBranch. */
54     private String JavaDoc commonBranch;
55     
56     RevisionsGroup() {
57         list = new LinkedList();
58         crcValue = 0;
59     }
60     
61     /** Getter for property startingDate.
62      * @return Value of property startingDate.
63      */

64     public Date getStartingDate() {
65         return this.startingDate;
66     }
67     
68     /** Setter for property startingDate.
69      * @param startingDate New value of property startingDate.
70      */

71     public void setStartingDate(Date startingDate) {
72         this.startingDate = startingDate;
73     }
74     
75     /** Getter for property trailingDate.
76      * @return Value of property trailingDate.
77      */

78     public Date getTrailingDate() {
79         return this.trailingDate;
80     }
81     
82     /** Setter for property trailingDate.
83      * @param trailingDate New value of property trailingDate.
84      */

85     public void setTrailingDate(Date trailingDate) {
86         this.trailingDate = trailingDate;
87     }
88
89     /** Getter for property message.
90      * @return Value of property message.
91      */

92     public String JavaDoc getMessage() {
93         return this.message;
94     }
95     
96     /** Setter for property message.
97      * @param message New value of property message.
98      */

99     public void setMessage(String JavaDoc message) {
100         this.message = message;
101     }
102     /** Getter for property user.
103      * @return Value of property user.
104      */

105     public String JavaDoc getUser() {
106         return this.user;
107     }
108     
109     /** Setter for property user.
110      * @param user New value of property user.
111      */

112     public void setUser(String JavaDoc user) {
113         this.user = user;
114     }
115     
116     public void addRevision(LogInfoRevision rev, String JavaDoc newMessage) {
117         if (getStartingDate() == null || rev.getDate().before(getStartingDate())) {
118             setStartingDate(rev.getDate());
119         }
120         if (getTrailingDate() == null || rev.getDate().after(getTrailingDate())) {
121             setTrailingDate(rev.getDate());
122         }
123         if (message == null) {
124             //first revision is added.
125
setMessage(newMessage);
126             setCRC32(computeCRC32(newMessage));
127             if (!rev.getBranch().equals("")) {
128                 setCommonBranch(rev.getBranch());
129             }
130         } else {
131             if (getCommonBranch() != null) {
132                 if (!getCommonBranch().equals(rev.getBranch())) {
133                     // not all revisions are on the same branch..
134
// reset common branch..
135
setCommonBranch(null);
136                 }
137             }
138         }
139         
140         if (user == null) {
141             setUser(rev.getAuthor());
142         }
143         list.add(rev);
144     }
145     
146     
147     public static long computeCRC32(String JavaDoc message) {
148         CRC32 crc = new CRC32();
149         byte[] bytes = message.getBytes();
150         crc.update(bytes);
151         return crc.getValue();
152     }
153     
154     void setCRC32(long crcValue) {
155         this.crcValue = crcValue;
156     }
157     
158     public long getCRC32() {
159         return crcValue;
160     }
161     
162     public List getList() {
163         return list;
164     }
165     
166     public List getSortedList(int sortingField) {
167         //TODO
168
return list;
169     }
170     
171     /** Getter for property commonBranch.
172      * @return Value of property commonBranch.
173      */

174     public String JavaDoc getCommonBranch() {
175         return this.commonBranch;
176     }
177     
178     /** Setter for property commonBranch.
179      * @param commonBranch New value of property commonBranch.
180      */

181     void setCommonBranch(String JavaDoc commonBranch) {
182         this.commonBranch = commonBranch;
183     }
184     
185     private static class FileNameRevComparator implements Comparator {
186         
187         public int compare(Object JavaDoc obj, Object JavaDoc obj1) {
188             LogInfoRevision rev1 = (LogInfoRevision)obj;
189             LogInfoRevision rev2 = (LogInfoRevision)obj1;
190             File JavaDoc file1 = rev1.getLogInfoHeader().getFile();
191             File JavaDoc file2 = rev2.getLogInfoHeader().getFile();
192             return file1.compareTo(file2);
193         }
194     }
195     
196     private static class TypeRevComparator implements Comparator {
197         
198         public int compare(Object JavaDoc obj, Object JavaDoc obj1) {
199             //TODO..
200
return 1;
201         }
202         
203     }
204     
205     public static class GroupDateComparator implements Comparator {
206         
207         private int descending;
208
209         public GroupDateComparator(boolean descending) {
210             this.descending = descending ? -1 : 1;
211         }
212         
213         public int compare(Object JavaDoc obj, Object JavaDoc obj1) {
214             if (!(obj instanceof RevisionsGroup) ||
215                 !(obj1 instanceof RevisionsGroup)) {
216                return 0;
217             }
218             RevisionsGroup gr1 = (RevisionsGroup)obj;
219             RevisionsGroup gr2 = (RevisionsGroup)obj1;
220             if (gr1.getStartingDate() == null) {
221                 return -1 * descending;
222             }
223             if (gr2.getStartingDate() == null) {
224                 return 1 * descending;
225             }
226             if (gr1.getStartingDate().before(gr2.getStartingDate())) {
227                 return -1 * descending;
228             }
229             if (gr1.getStartingDate().after(gr2.getStartingDate())) {
230                 return 1 * descending;
231             }
232             return 0;
233         }
234     }
235
236     
237     public static class UserDateComparator implements Comparator {
238         
239         private int descending;
240         private GroupDateComparator innerComp;
241
242         public UserDateComparator() {
243             this(false);
244         }
245         
246         public UserDateComparator(boolean descending) {
247             this.descending = descending ? -1 : 1;
248             innerComp = new RevisionsGroup.GroupDateComparator(false);
249         }
250         
251         public int compare(Object JavaDoc obj, Object JavaDoc obj1) {
252             if (!(obj instanceof RevisionsGroup) ||
253                 !(obj1 instanceof RevisionsGroup)) {
254                return 0;
255             }
256             RevisionsGroup gr1 = (RevisionsGroup)obj;
257             RevisionsGroup gr2 = (RevisionsGroup)obj1;
258             if (gr1.getUser() == null) {
259                 return -1 * descending;
260             }
261             if (gr2.getUser() == null) {
262                 return 1 * descending;
263             }
264             int toReturn = gr1.getUser().compareTo(gr2.getUser()) * descending;
265             if (toReturn == 0) {
266                 toReturn = innerComp.compare(obj, obj1);
267             }
268             return toReturn;
269         }
270     }
271     
272 }
273
Popular Tags