6 |
10 Oct 05 |
enell |
1 |
/* |
6 |
10 Oct 05 |
enell |
* (non-javadoc) BASEFileSection.java is part of BASEFile. |
6 |
10 Oct 05 |
enell |
3 |
* |
6 |
10 Oct 05 |
enell |
* BASEFile is free software; you can redistribute it and/or modify it under |
6 |
10 Oct 05 |
enell |
* the terms of the GNU General Public License as published by the Free |
6 |
10 Oct 05 |
enell |
* Software Foundation; either version 2 of the License, or (at your option) |
6 |
10 Oct 05 |
enell |
* any later version. |
6 |
10 Oct 05 |
enell |
8 |
* |
6 |
10 Oct 05 |
enell |
* BASEFile is distributed in the hope that it will be useful, but WITHOUT ANY |
6 |
10 Oct 05 |
enell |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
6 |
10 Oct 05 |
enell |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
6 |
10 Oct 05 |
enell |
* details. |
6 |
10 Oct 05 |
enell |
13 |
* |
6 |
10 Oct 05 |
enell |
* You should have received a copy of the GNU General Public License along with |
6 |
10 Oct 05 |
enell |
* BASEFile; if not, write to the Free Software Foundation, Inc., 59 Temple |
6 |
10 Oct 05 |
enell |
* Place, Suite 330, Boston, MA 02111-1307 USA |
6 |
10 Oct 05 |
enell |
17 |
* |
6 |
10 Oct 05 |
enell |
* johan.enell@onk.lu.se Johan Enell, Dept Oncology, Lund University, S-221 85 |
6 |
10 Oct 05 |
enell |
* Lund, Sweden |
6 |
10 Oct 05 |
enell |
20 |
*/ |
6 |
10 Oct 05 |
enell |
21 |
package basefile; |
6 |
10 Oct 05 |
enell |
22 |
|
6 |
10 Oct 05 |
enell |
23 |
import java.util.ArrayList; |
6 |
10 Oct 05 |
enell |
24 |
import java.util.Arrays; |
248 |
28 Mar 07 |
enell |
25 |
import java.util.Collections; |
6 |
10 Oct 05 |
enell |
26 |
import java.util.HashMap; |
6 |
10 Oct 05 |
enell |
27 |
import java.util.List; |
248 |
28 Mar 07 |
enell |
28 |
import java.util.Map; |
6 |
10 Oct 05 |
enell |
29 |
|
6 |
10 Oct 05 |
enell |
30 |
/** |
6 |
10 Oct 05 |
enell |
* This class describes a section in a baseFile created from the BASE database. |
6 |
10 Oct 05 |
enell |
32 |
* |
6 |
10 Oct 05 |
enell |
* @author Johan Enell |
6 |
10 Oct 05 |
enell |
34 |
*/ |
6 |
10 Oct 05 |
enell |
35 |
/** |
6 |
10 Oct 05 |
enell |
36 |
* |
6 |
10 Oct 05 |
enell |
* @author Johan Enell, johan.enell@onk.lu.se, Dept Oncology, Lund University, |
6 |
10 Oct 05 |
enell |
* S-221 85 Lund, Sweden |
6 |
10 Oct 05 |
enell |
39 |
*/ |
6 |
10 Oct 05 |
enell |
40 |
public class BASEFileSection |
6 |
10 Oct 05 |
enell |
41 |
{ |
6 |
10 Oct 05 |
enell |
42 |
|
6 |
10 Oct 05 |
enell |
43 |
/** |
6 |
10 Oct 05 |
enell |
* The line number in the inputstream were the section starts |
6 |
10 Oct 05 |
enell |
45 |
*/ |
97 |
20 Apr 06 |
enell |
46 |
private int startLine; |
6 |
10 Oct 05 |
enell |
47 |
|
6 |
10 Oct 05 |
enell |
48 |
/** |
6 |
10 Oct 05 |
enell |
* The line number in the inpustream were the data in the section starts |
6 |
10 Oct 05 |
enell |
50 |
*/ |
97 |
20 Apr 06 |
enell |
51 |
private int dataStartLine; |
6 |
10 Oct 05 |
enell |
52 |
|
6 |
10 Oct 05 |
enell |
53 |
/** |
6 |
10 Oct 05 |
enell |
* The headers in the section put in a HashMap with the parameternames as |
6 |
10 Oct 05 |
enell |
* keys. |
6 |
10 Oct 05 |
enell |
56 |
*/ |
185 |
12 Oct 06 |
enell |
57 |
private final HashMap<String, String> headers = new HashMap<String, String>(); |
6 |
10 Oct 05 |
enell |
58 |
|
6 |
10 Oct 05 |
enell |
59 |
/** |
248 |
28 Mar 07 |
enell |
* The type of this section. |
248 |
28 Mar 07 |
enell |
61 |
*/ |
248 |
28 Mar 07 |
enell |
62 |
private String type; |
248 |
28 Mar 07 |
enell |
63 |
|
250 |
30 Mar 07 |
enell |
64 |
private boolean init = false; |
248 |
28 Mar 07 |
enell |
65 |
|
248 |
28 Mar 07 |
enell |
66 |
/** |
6 |
10 Oct 05 |
enell |
* Creates a new BASEFileSection. |
6 |
10 Oct 05 |
enell |
68 |
*/ |
250 |
30 Mar 07 |
enell |
69 |
@Deprecated |
6 |
10 Oct 05 |
enell |
70 |
public BASEFileSection() |
6 |
10 Oct 05 |
enell |
71 |
{ |
6 |
10 Oct 05 |
enell |
72 |
startLine = -1; |
6 |
10 Oct 05 |
enell |
73 |
dataStartLine = -1; |
248 |
28 Mar 07 |
enell |
74 |
type = ""; |
6 |
10 Oct 05 |
enell |
75 |
} |
6 |
10 Oct 05 |
enell |
76 |
|
250 |
30 Mar 07 |
enell |
77 |
/** |
250 |
30 Mar 07 |
enell |
* Creates a new BASEFileSection. |
250 |
30 Mar 07 |
enell |
79 |
*/ |
250 |
30 Mar 07 |
enell |
80 |
public BASEFileSection(String type) |
250 |
30 Mar 07 |
enell |
81 |
{ |
250 |
30 Mar 07 |
enell |
82 |
startLine = -1; |
250 |
30 Mar 07 |
enell |
83 |
dataStartLine = -1; |
250 |
30 Mar 07 |
enell |
84 |
this.type = type; |
250 |
30 Mar 07 |
enell |
85 |
} |
250 |
30 Mar 07 |
enell |
86 |
|
248 |
28 Mar 07 |
enell |
87 |
public BASEFileSection(BASEFileSection bfs) throws BASEFileException |
248 |
28 Mar 07 |
enell |
88 |
{ |
248 |
28 Mar 07 |
enell |
89 |
if (bfs == null) |
248 |
28 Mar 07 |
enell |
90 |
{ |
248 |
28 Mar 07 |
enell |
91 |
throw new BASEFileException("Can't initiate an assay section with a null section."); |
248 |
28 Mar 07 |
enell |
92 |
} |
248 |
28 Mar 07 |
enell |
93 |
startLine = bfs.getStartLine(); |
248 |
28 Mar 07 |
enell |
94 |
dataStartLine = bfs.getDataStartLine(); |
248 |
28 Mar 07 |
enell |
95 |
type = bfs.getType(); |
248 |
28 Mar 07 |
enell |
96 |
setHeaders(bfs.getHeaders()); |
248 |
28 Mar 07 |
enell |
97 |
} |
248 |
28 Mar 07 |
enell |
98 |
|
6 |
10 Oct 05 |
enell |
99 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as an int. |
6 |
10 Oct 05 |
enell |
101 |
* |
6 |
10 Oct 05 |
enell |
* @param name |
6 |
10 Oct 05 |
enell |
* The name of the header |
6 |
10 Oct 05 |
enell |
* @return the option value as an int |
6 |
10 Oct 05 |
enell |
* @throws NumberFormatException |
6 |
10 Oct 05 |
enell |
* If the option is not an integer |
6 |
10 Oct 05 |
enell |
107 |
*/ |
105 |
02 Jun 06 |
enell |
108 |
public final Integer findIntOpt(String name) |
105 |
02 Jun 06 |
enell |
109 |
throws NumberFormatException |
6 |
10 Oct 05 |
enell |
110 |
{ |
6 |
10 Oct 05 |
enell |
111 |
String ret = headers.get(name); |
6 |
10 Oct 05 |
enell |
112 |
try |
6 |
10 Oct 05 |
enell |
113 |
{ |
105 |
02 Jun 06 |
enell |
114 |
return new Integer(ret); |
6 |
10 Oct 05 |
enell |
115 |
} |
6 |
10 Oct 05 |
enell |
116 |
catch (NumberFormatException e) |
6 |
10 Oct 05 |
enell |
117 |
{ |
264 |
27 Apr 07 |
enell |
118 |
throw new NumberFormatException("The value of parameter '" + name + "' is not an int: " + ret); |
6 |
10 Oct 05 |
enell |
119 |
} |
6 |
10 Oct 05 |
enell |
120 |
} |
6 |
10 Oct 05 |
enell |
121 |
|
6 |
10 Oct 05 |
enell |
122 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as a float. |
6 |
10 Oct 05 |
enell |
124 |
* |
6 |
10 Oct 05 |
enell |
* @param name |
6 |
10 Oct 05 |
enell |
* The name of the header |
6 |
10 Oct 05 |
enell |
* @return the option value as a float |
6 |
10 Oct 05 |
enell |
* @throws NumberFormatException |
6 |
10 Oct 05 |
enell |
* If the option is not a float |
6 |
10 Oct 05 |
enell |
130 |
*/ |
105 |
02 Jun 06 |
enell |
131 |
public Float findFloatOpt(String name) |
105 |
02 Jun 06 |
enell |
132 |
throws NumberFormatException |
6 |
10 Oct 05 |
enell |
133 |
{ |
6 |
10 Oct 05 |
enell |
134 |
String ret = headers.get(name); |
105 |
02 Jun 06 |
enell |
135 |
return new Float(ret); |
6 |
10 Oct 05 |
enell |
136 |
} |
6 |
10 Oct 05 |
enell |
137 |
|
6 |
10 Oct 05 |
enell |
138 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as a String. |
6 |
10 Oct 05 |
enell |
140 |
* |
6 |
10 Oct 05 |
enell |
* @param name |
6 |
10 Oct 05 |
enell |
* The name of the header |
6 |
10 Oct 05 |
enell |
* @return the option value as a String |
6 |
10 Oct 05 |
enell |
144 |
*/ |
97 |
20 Apr 06 |
enell |
145 |
public final String findStringOpt(String name) |
6 |
10 Oct 05 |
enell |
146 |
{ |
6 |
10 Oct 05 |
enell |
147 |
String ret = headers.get(name); |
6 |
10 Oct 05 |
enell |
148 |
return ret; |
6 |
10 Oct 05 |
enell |
149 |
} |
6 |
10 Oct 05 |
enell |
150 |
|
6 |
10 Oct 05 |
enell |
151 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as a String[]. |
6 |
10 Oct 05 |
enell |
* The values is separated by the tab (\u0009) character. |
6 |
10 Oct 05 |
enell |
154 |
* |
6 |
10 Oct 05 |
enell |
* @param name |
6 |
10 Oct 05 |
enell |
* The name of the header |
6 |
10 Oct 05 |
enell |
* @return the option value as a String |
6 |
10 Oct 05 |
enell |
158 |
*/ |
97 |
20 Apr 06 |
enell |
159 |
public final String[] findStringOpts(String name) |
6 |
10 Oct 05 |
enell |
160 |
{ |
106 |
13 Jun 06 |
enell |
161 |
return findStringOpts(name, "\t"); |
6 |
10 Oct 05 |
enell |
162 |
} |
106 |
13 Jun 06 |
enell |
163 |
|
106 |
13 Jun 06 |
enell |
164 |
/** |
106 |
13 Jun 06 |
enell |
* Find the specified header from the headers and return it as a String[]. |
106 |
13 Jun 06 |
enell |
* The values is separated by the del String. |
106 |
13 Jun 06 |
enell |
167 |
* |
106 |
13 Jun 06 |
enell |
* @param name The name of the header |
106 |
13 Jun 06 |
enell |
* @param del The string that splits the value. Using the method String.split() |
106 |
13 Jun 06 |
enell |
* @return the option value as a String or null if name isnt found in the headers |
106 |
13 Jun 06 |
enell |
171 |
*/ |
106 |
13 Jun 06 |
enell |
172 |
public final String[] findStringOpts(String name, String del) |
106 |
13 Jun 06 |
enell |
173 |
{ |
106 |
13 Jun 06 |
enell |
174 |
String value = headers.get(name); |
106 |
13 Jun 06 |
enell |
175 |
if (value != null) |
106 |
13 Jun 06 |
enell |
176 |
{ |
106 |
13 Jun 06 |
enell |
177 |
return value.split(del); |
106 |
13 Jun 06 |
enell |
178 |
} |
106 |
13 Jun 06 |
enell |
179 |
return null; |
106 |
13 Jun 06 |
enell |
180 |
} |
6 |
10 Oct 05 |
enell |
181 |
|
6 |
10 Oct 05 |
enell |
182 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as a boolean. |
6 |
10 Oct 05 |
enell |
184 |
* |
6 |
10 Oct 05 |
enell |
* @param name |
6 |
10 Oct 05 |
enell |
* The name of the header |
6 |
10 Oct 05 |
enell |
* @return the option value as a boolean |
6 |
10 Oct 05 |
enell |
* @throws NumberFormatException |
6 |
10 Oct 05 |
enell |
* If the option is not a boolean |
6 |
10 Oct 05 |
enell |
190 |
*/ |
97 |
20 Apr 06 |
enell |
191 |
public final boolean findBooleanOpt(String name) |
6 |
10 Oct 05 |
enell |
192 |
{ |
6 |
10 Oct 05 |
enell |
193 |
String ret = headers.get(name); |
6 |
10 Oct 05 |
enell |
194 |
|
6 |
10 Oct 05 |
enell |
195 |
boolean value = false; |
6 |
10 Oct 05 |
enell |
196 |
try |
6 |
10 Oct 05 |
enell |
197 |
{ |
6 |
10 Oct 05 |
enell |
198 |
value = Boolean.valueOf(ret).booleanValue(); |
6 |
10 Oct 05 |
enell |
199 |
} |
6 |
10 Oct 05 |
enell |
200 |
catch (NumberFormatException e) |
6 |
10 Oct 05 |
enell |
201 |
{ |
6 |
10 Oct 05 |
enell |
202 |
throw new NumberFormatException("The value of parameter " + name + " is not a boolean: " + ret); |
6 |
10 Oct 05 |
enell |
203 |
} |
6 |
10 Oct 05 |
enell |
204 |
return value; |
6 |
10 Oct 05 |
enell |
205 |
} |
6 |
10 Oct 05 |
enell |
206 |
|
6 |
10 Oct 05 |
enell |
207 |
/** |
6 |
10 Oct 05 |
enell |
* Used to get the values from a header as a {@link java.util.List<String>}. |
6 |
10 Oct 05 |
enell |
* The order is the same as in the basefile if the user hasent changed it. |
6 |
10 Oct 05 |
enell |
210 |
* |
6 |
10 Oct 05 |
enell |
* @param name |
6 |
10 Oct 05 |
enell |
* The name of the header |
6 |
10 Oct 05 |
enell |
* @return A list of the values. |
6 |
10 Oct 05 |
enell |
214 |
*/ |
97 |
20 Apr 06 |
enell |
215 |
public final List<String> findFieldList(String name) |
6 |
10 Oct 05 |
enell |
216 |
{ |
6 |
10 Oct 05 |
enell |
217 |
String s = headers.get(name); |
6 |
10 Oct 05 |
enell |
218 |
if (s == null) return null; |
269 |
15 May 07 |
enell |
219 |
if (s.equals("")) return new ArrayList<String>(); |
6 |
10 Oct 05 |
enell |
220 |
return new ArrayList<String>(Arrays.asList(s.split("\\t"))); |
6 |
10 Oct 05 |
enell |
221 |
|
6 |
10 Oct 05 |
enell |
222 |
} |
6 |
10 Oct 05 |
enell |
223 |
|
6 |
10 Oct 05 |
enell |
224 |
/** |
94 |
05 Apr 06 |
enell |
* Used to get the values from a header as a {@link java.util.List<Integer>}. |
94 |
05 Apr 06 |
enell |
* The order is the same as in the basefile if the user hasent changed it. |
94 |
05 Apr 06 |
enell |
227 |
* |
94 |
05 Apr 06 |
enell |
* @param name |
94 |
05 Apr 06 |
enell |
* The name of the header |
94 |
05 Apr 06 |
enell |
* @return A list of the values. |
94 |
05 Apr 06 |
enell |
231 |
*/ |
97 |
20 Apr 06 |
enell |
232 |
public final List<Integer> findFieldIntList(String name) |
94 |
05 Apr 06 |
enell |
233 |
{ |
269 |
15 May 07 |
enell |
234 |
List<String> stringList = this.findFieldList(name); |
269 |
15 May 07 |
enell |
235 |
if (stringList == null) return null; |
94 |
05 Apr 06 |
enell |
236 |
ArrayList<Integer> ret = new ArrayList<Integer>(); |
269 |
15 May 07 |
enell |
237 |
for (String assay : stringList) |
94 |
05 Apr 06 |
enell |
238 |
{ |
94 |
05 Apr 06 |
enell |
239 |
ret.add(new Integer(assay)); |
94 |
05 Apr 06 |
enell |
240 |
} |
94 |
05 Apr 06 |
enell |
241 |
return ret; |
94 |
05 Apr 06 |
enell |
242 |
} |
94 |
05 Apr 06 |
enell |
243 |
|
94 |
05 Apr 06 |
enell |
244 |
/** |
6 |
10 Oct 05 |
enell |
* Puts a header in the header map. The header is stored as a String using |
6 |
10 Oct 05 |
enell |
* the Object.toString() method. If the map previously contained a mapping |
6 |
10 Oct 05 |
enell |
* for this key, the old value is replaced. |
6 |
10 Oct 05 |
enell |
248 |
* |
6 |
10 Oct 05 |
enell |
* @param key |
6 |
10 Oct 05 |
enell |
* key with which the specified value is to be associated. |
6 |
10 Oct 05 |
enell |
* @param value |
6 |
10 Oct 05 |
enell |
* value to be associated with the specified key. |
6 |
10 Oct 05 |
enell |
* @return previous value associated with specified key, or null if there |
6 |
10 Oct 05 |
enell |
* was no mapping for key. A null return can also indicate that the |
6 |
10 Oct 05 |
enell |
* HashMap previously associated null with the specified key. |
6 |
10 Oct 05 |
enell |
256 |
*/ |
97 |
20 Apr 06 |
enell |
257 |
public final String setHeader(Object key, Object value) |
6 |
10 Oct 05 |
enell |
258 |
{ |
248 |
28 Mar 07 |
enell |
259 |
String ret = ""; |
248 |
28 Mar 07 |
enell |
260 |
if ("section".equals(key)) |
248 |
28 Mar 07 |
enell |
261 |
{ |
248 |
28 Mar 07 |
enell |
262 |
ret = this.getType(); |
248 |
28 Mar 07 |
enell |
263 |
this.setType(value.toString()); |
248 |
28 Mar 07 |
enell |
264 |
} |
248 |
28 Mar 07 |
enell |
265 |
else |
248 |
28 Mar 07 |
enell |
266 |
{ |
248 |
28 Mar 07 |
enell |
267 |
ret = headers.put(key.toString(), value.toString()); |
248 |
28 Mar 07 |
enell |
268 |
} |
248 |
28 Mar 07 |
enell |
269 |
return ret; |
6 |
10 Oct 05 |
enell |
270 |
} |
6 |
10 Oct 05 |
enell |
271 |
|
6 |
10 Oct 05 |
enell |
272 |
/** |
6 |
10 Oct 05 |
enell |
* Puts a header in the header map. The header is stored as a String using |
6 |
10 Oct 05 |
enell |
* the Object.toString() method. All the Object in the array is conbined the |
6 |
10 Oct 05 |
enell |
* with a tabulation character '\t'. If the map previously contained a |
6 |
10 Oct 05 |
enell |
* mapping for this key, the old value is replaced. |
6 |
10 Oct 05 |
enell |
277 |
* |
6 |
10 Oct 05 |
enell |
* @param key |
6 |
10 Oct 05 |
enell |
* key with which the specified value is to be associated. |
6 |
10 Oct 05 |
enell |
* @param value |
6 |
10 Oct 05 |
enell |
* values to be associated with the specified key. |
6 |
10 Oct 05 |
enell |
* @return previous value associated with specified key, or null if there |
6 |
10 Oct 05 |
enell |
* was no mapping for key. A null return can also indicate that the |
6 |
10 Oct 05 |
enell |
* HashMap previously associated null with the specified key. |
6 |
10 Oct 05 |
enell |
285 |
*/ |
97 |
20 Apr 06 |
enell |
286 |
public final String setHeader(Object key, Object... value) |
6 |
10 Oct 05 |
enell |
287 |
{ |
25 |
21 Oct 05 |
enell |
288 |
return this.setHeader(key, '\t', value); |
6 |
10 Oct 05 |
enell |
289 |
} |
6 |
10 Oct 05 |
enell |
290 |
|
6 |
10 Oct 05 |
enell |
291 |
/** |
6 |
10 Oct 05 |
enell |
* Puts a header in the header map. The header is stored as a String using |
6 |
10 Oct 05 |
enell |
* the Object.toString() method. All the Object in the array is conbined the |
6 |
10 Oct 05 |
enell |
* with the character c. If the map previously contained a mapping for this |
6 |
10 Oct 05 |
enell |
* key, the old value is replaced. |
6 |
10 Oct 05 |
enell |
296 |
* |
6 |
10 Oct 05 |
enell |
* @param key |
6 |
10 Oct 05 |
enell |
* key with which the specified value is to be associated. |
25 |
21 Oct 05 |
enell |
* @param c |
25 |
21 Oct 05 |
enell |
* the character used to combine the value array. |
6 |
10 Oct 05 |
enell |
* @param value |
6 |
10 Oct 05 |
enell |
* values to be associated with the specified key. |
6 |
10 Oct 05 |
enell |
* @return previous value associated with specified key, or null if there |
6 |
10 Oct 05 |
enell |
* was no mapping for key. A null return can also indicate that the |
6 |
10 Oct 05 |
enell |
* HashMap previously associated null with the specified key. |
6 |
10 Oct 05 |
enell |
306 |
*/ |
97 |
20 Apr 06 |
enell |
307 |
public final String setHeader(Object key, char c, Object... value) |
6 |
10 Oct 05 |
enell |
308 |
{ |
6 |
10 Oct 05 |
enell |
309 |
StringBuffer s = new StringBuffer(""); |
6 |
10 Oct 05 |
enell |
310 |
if (value.length > 0) |
6 |
10 Oct 05 |
enell |
311 |
{ |
6 |
10 Oct 05 |
enell |
312 |
s = new StringBuffer(value[0].toString()); |
6 |
10 Oct 05 |
enell |
313 |
for (int i = 1; i < value.length; i++) |
6 |
10 Oct 05 |
enell |
314 |
{ |
6 |
10 Oct 05 |
enell |
315 |
s.append(c); |
6 |
10 Oct 05 |
enell |
316 |
s.append(value[i]); |
6 |
10 Oct 05 |
enell |
317 |
} |
6 |
10 Oct 05 |
enell |
318 |
} |
6 |
10 Oct 05 |
enell |
319 |
return this.setHeader(key, s); |
6 |
10 Oct 05 |
enell |
320 |
} |
6 |
10 Oct 05 |
enell |
321 |
|
97 |
20 Apr 06 |
enell |
322 |
public final String getHeader(Object key) |
6 |
10 Oct 05 |
enell |
323 |
{ |
6 |
10 Oct 05 |
enell |
324 |
return this.headers.get(key.toString()); |
6 |
10 Oct 05 |
enell |
325 |
} |
248 |
28 Mar 07 |
enell |
326 |
|
248 |
28 Mar 07 |
enell |
327 |
public final Map<String, String> getHeaders() |
248 |
28 Mar 07 |
enell |
328 |
{ |
248 |
28 Mar 07 |
enell |
329 |
return Collections.unmodifiableMap(this.headers); |
248 |
28 Mar 07 |
enell |
330 |
} |
6 |
10 Oct 05 |
enell |
331 |
|
97 |
20 Apr 06 |
enell |
332 |
public final String removeHeader(Object key) |
6 |
10 Oct 05 |
enell |
333 |
{ |
18 |
18 Oct 05 |
enell |
334 |
if (key.equals("section")) |
18 |
18 Oct 05 |
enell |
335 |
{ |
18 |
18 Oct 05 |
enell |
336 |
return ""; |
18 |
18 Oct 05 |
enell |
337 |
} |
6 |
10 Oct 05 |
enell |
338 |
return headers.remove(key.toString()); |
6 |
10 Oct 05 |
enell |
339 |
} |
6 |
10 Oct 05 |
enell |
340 |
|
248 |
28 Mar 07 |
enell |
341 |
final boolean setHeaders(Map<String, String> headers) |
97 |
20 Apr 06 |
enell |
342 |
{ |
185 |
12 Oct 06 |
enell |
343 |
if (headers == null) |
185 |
12 Oct 06 |
enell |
344 |
{ |
185 |
12 Oct 06 |
enell |
345 |
return false; |
185 |
12 Oct 06 |
enell |
346 |
} |
185 |
12 Oct 06 |
enell |
347 |
this.headers.clear(); |
185 |
12 Oct 06 |
enell |
348 |
for (String key : headers.keySet()) |
185 |
12 Oct 06 |
enell |
349 |
{ |
248 |
28 Mar 07 |
enell |
350 |
this.setHeader(key, headers.get(key)); |
185 |
12 Oct 06 |
enell |
351 |
} |
97 |
20 Apr 06 |
enell |
352 |
return true; |
97 |
20 Apr 06 |
enell |
353 |
} |
248 |
28 Mar 07 |
enell |
354 |
|
248 |
28 Mar 07 |
enell |
355 |
public int getColIndex(String header, String col) throws BASEFileException |
248 |
28 Mar 07 |
enell |
356 |
{ |
248 |
28 Mar 07 |
enell |
357 |
List<String> l = this.findFieldList(header); |
248 |
28 Mar 07 |
enell |
358 |
if (l == null) throw new BASEFileException("Can't find header "+header); |
248 |
28 Mar 07 |
enell |
359 |
int index = l.indexOf(col); |
248 |
28 Mar 07 |
enell |
360 |
if (index == -1) throw new BASEFileException("Can't find column "+col+" in header "+header); |
248 |
28 Mar 07 |
enell |
361 |
return index; |
248 |
28 Mar 07 |
enell |
362 |
} |
97 |
20 Apr 06 |
enell |
363 |
|
6 |
10 Oct 05 |
enell |
364 |
/** |
97 |
20 Apr 06 |
enell |
* Get the type of the section. |
6 |
10 Oct 05 |
enell |
366 |
* |
97 |
20 Apr 06 |
enell |
* @return The value of the header 'section' |
6 |
10 Oct 05 |
enell |
368 |
*/ |
97 |
20 Apr 06 |
enell |
369 |
public final String getType() |
6 |
10 Oct 05 |
enell |
370 |
{ |
248 |
28 Mar 07 |
enell |
371 |
return type; |
6 |
10 Oct 05 |
enell |
372 |
} |
250 |
30 Mar 07 |
enell |
373 |
|
250 |
30 Mar 07 |
enell |
374 |
protected boolean isInitiated() |
250 |
30 Mar 07 |
enell |
375 |
{ |
250 |
30 Mar 07 |
enell |
376 |
return init; |
250 |
30 Mar 07 |
enell |
377 |
} |
6 |
10 Oct 05 |
enell |
378 |
|
97 |
20 Apr 06 |
enell |
379 |
/** |
248 |
28 Mar 07 |
enell |
* Checks the type of this section. |
248 |
28 Mar 07 |
enell |
381 |
* |
248 |
28 Mar 07 |
enell |
* @param string the type to test |
248 |
28 Mar 07 |
enell |
* @return true if type matches string |
97 |
20 Apr 06 |
enell |
384 |
*/ |
97 |
20 Apr 06 |
enell |
385 |
public final boolean isType(String string) |
97 |
20 Apr 06 |
enell |
386 |
{ |
97 |
20 Apr 06 |
enell |
387 |
return getType().equals(string); |
97 |
20 Apr 06 |
enell |
388 |
} |
248 |
28 Mar 07 |
enell |
389 |
|
248 |
28 Mar 07 |
enell |
390 |
/** |
248 |
28 Mar 07 |
enell |
* Sets the type of this section. |
248 |
28 Mar 07 |
enell |
392 |
* |
248 |
28 Mar 07 |
enell |
* @return the new type |
248 |
28 Mar 07 |
enell |
394 |
*/ |
250 |
30 Mar 07 |
enell |
395 |
@Deprecated |
248 |
28 Mar 07 |
enell |
396 |
public final void setType(String type) |
248 |
28 Mar 07 |
enell |
397 |
{ |
248 |
28 Mar 07 |
enell |
398 |
this.type = type; |
248 |
28 Mar 07 |
enell |
399 |
} |
105 |
02 Jun 06 |
enell |
400 |
|
97 |
20 Apr 06 |
enell |
401 |
public final int getDataStartLine() |
97 |
20 Apr 06 |
enell |
402 |
{ |
97 |
20 Apr 06 |
enell |
403 |
return dataStartLine; |
97 |
20 Apr 06 |
enell |
404 |
} |
97 |
20 Apr 06 |
enell |
405 |
|
248 |
28 Mar 07 |
enell |
406 |
@Deprecated |
97 |
20 Apr 06 |
enell |
407 |
public final void setDataStartLine(int dataStartLine) |
97 |
20 Apr 06 |
enell |
408 |
{ |
97 |
20 Apr 06 |
enell |
409 |
this.dataStartLine = dataStartLine; |
97 |
20 Apr 06 |
enell |
410 |
} |
97 |
20 Apr 06 |
enell |
411 |
public final int getStartLine() |
97 |
20 Apr 06 |
enell |
412 |
{ |
97 |
20 Apr 06 |
enell |
413 |
return startLine; |
97 |
20 Apr 06 |
enell |
414 |
} |
248 |
28 Mar 07 |
enell |
415 |
|
97 |
20 Apr 06 |
enell |
416 |
public final void setStartLine(int startLine) |
97 |
20 Apr 06 |
enell |
417 |
{ |
97 |
20 Apr 06 |
enell |
418 |
this.startLine = startLine; |
97 |
20 Apr 06 |
enell |
419 |
} |
97 |
20 Apr 06 |
enell |
420 |
|
103 |
01 Jun 06 |
enell |
421 |
public void clear() |
103 |
01 Jun 06 |
enell |
422 |
{ |
103 |
01 Jun 06 |
enell |
423 |
this.headers.clear(); |
103 |
01 Jun 06 |
enell |
424 |
startLine = -1; |
103 |
01 Jun 06 |
enell |
425 |
dataStartLine = -1; |
103 |
01 Jun 06 |
enell |
426 |
} |
103 |
01 Jun 06 |
enell |
427 |
|
31 |
08 Nov 05 |
enell |
428 |
@Override |
6 |
10 Oct 05 |
enell |
429 |
public String toString() |
6 |
10 Oct 05 |
enell |
430 |
{ |
6 |
10 Oct 05 |
enell |
431 |
String ret = "section\t" + this.getType() + "\n"; |
6 |
10 Oct 05 |
enell |
432 |
|
6 |
10 Oct 05 |
enell |
433 |
for (String key : headers.keySet()) |
6 |
10 Oct 05 |
enell |
434 |
{ |
248 |
28 Mar 07 |
enell |
435 |
ret += key + "\t" + headers.get(key) + "\n"; |
6 |
10 Oct 05 |
enell |
436 |
} |
6 |
10 Oct 05 |
enell |
437 |
ret += "%"; |
6 |
10 Oct 05 |
enell |
438 |
|
6 |
10 Oct 05 |
enell |
439 |
return ret; |
6 |
10 Oct 05 |
enell |
440 |
} |
250 |
30 Mar 07 |
enell |
441 |
|
250 |
30 Mar 07 |
enell |
442 |
protected void init() throws BASEFileException |
250 |
30 Mar 07 |
enell |
443 |
{ |
250 |
30 Mar 07 |
enell |
444 |
if (init) |
250 |
30 Mar 07 |
enell |
445 |
{ |
250 |
30 Mar 07 |
enell |
446 |
throw new BASEFileException("This section has already been initiated"); |
250 |
30 Mar 07 |
enell |
447 |
} |
250 |
30 Mar 07 |
enell |
448 |
init = true; |
250 |
30 Mar 07 |
enell |
449 |
} |
250 |
30 Mar 07 |
enell |
450 |
|
250 |
30 Mar 07 |
enell |
451 |
public void validate() throws BASEFileException |
250 |
30 Mar 07 |
enell |
452 |
{} |
6 |
10 Oct 05 |
enell |
453 |
} |