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.Iterator;
26
27 import net.sf.statcvs.Messages;
28 import net.sf.statcvs.model.Module;
29 import net.sf.statcvs.model.Repository;
30 import net.sf.statcvs.model.VersionedFile;
31 import net.sf.statcvs.reportmodel.IntegerColumn;
32 import net.sf.statcvs.reportmodel.SimpleTextColumn;
33 import net.sf.statcvs.reportmodel.Table;
34 import net.sf.statcvs.util.IntegerMap;
35
36 /**
37 * Table report which creates a table containing the names of
38 * all modules and the number of changes and LOC in them.
39 *
40 * @author Benoit Xhenseval
41 * @version $Id: ModuleTableReport.java,v 1.2 2009/08/22 10:30:42 benoitx Exp $
42 */
43 public class ModuleTableReport implements TableReport {
44 private final Repository content;
45 private Table table = null;
46 private final IntegerMap filesMap = new IntegerMap();
47 private final IntegerMap changesMap = new IntegerMap();
48 private final IntegerMap linesMap = new IntegerMap();
49
50 /**
51 * Creates a table report containing all modules and their
52 * respective number of changes and LOC.
53 * @param content the version control source data
54 */
55 public ModuleTableReport(final Repository content) {
56 this.content = content;
57 }
58
59 public void calculate() {
60 Iterator it = this.content.getModules().values().iterator();
61 while (it.hasNext()) {
62 final Module mod = (Module) it.next();
63
64 final Iterator files = mod.getFiles().iterator();
65 while (files.hasNext()) {
66 final VersionedFile vf = (VersionedFile) files.next();
67 filesMap.addInt(mod.getName(), 1);
68 changesMap.addInt(mod.getName(), vf.getRevisions().size());
69 }
70 linesMap.addInt(mod.getName(), mod.getCurrentLinesOfCode());
71 }
72 this.table = new Table(Messages.getString("MODULES_TABLE_SUMMARY"));
73 final IntegerColumn changes = new IntegerColumn(Messages.getString("COLUMN_CHANGES"));
74 final IntegerColumn linesOfCode = new IntegerColumn(Messages.getString("COLUMN_LOC"));
75 final IntegerColumn filesCol = new IntegerColumn(Messages.getString("FILES"));
76 final SimpleTextColumn keys = new SimpleTextColumn(Messages.getString("COLUMN_MODULES"));
77 keys.setTotal(Messages.getString("TOTALS"));
78 changes.setShowPercentages(true);
79 linesOfCode.setShowPercentages(true);
80 this.table.addColumn(keys);
81 this.table.addColumn(filesCol);
82 this.table.addColumn(changes);
83 this.table.addColumn(linesOfCode);
84 this.table.setKeysInFirstColumn(true);
85
86 it = linesMap.iteratorSortedByValueReverse();
87 while (it.hasNext()) {
88 final Object key = it.next();
89 keys.addValue(key);
90 changes.addValue(changesMap.get(key));
91 linesOfCode.addValue(linesMap.get(key));
92 filesCol.addValue(filesMap.get(key));
93 }
94 if (this.table.getRowCount() > 1) {
95 this.table.setShowTotals(true);
96 }
97 }
98
99 public Table getTable() {
100 return table;
101 }
102 }