Coverage Report - org.apache.tapestry.contrib.table.model.simple.SimpleTableColumnModel
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleTableColumnModel
0%
0/14
0%
0/6
1.667
 
 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 org.apache.tapestry.contrib.table.model.ITableColumn;
 18  
 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
 19  
 import org.apache.tapestry.contrib.table.model.common.ArrayIterator;
 20  
 
 21  
 import java.io.Serializable;
 22  
 import java.util.HashMap;
 23  
 import java.util.Iterator;
 24  
 import java.util.List;
 25  
 import java.util.Map;
 26  
 
 27  
 /**
 28  
  * A minimal implementation of the
 29  
  * {@link org.apache.tapestry.contrib.table.model.ITableColumnModel} interface
 30  
  * that stores columns as an array.
 31  
  * 
 32  
  * @author mindbridge
 33  
  */
 34  
 public class SimpleTableColumnModel implements ITableColumnModel, Serializable
 35  
 {
 36  
     private static final long serialVersionUID = 1L;
 37  
 
 38  
     private ITableColumn[] m_arrColumns;
 39  
     private Map m_mapColumns;
 40  
 
 41  
     public SimpleTableColumnModel(ITableColumn[] arrColumns)
 42  0
     {
 43  0
         m_arrColumns = arrColumns;
 44  0
         m_mapColumns = new HashMap();
 45  
 
 46  0
         for(int i = 0; i < m_arrColumns.length; i++)
 47  
         {
 48  0
             m_mapColumns.put(m_arrColumns[i].getColumnName(), m_arrColumns[i]);
 49  
         }
 50  0
     }
 51  
 
 52  
     public SimpleTableColumnModel(List arrColumns)
 53  
     {
 54  0
         this((ITableColumn[]) arrColumns.toArray(new ITableColumn[arrColumns.size()]));
 55  0
     }
 56  
 
 57  
     public int getColumnCount()
 58  
     {
 59  0
         return m_arrColumns.length;
 60  
     }
 61  
 
 62  
     public ITableColumn getColumn(int nColumn)
 63  
     {
 64  0
         if (nColumn < 0 || nColumn >= m_arrColumns.length)
 65  
         {
 66  
             // error message
 67  0
             return null;
 68  
         }
 69  
         
 70  0
         return m_arrColumns[nColumn];
 71  
     }
 72  
 
 73  
     public ITableColumn getColumn(String strColumn)
 74  
     {
 75  0
         return (ITableColumn) m_mapColumns.get(strColumn);
 76  
     }
 77  
 
 78  
     public Iterator getColumns()
 79  
     {
 80  0
         return new ArrayIterator(m_arrColumns);
 81  
     }
 82  
 }