1 21 22 package org.dbunit.dataset; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 32 public class DefaultTable extends AbstractTable 33 { 34 private final ITableMetaData _metaData; 35 private final List _rowList; 36 37 41 public DefaultTable(ITableMetaData metaData, List list) 42 { 43 _metaData = metaData; 44 _rowList = list; 45 } 46 47 50 public DefaultTable(String tableName) 51 { 52 _metaData = new DefaultTableMetaData(tableName, new Column[0]); 53 _rowList = new ArrayList (); 54 } 55 56 60 public DefaultTable(String tableName, Column[] columns, List list) 61 { 62 _metaData = new DefaultTableMetaData(tableName, columns); 63 _rowList = list; 64 } 65 66 69 public DefaultTable(String tableName, Column[] columns) 70 { 71 _metaData = new DefaultTableMetaData(tableName, columns); 72 _rowList = new ArrayList (); 73 } 74 75 public DefaultTable(ITableMetaData metaData) 76 { 77 _metaData = metaData; 78 _rowList = new ArrayList (); 79 } 80 81 84 public void addRow() throws DataSetException 85 { 86 int columnCount = _metaData.getColumns().length; 87 _rowList.add(new Object [columnCount]); 88 } 89 90 96 public void addRow(Object [] values) throws DataSetException 97 { 98 _rowList.add(values); 99 } 100 101 105 public void addTableRows(ITable table) throws DataSetException 106 { 107 try 108 { 109 Column[] columns = _metaData.getColumns(); 110 if (columns.length > 0) 111 { 112 for (int i = 0; ; i++) 113 { 114 Object [] rowValues = new Object [columns.length]; 115 for (int j = 0; j < columns.length; j++) 116 { 117 Column column = columns[j]; 118 rowValues[j] = table.getValue(i, column.getColumnName()); 119 } 120 _rowList.add(rowValues); 121 } 122 } 123 } 124 catch(RowOutOfBoundsException e) 125 { 126 } 128 } 129 130 140 public Object setValue(int row, String column, Object value) 141 throws RowOutOfBoundsException, NoSuchColumnException, DataSetException 142 { 143 assertValidRowIndex(row); 144 145 Object [] rowValues = (Object [])_rowList.get(row); 146 int columnIndex = getColumnIndex(column); 147 Object oldValue = rowValues[columnIndex]; 148 rowValues[columnIndex] = value; 149 return oldValue; 150 } 151 152 155 public ITableMetaData getTableMetaData() 156 { 157 return _metaData; 158 } 159 160 public int getRowCount() 161 { 162 return _rowList.size(); 163 } 164 165 public Object getValue(int row, String column) throws DataSetException 166 { 167 assertValidRowIndex(row); 168 169 Object [] rowValues = (Object [])_rowList.get(row); 170 return rowValues[getColumnIndex(column)]; 171 } 172 173 } 174 175 176 177 178 179 | Popular Tags |