Coverage Report - net.sf.statcvs.reports.AbstractLocTableReport
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractLocTableReport
0%
0/62
0%
0/20
2.125
 
 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: AbstractLocTableReport.java,v $ 
 21  
         Created on $Date: 2008/04/02 11:22:15 $ 
 22  
 */
 23  
 package net.sf.statcvs.reports;
 24  
 
 25  
 import java.util.Collection;
 26  
 import java.util.Iterator;
 27  
 
 28  
 import net.sf.statcvs.Messages;
 29  
 import net.sf.statcvs.model.Author;
 30  
 import net.sf.statcvs.model.Directory;
 31  
 import net.sf.statcvs.model.Repository;
 32  
 import net.sf.statcvs.model.Revision;
 33  
 import net.sf.statcvs.output.ReportConfig;
 34  
 import net.sf.statcvs.reportmodel.GenericColumn;
 35  
 import net.sf.statcvs.reportmodel.IntegerColumn;
 36  
 import net.sf.statcvs.reportmodel.RatioColumn;
 37  
 import net.sf.statcvs.reportmodel.Table;
 38  
 import net.sf.statcvs.util.IntegerMap;
 39  
 
 40  
 /**
 41  
  * Convenience superclass for table reports related to authors and directories.
 42  
  * Contains methods to calculate some common stuff for these tables.
 43  
  * @author Lukasz Pekacki
 44  
  * @version $Id: AbstractLocTableReport.java,v 1.12 2008/04/02 11:22:15 benoitx Exp $
 45  
  */
 46  
 public abstract class AbstractLocTableReport {
 47  
 
 48  
     /**
 49  
      * Sort the authors table by name
 50  
      * */
 51  
     public static final int SORT_BY_NAME = 0;
 52  
 
 53  
     /**
 54  
      * Sort the authors table by lines of code
 55  
      * */
 56  
     public static final int SORT_BY_LINES = 1;
 57  
 
 58  
     private final ReportConfig config;
 59  
     private final Repository content;
 60  
 
 61  0
     private final IntegerMap changesMap = new IntegerMap();
 62  0
     private final IntegerMap linesMap = new IntegerMap();
 63  
 
 64  
     /**
 65  
      * Constructor
 66  
      * @param content render table on specified content
 67  
      */
 68  0
     public AbstractLocTableReport(final ReportConfig config) {
 69  0
         this.config = config;
 70  0
         this.content = config.getRepository();
 71  0
     }
 72  
 
 73  
     protected void calculateChangesAndLinesPerDeveloper(final Collection revs) {
 74  0
         final Iterator it = revs.iterator();
 75  0
         while (it.hasNext()) {
 76  0
             final Revision rev = (Revision) it.next();
 77  0
             if (rev.getAuthor() == null || !this.config.isDeveloper(rev.getAuthor())) {
 78  0
                 continue;
 79  
             }
 80  0
             changesMap.addInt(rev.getAuthor(), 1);
 81  0
             linesMap.addInt(rev.getAuthor(), rev.getNewLines());
 82  0
         }
 83  0
     }
 84  
 
 85  
     protected void calculateChangesAndLinesPerDirectory(final Collection revisions) {
 86  0
         final Iterator it = revisions.iterator();
 87  0
         while (it.hasNext()) {
 88  0
             final Revision rev = (Revision) it.next();
 89  0
             final Directory dir = rev.getFile().getDirectory();
 90  0
             changesMap.addInt(dir, 1);
 91  0
             linesMap.addInt(dir, rev.getNewLines());
 92  0
         }
 93  0
     }
 94  
 
 95  
     protected Table createChangesAndLinesTable(final GenericColumn keys, final GenericColumn keys2, final String summary) {
 96  
 
 97  0
         final Table result = new Table(summary);
 98  0
         final IntegerColumn changes = new IntegerColumn(Messages.getString("COLUMN_CHANGES"));
 99  0
         final IntegerColumn linesOfCode = new IntegerColumn(Messages.getString("COLUMN_LOC"));
 100  0
         final RatioColumn linesPerChange = new RatioColumn(Messages.getString("COLUMN_LOC_PER_CHANGE"), linesOfCode, changes);
 101  0
         keys.setTotal(Messages.getString("TOTALS"));
 102  0
         changes.setShowPercentages(true);
 103  0
         linesOfCode.setShowPercentages(true);
 104  0
         result.addColumn(keys);
 105  0
         if (keys2 != null) {
 106  0
             keys.setTotal("");
 107  0
             keys2.setTotal(Messages.getString("TOTALS"));
 108  0
             result.addColumn(keys2);
 109  
         }
 110  0
         result.addColumn(changes);
 111  0
         result.addColumn(linesOfCode);
 112  0
         result.addColumn(linesPerChange);
 113  0
         result.setKeysInFirstColumn(true);
 114  
 
 115  
         Iterator it;
 116  0
         it = linesMap.iteratorSortedByValueReverse();
 117  0
         while (it.hasNext()) {
 118  0
             final Object key = it.next();
 119  0
             keys.addValue(key);
 120  0
             if (keys2 != null) {
 121  0
                 keys2.addValue(key);
 122  
             }
 123  0
             changes.addValue(changesMap.get(key));
 124  0
             linesOfCode.addValue(linesMap.get(key));
 125  0
         }
 126  0
         if (result.getRowCount() > 1) {
 127  0
             result.setShowTotals(true);
 128  
         }
 129  0
         return result;
 130  
     }
 131  
 
 132  
     protected Repository getContent() {
 133  0
         return content;
 134  
     }
 135  
 
 136  
     protected IntegerMap getChangesMap() {
 137  0
         return changesMap;
 138  
     }
 139  
 
 140  
     protected IntegerMap getLinesMap() {
 141  0
         return linesMap;
 142  
     }
 143  
 
 144  
     public int getDeveloperCount() {
 145  0
         int result = 0;
 146  0
         final Iterator it = getContent().getAuthors().iterator();
 147  0
         while (it.hasNext()) {
 148  0
             final Author author = (Author) it.next();
 149  0
             if (this.config.isDeveloper(author)) {
 150  0
                 result++;
 151  
             }
 152  0
         }
 153  0
         return result;
 154  
     }
 155  
 }