| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Table |
|
| 1.2222222222222223;1.222 |
| 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: Table.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.Iterator; | |
| 27 | import java.util.List; | |
| 28 | ||
| 29 | /** | |
| 30 | * Represents a data table for a report. Columns may be added to the table. | |
| 31 | * Values can be added to the columns. Finally, the table can be rendered | |
| 32 | * as HTML. | |
| 33 | * | |
| 34 | * @author Richard Cyganiak <rcyg@gmx.de> | |
| 35 | * @version $Id: Table.java,v 1.2 2008/04/02 11:22:14 benoitx Exp $ | |
| 36 | */ | |
| 37 | public class Table { | |
| 38 | ||
| 39 | private final String summary; | |
| 40 | 0 | private boolean keysInFirstColumn = false; |
| 41 | 0 | private boolean showTotals = false; |
| 42 | 0 | private final List columns = new ArrayList(); |
| 43 | ||
| 44 | /** | |
| 45 | * Creates a new table model | |
| 46 | * @param summary a short summary of the table data, intended for | |
| 47 | * non-visual web browsers | |
| 48 | */ | |
| 49 | 0 | public Table(final String summary) { |
| 50 | 0 | this.summary = summary; |
| 51 | 0 | } |
| 52 | ||
| 53 | /** | |
| 54 | * set if the first column contains keys that identify each row | |
| 55 | * @param enabled <tt>true</tt> if first column contains keys | |
| 56 | */ | |
| 57 | public void setKeysInFirstColumn(final boolean enabled) { | |
| 58 | 0 | keysInFirstColumn = enabled; |
| 59 | 0 | } |
| 60 | ||
| 61 | /** | |
| 62 | * Returns if the first column contains keys that identify each row | |
| 63 | * @return <tt>true</tt> if first column contains keys | |
| 64 | */ | |
| 65 | public boolean hasKeysInFirstColumn() { | |
| 66 | 0 | return keysInFirstColumn; |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * set if totals of each column should be shown | |
| 71 | * @param enabled <tt>true</tt> if totals should be shown | |
| 72 | */ | |
| 73 | public void setShowTotals(final boolean enabled) { | |
| 74 | 0 | showTotals = enabled; |
| 75 | 0 | } |
| 76 | ||
| 77 | /** | |
| 78 | * Returns if totals of each column should be shown | |
| 79 | * @return <tt>true</tt> if so | |
| 80 | */ | |
| 81 | public boolean showTotals() { | |
| 82 | 0 | return showTotals; |
| 83 | } | |
| 84 | ||
| 85 | /** | |
| 86 | * Returns the summary text of the table. This is intended for non-visual | |
| 87 | * web browsers. | |
| 88 | * @return the table summary | |
| 89 | */ | |
| 90 | public String getSummary() { | |
| 91 | 0 | return summary; |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * Returns the number of data rows in the table. | |
| 96 | * @return number of data rows in the table | |
| 97 | */ | |
| 98 | public int getRowCount() { | |
| 99 | 0 | int result = 0; |
| 100 | 0 | final Iterator it = columns.iterator(); |
| 101 | 0 | while (it.hasNext()) { |
| 102 | 0 | final Column column = (Column) it.next(); |
| 103 | 0 | if (column.getRows() > result) { |
| 104 | 0 | result = column.getRows(); |
| 105 | } | |
| 106 | 0 | } |
| 107 | 0 | return result; |
| 108 | } | |
| 109 | ||
| 110 | /** | |
| 111 | * Adds a column to the table | |
| 112 | * @param column the column | |
| 113 | */ | |
| 114 | public void addColumn(final Column column) { | |
| 115 | 0 | columns.add(column); |
| 116 | 0 | } |
| 117 | ||
| 118 | /** | |
| 119 | * Returns an iterator of all {@link Column} objects of the table | |
| 120 | * @return an iterator of Columns | |
| 121 | */ | |
| 122 | public Iterator getColumnIterator() { | |
| 123 | 0 | return columns.iterator(); |
| 124 | } | |
| 125 | } |