Clover coverage report - Code Coverage for tapestry-contrib release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:15:40 EST
file stats: LOC: 149   Methods: 13
NCLOC: 81   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SimpleListTableDataModel.java 0% 0% 0% 0%
coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.contrib.table.model.simple;
 16   
 17    import java.io.Serializable;
 18    import java.util.ArrayList;
 19    import java.util.Arrays;
 20    import java.util.Collection;
 21    import java.util.Iterator;
 22    import java.util.List;
 23   
 24    import org.apache.tapestry.contrib.table.model.CTableDataModelEvent;
 25    import org.apache.tapestry.contrib.table.model.common.AbstractTableDataModel;
 26    import org.apache.tapestry.contrib.table.model.common.ArrayIterator;
 27   
 28    /**
 29    * A minimal list implementation of the
 30    * {@link org.apache.tapestry.contrib.table.model.ITableDataModel} interface
 31    *
 32    * @author mindbridge
 33    */
 34    public class SimpleListTableDataModel extends AbstractTableDataModel implements Serializable
 35    {
 36    private static final long serialVersionUID = 1L;
 37   
 38    private List m_arrRows;
 39   
 40  0 public SimpleListTableDataModel(Object[] arrRows)
 41    {
 42  0 this(Arrays.asList(arrRows));
 43    }
 44   
 45  0 public SimpleListTableDataModel(List arrRows)
 46    {
 47  0 m_arrRows = arrRows;
 48    }
 49   
 50  0 public SimpleListTableDataModel(Collection arrRows)
 51    {
 52  0 m_arrRows = new ArrayList(arrRows);
 53    }
 54   
 55  0 public SimpleListTableDataModel(Iterator objRows)
 56    {
 57  0 m_arrRows = new ArrayList();
 58  0 addAll(m_arrRows, objRows);
 59    }
 60   
 61  0 private void addAll(List arrRows, Iterator objRows)
 62    {
 63  0 while (objRows.hasNext())
 64  0 arrRows.add(objRows.next());
 65    }
 66   
 67    /**
 68    * @see org.apache.tapestry.contrib.table.model.ITableDataModel#getRowCount()
 69    */
 70  0 public int getRowCount()
 71    {
 72  0 return m_arrRows.size();
 73    }
 74   
 75    /**
 76    * Returns the row element at the given position
 77    * @param nRow the index of the element to return
 78    */
 79  0 public Object getRow(int nRow)
 80    {
 81  0 if (nRow < 0 || nRow >= m_arrRows.size())
 82    {
 83    // error message
 84  0 return null;
 85    }
 86  0 return m_arrRows.get(nRow);
 87    }
 88   
 89    /**
 90    * Returns an Iterator with the elements from the given range
 91    * @param nFrom the start of the range (inclusive)
 92    * @param nTo the stop of the range (exclusive)
 93    */
 94  0 public Iterator getRows(int nFrom, int nTo)
 95    {
 96  0 return new ArrayIterator(m_arrRows.toArray(), nFrom, nTo);
 97    }
 98   
 99    /**
 100    * @see org.apache.tapestry.contrib.table.model.ITableDataModel#getRows()
 101    */
 102  0 public Iterator getRows()
 103    {
 104  0 return m_arrRows.iterator();
 105    }
 106   
 107    /**
 108    * Method addRow.
 109    * Adds a row object to the model at its end
 110    * @param objRow the row object to add
 111    */
 112  0 public void addRow(Object objRow)
 113    {
 114  0 m_arrRows.add(objRow);
 115   
 116  0 CTableDataModelEvent objEvent = new CTableDataModelEvent();
 117  0 fireTableDataModelEvent(objEvent);
 118    }
 119   
 120  0 public void addRows(Collection arrRows)
 121    {
 122  0 m_arrRows.addAll(arrRows);
 123   
 124  0 CTableDataModelEvent objEvent = new CTableDataModelEvent();
 125  0 fireTableDataModelEvent(objEvent);
 126    }
 127   
 128    /**
 129    * Method removeRow.
 130    * Removes a row object from the model
 131    * @param objRow the row object to remove
 132    */
 133  0 public void removeRow(Object objRow)
 134    {
 135  0 m_arrRows.remove(objRow);
 136   
 137  0 CTableDataModelEvent objEvent = new CTableDataModelEvent();
 138  0 fireTableDataModelEvent(objEvent);
 139    }
 140   
 141  0 public void removeRows(Collection arrRows)
 142    {
 143  0 m_arrRows.removeAll(arrRows);
 144   
 145  0 CTableDataModelEvent objEvent = new CTableDataModelEvent();
 146  0 fireTableDataModelEvent(objEvent);
 147    }
 148   
 149    }