Coverage Report - net.sf.statcvs.reportmodel.IntegerColumn
 
Classes in this File Line Coverage Branch Coverage Complexity
IntegerColumn
0%
0/33
0%
0/8
1.25
 
 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: IntegerColumn.java,v $
 21  
         $Date: 2008/04/02 11:22:14 $
 22  
 */
 23  
 package net.sf.statcvs.reportmodel;
 24  
 
 25  
 import java.util.ArrayList;
 26  
 import java.util.List;
 27  
 
 28  
 import net.sf.statcvs.renderer.TableCellRenderer;
 29  
 
 30  
 /**
 31  
  * A column of integer values. The column's total is the sum of all values. 
 32  
  * 
 33  
  * @author Richard Cyganiak <rcyg@gmx.de>
 34  
  * @version $Id: IntegerColumn.java,v 1.2 2008/04/02 11:22:14 benoitx Exp $
 35  
  */
 36  
 public class IntegerColumn extends Column {
 37  
 
 38  
     private final String title;
 39  0
     private final List values = new ArrayList();
 40  0
     private int sum = 0;
 41  0
     private boolean showValues = true;
 42  0
     private boolean showPercentages = true;
 43  
 
 44  
     /**
 45  
      * Creates a new <tt>SimpleTextColumn</tt> with the given head
 46  
      * @param title the head of the column
 47  
      */
 48  0
     public IntegerColumn(final String title) {
 49  0
         this.title = title;
 50  0
     }
 51  
 
 52  
     /**
 53  
      * Set if the actual integer values should be shown
 54  
      * @param enable show values?
 55  
      */
 56  
     public void setShowValues(final boolean enable) {
 57  0
         showValues = enable;
 58  0
     }
 59  
 
 60  
     /**
 61  
      * Set if the values should be shown as percentages
 62  
      * @param enable show percentages?
 63  
      */
 64  
     public void setShowPercentages(final boolean enable) {
 65  0
         showPercentages = enable;
 66  0
     }
 67  
 
 68  
     /**
 69  
      * Adds a value to this column (in a new row)
 70  
      * @param value the new value
 71  
      */
 72  
     public void addValue(final int value) {
 73  0
         values.add(new Integer(value));
 74  0
         sum += value;
 75  0
     }
 76  
 
 77  
     /**
 78  
      * Returns a value in the column
 79  
      * @param rowIndex the row to get, starting at 0
 80  
      * @return the value of this row
 81  
      */
 82  
     public int getValue(final int rowIndex) {
 83  0
         return ((Integer) values.get(rowIndex)).intValue();
 84  
     }
 85  
 
 86  
     /**
 87  
      * Returns the sum of all values in the column
 88  
      * @return sum
 89  
      */
 90  
     public int getSum() {
 91  0
         return sum;
 92  
     }
 93  
 
 94  
     /**
 95  
      * Sets the sum of the column. Useful if, for example, the
 96  
      * column contains only the top 10 values of more values, but
 97  
      * the column total should reflect all values.
 98  
      * @param sum the column's total
 99  
      */
 100  
     public void setSum(final int sum) {
 101  0
         this.sum = sum;
 102  0
     }
 103  
 
 104  
     /**
 105  
      * @see net.sf.statcvs.reportmodel.Column#getRows()
 106  
      */
 107  
     public int getRows() {
 108  0
         return values.size();
 109  
     }
 110  
 
 111  
     /**
 112  
      * @see net.sf.statcvs.reportmodel.Column#renderHead(net.sf.statcvs.renderer.TableCellRenderer)
 113  
      */
 114  
     public void renderHead(final TableCellRenderer renderer) {
 115  0
         renderer.renderCell(title);
 116  0
     }
 117  
 
 118  
     /**
 119  
      * @see net.sf.statcvs.reportmodel.Column#renderCell
 120  
      */
 121  
     public void renderCell(final int rowIndex, final TableCellRenderer renderer) {
 122  0
         callRenderer(renderer, getValue(rowIndex));
 123  0
     }
 124  
 
 125  
     /**
 126  
      * @see net.sf.statcvs.reportmodel.Column#renderTotal(net.sf.statcvs.renderer.TableCellRenderer)
 127  
      */
 128  
     public void renderTotal(final TableCellRenderer renderer) {
 129  0
         callRenderer(renderer, sum);
 130  0
     }
 131  
 
 132  
     private void callRenderer(final TableCellRenderer renderer, final int value) {
 133  0
         if (showValues && showPercentages) {
 134  0
             renderer.renderIntegerCell(value, sum);
 135  0
         } else if (showValues) {
 136  0
             renderer.renderIntegerCell(value);
 137  0
         } else if (showPercentages) {
 138  0
             renderer.renderPercentageCell((double) value / (double) sum);
 139  
         } else {
 140  0
             renderer.renderEmptyCell();
 141  
         }
 142  0
     }
 143  
 }