1 19 20 21 package org.netbeans.modules.changelog; 22 23 import java.util.*; 24 import java.io.File ; 25 import java.util.zip.*; 26 27 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 38 private Date startingDate = null; 39 40 41 private Date trailingDate = null; 42 43 44 private String message = null; 45 46 private List list; 47 48 private long crcValue; 49 50 51 private String user; 52 53 54 private String commonBranch; 55 56 RevisionsGroup() { 57 list = new LinkedList(); 58 crcValue = 0; 59 } 60 61 64 public Date getStartingDate() { 65 return this.startingDate; 66 } 67 68 71 public void setStartingDate(Date startingDate) { 72 this.startingDate = startingDate; 73 } 74 75 78 public Date getTrailingDate() { 79 return this.trailingDate; 80 } 81 82 85 public void setTrailingDate(Date trailingDate) { 86 this.trailingDate = trailingDate; 87 } 88 89 92 public String getMessage() { 93 return this.message; 94 } 95 96 99 public void setMessage(String message) { 100 this.message = message; 101 } 102 105 public String getUser() { 106 return this.user; 107 } 108 109 112 public void setUser(String user) { 113 this.user = user; 114 } 115 116 public void addRevision(LogInfoRevision rev, String 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 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 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 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 return list; 169 } 170 171 174 public String getCommonBranch() { 175 return this.commonBranch; 176 } 177 178 181 void setCommonBranch(String commonBranch) { 182 this.commonBranch = commonBranch; 183 } 184 185 private static class FileNameRevComparator implements Comparator { 186 187 public int compare(Object obj, Object obj1) { 188 LogInfoRevision rev1 = (LogInfoRevision)obj; 189 LogInfoRevision rev2 = (LogInfoRevision)obj1; 190 File file1 = rev1.getLogInfoHeader().getFile(); 191 File 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 obj, Object obj1) { 199 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 obj, Object 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 obj, Object 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 |