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.Collection;
26 import java.util.Iterator;
27
28 import net.sf.statcvs.Messages;
29 import net.sf.statcvs.model.Author;
30 import net.sf.statcvs.model.Directory;
31 import net.sf.statcvs.model.Repository;
32 import net.sf.statcvs.model.Revision;
33 import net.sf.statcvs.output.ReportConfig;
34 import net.sf.statcvs.reportmodel.GenericColumn;
35 import net.sf.statcvs.reportmodel.IntegerColumn;
36 import net.sf.statcvs.reportmodel.RatioColumn;
37 import net.sf.statcvs.reportmodel.Table;
38 import net.sf.statcvs.util.IntegerMap;
39
40 /**
41 * Convenience superclass for table reports related to authors and directories.
42 * Contains methods to calculate some common stuff for these tables.
43 * @author Lukasz Pekacki
44 * @version $Id: AbstractLocTableReport.java,v 1.12 2008/04/02 11:22:15 benoitx Exp $
45 */
46 public abstract class AbstractLocTableReport {
47
48 /**
49 * Sort the authors table by name
50 * */
51 public static final int SORT_BY_NAME = 0;
52
53 /**
54 * Sort the authors table by lines of code
55 * */
56 public static final int SORT_BY_LINES = 1;
57
58 private final ReportConfig config;
59 private final Repository content;
60
61 private final IntegerMap changesMap = new IntegerMap();
62 private final IntegerMap linesMap = new IntegerMap();
63
64 /**
65 * Constructor
66 * @param content render table on specified content
67 */
68 public AbstractLocTableReport(final ReportConfig config) {
69 this.config = config;
70 this.content = config.getRepository();
71 }
72
73 protected void calculateChangesAndLinesPerDeveloper(final Collection revs) {
74 final Iterator it = revs.iterator();
75 while (it.hasNext()) {
76 final Revision rev = (Revision) it.next();
77 if (rev.getAuthor() == null || !this.config.isDeveloper(rev.getAuthor())) {
78 continue;
79 }
80 changesMap.addInt(rev.getAuthor(), 1);
81 linesMap.addInt(rev.getAuthor(), rev.getNewLines());
82 }
83 }
84
85 protected void calculateChangesAndLinesPerDirectory(final Collection revisions) {
86 final Iterator it = revisions.iterator();
87 while (it.hasNext()) {
88 final Revision rev = (Revision) it.next();
89 final Directory dir = rev.getFile().getDirectory();
90 changesMap.addInt(dir, 1);
91 linesMap.addInt(dir, rev.getNewLines());
92 }
93 }
94
95 protected Table createChangesAndLinesTable(final GenericColumn keys, final GenericColumn keys2, final String summary) {
96
97 final Table result = new Table(summary);
98 final IntegerColumn changes = new IntegerColumn(Messages.getString("COLUMN_CHANGES"));
99 final IntegerColumn linesOfCode = new IntegerColumn(Messages.getString("COLUMN_LOC"));
100 final RatioColumn linesPerChange = new RatioColumn(Messages.getString("COLUMN_LOC_PER_CHANGE"), linesOfCode, changes);
101 keys.setTotal(Messages.getString("TOTALS"));
102 changes.setShowPercentages(true);
103 linesOfCode.setShowPercentages(true);
104 result.addColumn(keys);
105 if (keys2 != null) {
106 keys.setTotal("");
107 keys2.setTotal(Messages.getString("TOTALS"));
108 result.addColumn(keys2);
109 }
110 result.addColumn(changes);
111 result.addColumn(linesOfCode);
112 result.addColumn(linesPerChange);
113 result.setKeysInFirstColumn(true);
114
115 Iterator it;
116 it = linesMap.iteratorSortedByValueReverse();
117 while (it.hasNext()) {
118 final Object key = it.next();
119 keys.addValue(key);
120 if (keys2 != null) {
121 keys2.addValue(key);
122 }
123 changes.addValue(changesMap.get(key));
124 linesOfCode.addValue(linesMap.get(key));
125 }
126 if (result.getRowCount() > 1) {
127 result.setShowTotals(true);
128 }
129 return result;
130 }
131
132 protected Repository getContent() {
133 return content;
134 }
135
136 protected IntegerMap getChangesMap() {
137 return changesMap;
138 }
139
140 protected IntegerMap getLinesMap() {
141 return linesMap;
142 }
143
144 public int getDeveloperCount() {
145 int result = 0;
146 final Iterator it = getContent().getAuthors().iterator();
147 while (it.hasNext()) {
148 final Author author = (Author) it.next();
149 if (this.config.isDeveloper(author)) {
150 result++;
151 }
152 }
153 return result;
154 }
155 }