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