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.statcvs.reports;
24
25 import java.io.Serializable;
26 import java.util.Comparator;
27 import java.util.Iterator;
28
29 import net.sf.statcvs.model.Revision;
30 import net.sf.statcvs.model.VersionedFile;
31
32 /**
33 * Compares two files according to their number of changes (revisions).
34 * If two files have the same number of changes, the number of changed
35 * lines of code is used.
36 *
37 * @author Richard Cyganiak <rcyg@gmx.de>
38 * @version $Id: FilesRevisionCountComparator.java,v 1.6 2009/08/20 17:44:05 benoitx Exp $
39 */
40 public class FilesRevisionCountComparator implements Comparator, Serializable {
41
42 /**
43 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
44 */
45 public int compare(final Object o1, final Object o2) {
46 final VersionedFile file1 = (VersionedFile) o1;
47 final VersionedFile file2 = (VersionedFile) o2;
48 if (file1.getRevisions().size() < file2.getRevisions().size()) {
49 return 2;
50 } else if (file1.getRevisions().size() > file2.getRevisions().size()) {
51 return -2;
52 } else {
53 int lines1 = 0;
54 Iterator it = file1.getRevisions().iterator();
55 while (it.hasNext()) {
56 final Revision rev = (Revision) it.next();
57 lines1 += rev.getNewLines();
58 }
59 int lines2 = 0;
60 it = file2.getRevisions().iterator();
61 while (it.hasNext()) {
62 final Revision rev = (Revision) it.next();
63 lines2 += rev.getNewLines();
64 }
65 if (lines1 < lines2) {
66 return 1;
67 } else if (lines1 > lines2) {
68 return -1;
69 } else {
70 return 0;
71 }
72 }
73 }
74 }