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: DirectoriesTableReport.java,v $
21  	$Date: 2008/04/02 11:22:15 $
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   * Table report which creates a table containing the names of
38   * all directories and the number of changes and LOC in them.
39   * 
40   * @author Richard Cyganiak (richard@cyganiak.de)
41   * @version $Id: DirectoriesTableReport.java,v 1.6 2008/04/02 11:22:15 benoitx Exp $
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       * Creates a table report containing all directories and their
51       * respective number of changes and LOC.
52       * @param content the version control source data
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  }