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.ArrayList;
26 import java.util.Collections;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.SortedSet;
30
31 import net.sf.statcvs.Messages;
32 import net.sf.statcvs.model.VersionedFile;
33 import net.sf.statcvs.output.ReportConfig;
34 import net.sf.statcvs.reportmodel.FileColumn;
35 import net.sf.statcvs.reportmodel.IntegerColumn;
36 import net.sf.statcvs.reportmodel.Table;
37
38 /**
39 * Table report for a table containing the files with most changes
40 *
41 * @author Richard Cyganiak <rcyg@gmx.de>
42 * @version $Id: FilesWithMostRevisionsTableReport.java,v 1.7 2008/04/02 11:22:15 benoitx Exp $
43 */
44 public class FilesWithMostRevisionsTableReport implements TableReport {
45 private final ReportConfig config;
46 private final List files;
47 private Table table;
48 private final int maxRows;
49
50 /**
51 * Creates a table containing the files with most changes from a file list
52 * @param files a <tt>SortedSet</tt> of
53 * {@link net.sf.statcvs.model.VersionedFile}s
54 * @param maxRows the maximum number of files displayed in the table
55 */
56 public FilesWithMostRevisionsTableReport(final ReportConfig config, final SortedSet files, final int maxRows) {
57 this.config = config;
58 this.files = new ArrayList(files);
59 this.maxRows = maxRows;
60 }
61
62 /**
63 * @see net.sf.statcvs.reports.TableReport#calculate()
64 */
65 public void calculate() {
66 Collections.sort(files, new FilesRevisionCountComparator());
67 table = new Table(Messages.getString("FILES_WITH_MOST_REVISIONS_TABLE_SUMMARY"));
68 table.setKeysInFirstColumn(true);
69 final FileColumn filesCol = new FileColumn();
70 filesCol.setWithIcon(true);
71 filesCol.setWebRepository(this.config.getWebRepository());
72 final IntegerColumn locCol = new IntegerColumn("Revisions");
73 locCol.setShowPercentages(false);
74 table.addColumn(filesCol);
75 table.addColumn(locCol);
76 int lines = 0;
77 final Iterator it = files.iterator();
78 while (it.hasNext() && lines < maxRows) {
79 final VersionedFile file = (VersionedFile) it.next();
80 filesCol.addValue(file);
81 locCol.addValue(file.getRevisions().size());
82 lines++;
83 }
84 }
85
86 /**
87 * @see net.sf.statcvs.reports.TableReport#getTable()
88 */
89 public Table getTable() {
90 return table;
91 }
92 }