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 lines of code
40 *
41 * @author Richard Cyganiak <rcyg@gmx.de>
42 * @version $Id: LargestFilesTableReport.java,v 1.8 2008/04/02 11:22:15 benoitx Exp $
43 */
44 public class LargestFilesTableReport 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 largest files 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 LargestFilesTableReport(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 FilesLocComparator());
67 table = new Table(Messages.getString("LARGEST_FILES_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(Messages.getString("COLUMN_LOC"));
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 if (file.isDead()) {
81 continue;
82 }
83 filesCol.addValue(file);
84 locCol.addValue(file.getCurrentLinesOfCode());
85 lines++;
86 }
87 }
88
89 /**
90 * @see net.sf.statcvs.reports.TableReport#getTable()
91 */
92 public Table getTable() {
93 return table;
94 }
95 }