View Javadoc

1   package net.sf.tomp.djunit.simple;
2   
3   import net.sf.tomp.djunit.Record;
4   import net.sf.tomp.djunit.RecordMetadata;
5   
6   import java.util.HashMap;
7   import java.util.Map;
8   
9   public class RecordImpl implements Record
10  {
11      protected Map fields = new HashMap();
12      protected RecordMetadata metadata;
13  
14      public RecordImpl(RecordMetadata m)
15      {
16          metadata = m;
17      }
18  
19      public Object get(int i)
20      {
21          return get(metadata.fieldNameAt(i));
22      }
23  
24      public Object get(String name)
25      {
26          return fields.get(name);
27      }
28  
29      public int getInt(String name)
30      {
31          return Integer.parseInt(getString(name));
32      }
33  
34      public double getDouble(String name)
35      {
36          return Double.parseDouble(getString(name));
37      }
38  
39      public String getString(String name)
40      {
41          return get(name).toString();
42      }
43  
44      public int getInt(int i)
45      {
46          return Integer.parseInt(getString(i));
47      }
48  
49      public double getDouble(int i)
50      {
51          return Double.parseDouble(getString(i));
52      }
53  
54      public String getString(int i)
55      {
56          return get(i).toString();
57      }
58  
59      public void addField(String name, Object value)
60      {
61          if (metadata.hasField(name))
62          {
63              fields.put(name, value);
64          }
65          else
66          {
67              throw new IllegalArgumentException("Record of type " + metadata
68                  + " does not have field " + name);
69          }
70      }
71  
72      /*
73       * (non-Javadoc)
74       *
75       * @see net.sf.tomp.djunit.Record#recordMetadata()
76       */
77      public RecordMetadata recordMetadata()
78      {
79          return metadata;
80      }
81  }