Add code to load bug categories and patterns from the FindBugs messages.xml file.
[cfb.git] / prod / net / jaekl / cfb / db / Row.java
1 package net.jaekl.cfb.db;
2
3
4 public class Row {
5         Column[] m_columns;
6         Object[] m_values;
7         
8         public Row(Column[] columns, Object[] values)
9         {
10                 m_columns = columns.clone();
11                 m_values = values.clone();
12         }
13         
14         public int getNumColumns() { return m_columns.length; }
15         
16         public String getString(int index) throws TypeMismatchException {
17                 checkType(index, Column.Type.VARCHAR);
18                 return (String)m_values[index];
19         }
20         
21         public int getInt(int index) throws TypeMismatchException
22         {
23                 checkType(index, Column.Type.INTEGER);
24                 Number num = (Number)m_values[index];
25                 return num.intValue();
26         }
27         
28         public long getLong(int index) throws TypeMismatchException
29         {
30                 checkType(index, Column.Type.INTEGER);
31                 Number num = (Number)m_values[index];
32                 return num.longValue();
33         }
34         
35         protected void checkType(int index, Column.Type type) throws TypeMismatchException {
36                 Column column = m_columns[index];
37                 if (column.getType().equals(type)) {
38                         return;
39                 }
40                 
41                 String msg = "Column " + column.getName() 
42                                    + " is of type " + column.getType().name()
43                                    + " which cannot be coerced to type " + type.name() + ".";
44                 throw new TypeMismatchException(msg);
45         }
46 }