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.Directory;
29 import net.sf.statcvs.model.Repository;
30 import net.sf.statcvs.model.Revision;
31 import net.sf.statcvs.reportmodel.DirectoryColumn;
32 import net.sf.statcvs.reportmodel.IntegerColumn;
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 directories and the number of changes and LOC in them.
39 *
40 * @author Richard Cyganiak (richard@cyganiak.de)
41 * @version $Id: DirectoriesTableReport.java,v 1.6 2008/04/02 11:22:15 benoitx Exp $
42 */
43 public class DirectoriesTableReport implements TableReport {
44 private final Repository content;
45 private Table table = null;
46 private final IntegerMap changesMap = new IntegerMap();
47 private final IntegerMap linesMap = new IntegerMap();
48
49 /**
50 * Creates a table report containing all directories and their
51 * respective number of changes and LOC.
52 * @param content the version control source data
53 */
54 public DirectoriesTableReport(final Repository content) {
55 this.content = content;
56 }
57
58 public void calculate() {
59 Iterator it = this.content.getRevisions().iterator();
60 while (it.hasNext()) {
61 final Revision rev = (Revision) it.next();
62 final Directory dir = rev.getFile().getDirectory();
63 changesMap.addInt(dir, 1);
64 if (rev.isBeginOfLog()) {
65 linesMap.addInt(dir, rev.getLines());
66 } else {
67 linesMap.addInt(dir, rev.getLinesDelta());
68 }
69 }
70 this.table = new Table(Messages.getString("DIRECTORIES_TABLE_SUMMARY"));
71 final IntegerColumn changes = new IntegerColumn(Messages.getString("COLUMN_CHANGES"));
72 final IntegerColumn linesOfCode = new IntegerColumn(Messages.getString("COLUMN_LOC"));
73 final DirectoryColumn keys = new DirectoryColumn();
74 keys.setTotal(Messages.getString("TOTALS"));
75 changes.setShowPercentages(true);
76 linesOfCode.setShowPercentages(true);
77 this.table.addColumn(keys);
78 this.table.addColumn(changes);
79 this.table.addColumn(linesOfCode);
80 this.table.setKeysInFirstColumn(true);
81
82 it = linesMap.iteratorSortedByValueReverse();
83 while (it.hasNext()) {
84 final Object key = it.next();
85 keys.addValue(key);
86 changes.addValue(changesMap.get(key));
87 linesOfCode.addValue(linesMap.get(key));
88 }
89 if (this.table.getRowCount() > 1) {
90 this.table.setShowTotals(true);
91 }
92 }
93
94 public Table getTable() {
95 return table;
96 }
97 }