View Javadoc

1   /*
2   	StatCvs - CVS statistics generation 
3   	Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4   	http://statcvs.sf.net/
5       
6   	This library is free software; you can redistribute it and/or
7   	modify it under the terms of the GNU Lesser General Public
8   	License as published by the Free Software Foundation; either
9   	version 2.1 of the License, or (at your option) any later version.
10  
11  	This library is distributed in the hope that it will be useful,
12  	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  	Lesser General Public License for more details.
15  
16  	You should have received a copy of the GNU Lesser General Public
17  	License along with this library; if not, write to the Free Software
18  	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19      
20  	$RCSfile: FilesWithMostRevisionsTableReport.java,v $
21  	$Date: 2008/04/02 11:22:15 $
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  }