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
38
39
40
41
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
51
52
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 }