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: AvgFileSizeTimeLineReport.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.Revision;
33  import net.sf.statcvs.model.VersionedFile;
34  import net.sf.statcvs.reportmodel.TimeLine;
35  
36  /**
37   * Time line for the average file size from a specified file list.
38   * 
39   * @author Richard Cyganiak <rcyg@gmx.de>
40   * @version $Id: AvgFileSizeTimeLineReport.java,v 1.6 2008/04/02 11:22:15 benoitx Exp $
41   */
42  public class AvgFileSizeTimeLineReport {
43      private final TimeLine timeLine;
44  
45      /**
46       * Creates a new file count time line for a specified list of files.
47       * @param files a list of {@link net.sf.statcvs.model.VersionedFile}s
48       */
49      public AvgFileSizeTimeLineReport(final SortedSet files) {
50          timeLine = new TimeLine(Messages.getString("AVERAGE_FILE_SIZE_TITLE"), Messages.getString("RANGE_LOC_PER_FILE"));
51          final List revisions = new ArrayList();
52          final Iterator filesIt = files.iterator();
53          while (filesIt.hasNext()) {
54              final VersionedFile file = (VersionedFile) filesIt.next();
55              revisions.addAll(file.getRevisions());
56          }
57          Collections.sort(revisions);
58          final Iterator it = revisions.iterator();
59          int loc = 0;
60          int fileCount = 0;
61          while (it.hasNext()) {
62              final Revision rev = (Revision) it.next();
63              loc += rev.getLinesDelta();
64              fileCount += rev.getFileCountDelta();
65              final int ratio = (fileCount == 0) ? 0 : loc / fileCount;
66              timeLine.addTimePoint(rev.getDate(), ratio);
67          }
68      }
69  
70      /**
71       * Returns the result time line
72       * @return the result time line
73       */
74      public TimeLine getTimeLine() {
75          return timeLine;
76      }
77  }