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: ModuleTableReport.java,v $
21  	$Date: 2009/08/22 10:30:42 $
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.Module;
29  import net.sf.statcvs.model.Repository;
30  import net.sf.statcvs.model.VersionedFile;
31  import net.sf.statcvs.reportmodel.IntegerColumn;
32  import net.sf.statcvs.reportmodel.SimpleTextColumn;
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 modules and the number of changes and LOC in them.
39   * 
40   * @author Benoit Xhenseval
41   * @version $Id: ModuleTableReport.java,v 1.2 2009/08/22 10:30:42 benoitx Exp $
42   */
43  public class ModuleTableReport implements TableReport {
44      private final Repository content;
45      private Table table = null;
46      private final IntegerMap filesMap = new IntegerMap();
47      private final IntegerMap changesMap = new IntegerMap();
48      private final IntegerMap linesMap = new IntegerMap();
49  
50      /**
51       * Creates a table report containing all modules and their
52       * respective number of changes and LOC.
53       * @param content the version control source data
54       */
55      public ModuleTableReport(final Repository content) {
56          this.content = content;
57      }
58  
59      public void calculate() {
60          Iterator it = this.content.getModules().values().iterator();
61          while (it.hasNext()) {
62              final Module mod = (Module) it.next();
63              //            final Directory dir = rev.getFile().getDirectory();
64              final Iterator files = mod.getFiles().iterator();
65              while (files.hasNext()) {
66                  final VersionedFile vf = (VersionedFile) files.next();
67                  filesMap.addInt(mod.getName(), 1);
68                  changesMap.addInt(mod.getName(), vf.getRevisions().size());
69              }
70              linesMap.addInt(mod.getName(), mod.getCurrentLinesOfCode());
71          }
72          this.table = new Table(Messages.getString("MODULES_TABLE_SUMMARY"));
73          final IntegerColumn changes = new IntegerColumn(Messages.getString("COLUMN_CHANGES"));
74          final IntegerColumn linesOfCode = new IntegerColumn(Messages.getString("COLUMN_LOC"));
75          final IntegerColumn filesCol = new IntegerColumn(Messages.getString("FILES"));
76          final SimpleTextColumn keys = new SimpleTextColumn(Messages.getString("COLUMN_MODULES"));
77          keys.setTotal(Messages.getString("TOTALS"));
78          changes.setShowPercentages(true);
79          linesOfCode.setShowPercentages(true);
80          this.table.addColumn(keys);
81          this.table.addColumn(filesCol);
82          this.table.addColumn(changes);
83          this.table.addColumn(linesOfCode);
84          this.table.setKeysInFirstColumn(true);
85  
86          it = linesMap.iteratorSortedByValueReverse();
87          while (it.hasNext()) {
88              final Object key = it.next();
89              keys.addValue(key);
90              changes.addValue(changesMap.get(key));
91              linesOfCode.addValue(linesMap.get(key));
92              filesCol.addValue(filesMap.get(key));
93          }
94          if (this.table.getRowCount() > 1) {
95              this.table.setShowTotals(true);
96          }
97      }
98  
99      public Table getTable() {
100         return table;
101     }
102 }