1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb.client.util;
26
27 import java.util.HashMap;
28 import java.util.Set;
29
30 import org.utgenome.gwt.utgb.client.UTGBClientException;
31
32 import com.google.gwt.core.client.GWT;
33
34
35
36
37
38
39
40 public class TableData {
41
42 private String[] _columnName;
43 private HashMap<Object, Object[]> _rowTable = new HashMap<Object, Object[]>();
44
45 public final static String DEFAULT_KEY_COLUMN_NAME = "id";
46 private int _keyColumn = -1;
47
48 public TableData(String[] columnName)
49 {
50 this._columnName = columnName;
51
52 for(int i=0; i<_columnName.length; i++)
53 {
54 if(_columnName[i].equals(DEFAULT_KEY_COLUMN_NAME))
55 _keyColumn = i;
56 }
57
58 verifyKeyColumn();
59 }
60
61 public TableData(String[] columnName, int keyColumn)
62 {
63 this._columnName = columnName;
64 _keyColumn = keyColumn;
65 verifyKeyColumn();
66 }
67
68 private void verifyKeyColumn()
69 {
70 if(_keyColumn < 0 || _keyColumn >= _columnName.length)
71 {
72 GWT.log("key column is not found in " + _columnName, new UTGBClientException());
73 _keyColumn = 0;
74 }
75 }
76
77
78
79
80
81
82
83 public Object addRow(Object[] row)
84 {
85 Object key = row[_keyColumn];
86 _rowTable.put(key, row);
87 return key;
88 }
89
90
91
92
93
94 public Set<Object> keySet()
95 {
96 return _rowTable.keySet();
97 }
98
99 public Object[] getRow(Object key)
100 {
101 return _rowTable.get(key);
102 }
103
104 public int getColumnCount()
105 {
106 return _columnName.length;
107 }
108
109
110 public String[] getColumnLabel()
111 {
112 return _columnName;
113 }
114 public String getColumnLabel(int column)
115 {
116 return _columnName[column];
117 }
118
119 public void clear() {
120 _rowTable.clear();
121 }
122
123 public int getKeyColumn() {
124 return _keyColumn;
125 }
126
127 }
128
129
130
131