6 |
10 Oct 05 |
enell |
1 |
/* |
782 |
18 Sep 08 |
jari |
$Id$ |
782 |
18 Sep 08 |
jari |
3 |
|
782 |
18 Sep 08 |
jari |
Copyright (C) 2006 Johan Enell |
782 |
18 Sep 08 |
jari |
5 |
|
782 |
18 Sep 08 |
jari |
This file is part of the se.lu.onk.BaseFile package, a utility |
782 |
18 Sep 08 |
jari |
package for reading files generated by BASE. The package is |
782 |
18 Sep 08 |
jari |
available at http://baseplugins.thep.lu.se/ and BASE web site is |
782 |
18 Sep 08 |
jari |
http://base.thep.lu.se |
782 |
18 Sep 08 |
jari |
10 |
|
782 |
18 Sep 08 |
jari |
This is free software; you can redistribute it and/or modify it |
782 |
18 Sep 08 |
jari |
under the terms of the GNU General Public License as published by |
782 |
18 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
782 |
18 Sep 08 |
jari |
(at your option) any later version. |
782 |
18 Sep 08 |
jari |
15 |
|
782 |
18 Sep 08 |
jari |
The software is distributed in the hope that it will be useful, but |
782 |
18 Sep 08 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
782 |
18 Sep 08 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
782 |
18 Sep 08 |
jari |
General Public License for more details. |
782 |
18 Sep 08 |
jari |
20 |
|
782 |
18 Sep 08 |
jari |
You should have received a copy of the GNU General Public License |
782 |
18 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
782 |
18 Sep 08 |
jari |
23 |
*/ |
6 |
10 Oct 05 |
enell |
24 |
package basefile; |
6 |
10 Oct 05 |
enell |
25 |
|
6 |
10 Oct 05 |
enell |
26 |
import java.util.ArrayList; |
6 |
10 Oct 05 |
enell |
27 |
import java.util.Arrays; |
248 |
28 Mar 07 |
enell |
28 |
import java.util.Collections; |
6 |
10 Oct 05 |
enell |
29 |
import java.util.HashMap; |
6 |
10 Oct 05 |
enell |
30 |
import java.util.List; |
248 |
28 Mar 07 |
enell |
31 |
import java.util.Map; |
6 |
10 Oct 05 |
enell |
32 |
|
6 |
10 Oct 05 |
enell |
33 |
/** |
6 |
10 Oct 05 |
enell |
* This class describes a section in a baseFile created from the BASE database. |
6 |
10 Oct 05 |
enell |
35 |
* |
6 |
10 Oct 05 |
enell |
* @author Johan Enell |
6 |
10 Oct 05 |
enell |
37 |
*/ |
6 |
10 Oct 05 |
enell |
38 |
/** |
6 |
10 Oct 05 |
enell |
39 |
* |
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 |
42 |
*/ |
6 |
10 Oct 05 |
enell |
43 |
public class BASEFileSection |
6 |
10 Oct 05 |
enell |
44 |
{ |
6 |
10 Oct 05 |
enell |
45 |
|
6 |
10 Oct 05 |
enell |
46 |
/** |
6 |
10 Oct 05 |
enell |
* The line number in the inputstream were the section starts |
6 |
10 Oct 05 |
enell |
48 |
*/ |
97 |
20 Apr 06 |
enell |
49 |
private int startLine; |
6 |
10 Oct 05 |
enell |
50 |
|
6 |
10 Oct 05 |
enell |
51 |
/** |
6 |
10 Oct 05 |
enell |
* The line number in the inpustream were the data in the section starts |
6 |
10 Oct 05 |
enell |
53 |
*/ |
97 |
20 Apr 06 |
enell |
54 |
private int dataStartLine; |
6 |
10 Oct 05 |
enell |
55 |
|
6 |
10 Oct 05 |
enell |
56 |
/** |
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 |
59 |
*/ |
185 |
12 Oct 06 |
enell |
60 |
private final HashMap<String, String> headers = new HashMap<String, String>(); |
6 |
10 Oct 05 |
enell |
61 |
|
6 |
10 Oct 05 |
enell |
62 |
/** |
248 |
28 Mar 07 |
enell |
* The type of this section. |
248 |
28 Mar 07 |
enell |
64 |
*/ |
248 |
28 Mar 07 |
enell |
65 |
private String type; |
248 |
28 Mar 07 |
enell |
66 |
|
250 |
30 Mar 07 |
enell |
67 |
private boolean init = false; |
248 |
28 Mar 07 |
enell |
68 |
|
248 |
28 Mar 07 |
enell |
69 |
/** |
6 |
10 Oct 05 |
enell |
* Creates a new BASEFileSection. |
6 |
10 Oct 05 |
enell |
71 |
*/ |
250 |
30 Mar 07 |
enell |
72 |
@Deprecated |
6 |
10 Oct 05 |
enell |
73 |
public BASEFileSection() |
6 |
10 Oct 05 |
enell |
74 |
{ |
6 |
10 Oct 05 |
enell |
75 |
startLine = -1; |
6 |
10 Oct 05 |
enell |
76 |
dataStartLine = -1; |
248 |
28 Mar 07 |
enell |
77 |
type = ""; |
6 |
10 Oct 05 |
enell |
78 |
} |
6 |
10 Oct 05 |
enell |
79 |
|
250 |
30 Mar 07 |
enell |
80 |
/** |
250 |
30 Mar 07 |
enell |
* Creates a new BASEFileSection. |
250 |
30 Mar 07 |
enell |
82 |
*/ |
250 |
30 Mar 07 |
enell |
83 |
public BASEFileSection(String type) |
250 |
30 Mar 07 |
enell |
84 |
{ |
250 |
30 Mar 07 |
enell |
85 |
startLine = -1; |
250 |
30 Mar 07 |
enell |
86 |
dataStartLine = -1; |
250 |
30 Mar 07 |
enell |
87 |
this.type = type; |
250 |
30 Mar 07 |
enell |
88 |
} |
250 |
30 Mar 07 |
enell |
89 |
|
248 |
28 Mar 07 |
enell |
90 |
public BASEFileSection(BASEFileSection bfs) throws BASEFileException |
248 |
28 Mar 07 |
enell |
91 |
{ |
248 |
28 Mar 07 |
enell |
92 |
if (bfs == null) |
248 |
28 Mar 07 |
enell |
93 |
{ |
248 |
28 Mar 07 |
enell |
94 |
throw new BASEFileException("Can't initiate an assay section with a null section."); |
248 |
28 Mar 07 |
enell |
95 |
} |
248 |
28 Mar 07 |
enell |
96 |
startLine = bfs.getStartLine(); |
248 |
28 Mar 07 |
enell |
97 |
dataStartLine = bfs.getDataStartLine(); |
248 |
28 Mar 07 |
enell |
98 |
type = bfs.getType(); |
248 |
28 Mar 07 |
enell |
99 |
setHeaders(bfs.getHeaders()); |
248 |
28 Mar 07 |
enell |
100 |
} |
248 |
28 Mar 07 |
enell |
101 |
|
6 |
10 Oct 05 |
enell |
102 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as an int. |
6 |
10 Oct 05 |
enell |
104 |
* |
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 |
110 |
*/ |
105 |
02 Jun 06 |
enell |
111 |
public final Integer findIntOpt(String name) |
105 |
02 Jun 06 |
enell |
112 |
throws NumberFormatException |
6 |
10 Oct 05 |
enell |
113 |
{ |
6 |
10 Oct 05 |
enell |
114 |
String ret = headers.get(name); |
6 |
10 Oct 05 |
enell |
115 |
try |
6 |
10 Oct 05 |
enell |
116 |
{ |
105 |
02 Jun 06 |
enell |
117 |
return new Integer(ret); |
6 |
10 Oct 05 |
enell |
118 |
} |
6 |
10 Oct 05 |
enell |
119 |
catch (NumberFormatException e) |
6 |
10 Oct 05 |
enell |
120 |
{ |
264 |
27 Apr 07 |
enell |
121 |
throw new NumberFormatException("The value of parameter '" + name + "' is not an int: " + ret); |
6 |
10 Oct 05 |
enell |
122 |
} |
6 |
10 Oct 05 |
enell |
123 |
} |
6 |
10 Oct 05 |
enell |
124 |
|
6 |
10 Oct 05 |
enell |
125 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as a float. |
6 |
10 Oct 05 |
enell |
127 |
* |
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 |
133 |
*/ |
105 |
02 Jun 06 |
enell |
134 |
public Float findFloatOpt(String name) |
105 |
02 Jun 06 |
enell |
135 |
throws NumberFormatException |
6 |
10 Oct 05 |
enell |
136 |
{ |
6 |
10 Oct 05 |
enell |
137 |
String ret = headers.get(name); |
105 |
02 Jun 06 |
enell |
138 |
return new Float(ret); |
6 |
10 Oct 05 |
enell |
139 |
} |
6 |
10 Oct 05 |
enell |
140 |
|
6 |
10 Oct 05 |
enell |
141 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as a String. |
6 |
10 Oct 05 |
enell |
143 |
* |
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 |
147 |
*/ |
97 |
20 Apr 06 |
enell |
148 |
public final String findStringOpt(String name) |
6 |
10 Oct 05 |
enell |
149 |
{ |
6 |
10 Oct 05 |
enell |
150 |
String ret = headers.get(name); |
6 |
10 Oct 05 |
enell |
151 |
return ret; |
6 |
10 Oct 05 |
enell |
152 |
} |
6 |
10 Oct 05 |
enell |
153 |
|
6 |
10 Oct 05 |
enell |
154 |
/** |
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 |
157 |
* |
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 |
161 |
*/ |
97 |
20 Apr 06 |
enell |
162 |
public final String[] findStringOpts(String name) |
6 |
10 Oct 05 |
enell |
163 |
{ |
106 |
13 Jun 06 |
enell |
164 |
return findStringOpts(name, "\t"); |
6 |
10 Oct 05 |
enell |
165 |
} |
106 |
13 Jun 06 |
enell |
166 |
|
106 |
13 Jun 06 |
enell |
167 |
/** |
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 |
170 |
* |
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 |
174 |
*/ |
106 |
13 Jun 06 |
enell |
175 |
public final String[] findStringOpts(String name, String del) |
106 |
13 Jun 06 |
enell |
176 |
{ |
106 |
13 Jun 06 |
enell |
177 |
String value = headers.get(name); |
106 |
13 Jun 06 |
enell |
178 |
if (value != null) |
106 |
13 Jun 06 |
enell |
179 |
{ |
106 |
13 Jun 06 |
enell |
180 |
return value.split(del); |
106 |
13 Jun 06 |
enell |
181 |
} |
106 |
13 Jun 06 |
enell |
182 |
return null; |
106 |
13 Jun 06 |
enell |
183 |
} |
6 |
10 Oct 05 |
enell |
184 |
|
6 |
10 Oct 05 |
enell |
185 |
/** |
6 |
10 Oct 05 |
enell |
* Find the specified header from the headers and return it as a boolean. |
6 |
10 Oct 05 |
enell |
187 |
* |
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 |
193 |
*/ |
97 |
20 Apr 06 |
enell |
194 |
public final boolean findBooleanOpt(String name) |
6 |
10 Oct 05 |
enell |
195 |
{ |
6 |
10 Oct 05 |
enell |
196 |
String ret = headers.get(name); |
6 |
10 Oct 05 |
enell |
197 |
|
6 |
10 Oct 05 |
enell |
198 |
boolean value = false; |
6 |
10 Oct 05 |
enell |
199 |
try |
6 |
10 Oct 05 |
enell |
200 |
{ |
6 |
10 Oct 05 |
enell |
201 |
value = Boolean.valueOf(ret).booleanValue(); |
6 |
10 Oct 05 |
enell |
202 |
} |
6 |
10 Oct 05 |
enell |
203 |
catch (NumberFormatException e) |
6 |
10 Oct 05 |
enell |
204 |
{ |
6 |
10 Oct 05 |
enell |
205 |
throw new NumberFormatException("The value of parameter " + name + " is not a boolean: " + ret); |
6 |
10 Oct 05 |
enell |
206 |
} |
6 |
10 Oct 05 |
enell |
207 |
return value; |
6 |
10 Oct 05 |
enell |
208 |
} |
6 |
10 Oct 05 |
enell |
209 |
|
6 |
10 Oct 05 |
enell |
210 |
/** |
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 |
213 |
* |
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 |
217 |
*/ |
97 |
20 Apr 06 |
enell |
218 |
public final List<String> findFieldList(String name) |
6 |
10 Oct 05 |
enell |
219 |
{ |
6 |
10 Oct 05 |
enell |
220 |
String s = headers.get(name); |
6 |
10 Oct 05 |
enell |
221 |
if (s == null) return null; |
269 |
15 May 07 |
enell |
222 |
if (s.equals("")) return new ArrayList<String>(); |
6 |
10 Oct 05 |
enell |
223 |
return new ArrayList<String>(Arrays.asList(s.split("\\t"))); |
6 |
10 Oct 05 |
enell |
224 |
|
6 |
10 Oct 05 |
enell |
225 |
} |
6 |
10 Oct 05 |
enell |
226 |
|
6 |
10 Oct 05 |
enell |
227 |
/** |
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 |
230 |
* |
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 |
234 |
*/ |
97 |
20 Apr 06 |
enell |
235 |
public final List<Integer> findFieldIntList(String name) |
94 |
05 Apr 06 |
enell |
236 |
{ |
269 |
15 May 07 |
enell |
237 |
List<String> stringList = this.findFieldList(name); |
269 |
15 May 07 |
enell |
238 |
if (stringList == null) return null; |
94 |
05 Apr 06 |
enell |
239 |
ArrayList<Integer> ret = new ArrayList<Integer>(); |
269 |
15 May 07 |
enell |
240 |
for (String assay : stringList) |
94 |
05 Apr 06 |
enell |
241 |
{ |
94 |
05 Apr 06 |
enell |
242 |
ret.add(new Integer(assay)); |
94 |
05 Apr 06 |
enell |
243 |
} |
94 |
05 Apr 06 |
enell |
244 |
return ret; |
94 |
05 Apr 06 |
enell |
245 |
} |
94 |
05 Apr 06 |
enell |
246 |
|
94 |
05 Apr 06 |
enell |
247 |
/** |
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 |
251 |
* |
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 |
259 |
*/ |
97 |
20 Apr 06 |
enell |
260 |
public final String setHeader(Object key, Object value) |
6 |
10 Oct 05 |
enell |
261 |
{ |
248 |
28 Mar 07 |
enell |
262 |
String ret = ""; |
248 |
28 Mar 07 |
enell |
263 |
if ("section".equals(key)) |
248 |
28 Mar 07 |
enell |
264 |
{ |
248 |
28 Mar 07 |
enell |
265 |
ret = this.getType(); |
248 |
28 Mar 07 |
enell |
266 |
this.setType(value.toString()); |
248 |
28 Mar 07 |
enell |
267 |
} |
248 |
28 Mar 07 |
enell |
268 |
else |
248 |
28 Mar 07 |
enell |
269 |
{ |
248 |
28 Mar 07 |
enell |
270 |
ret = headers.put(key.toString(), value.toString()); |
248 |
28 Mar 07 |
enell |
271 |
} |
248 |
28 Mar 07 |
enell |
272 |
return ret; |
6 |
10 Oct 05 |
enell |
273 |
} |
6 |
10 Oct 05 |
enell |
274 |
|
6 |
10 Oct 05 |
enell |
275 |
/** |
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 |
280 |
* |
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 |
288 |
*/ |
97 |
20 Apr 06 |
enell |
289 |
public final String setHeader(Object key, Object... value) |
6 |
10 Oct 05 |
enell |
290 |
{ |
25 |
21 Oct 05 |
enell |
291 |
return this.setHeader(key, '\t', value); |
6 |
10 Oct 05 |
enell |
292 |
} |
6 |
10 Oct 05 |
enell |
293 |
|
6 |
10 Oct 05 |
enell |
294 |
/** |
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 |
299 |
* |
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 |
309 |
*/ |
97 |
20 Apr 06 |
enell |
310 |
public final String setHeader(Object key, char c, Object... value) |
6 |
10 Oct 05 |
enell |
311 |
{ |
6 |
10 Oct 05 |
enell |
312 |
StringBuffer s = new StringBuffer(""); |
6 |
10 Oct 05 |
enell |
313 |
if (value.length > 0) |
6 |
10 Oct 05 |
enell |
314 |
{ |
6 |
10 Oct 05 |
enell |
315 |
s = new StringBuffer(value[0].toString()); |
6 |
10 Oct 05 |
enell |
316 |
for (int i = 1; i < value.length; i++) |
6 |
10 Oct 05 |
enell |
317 |
{ |
6 |
10 Oct 05 |
enell |
318 |
s.append(c); |
6 |
10 Oct 05 |
enell |
319 |
s.append(value[i]); |
6 |
10 Oct 05 |
enell |
320 |
} |
6 |
10 Oct 05 |
enell |
321 |
} |
6 |
10 Oct 05 |
enell |
322 |
return this.setHeader(key, s); |
6 |
10 Oct 05 |
enell |
323 |
} |
6 |
10 Oct 05 |
enell |
324 |
|
97 |
20 Apr 06 |
enell |
325 |
public final String getHeader(Object key) |
6 |
10 Oct 05 |
enell |
326 |
{ |
6 |
10 Oct 05 |
enell |
327 |
return this.headers.get(key.toString()); |
6 |
10 Oct 05 |
enell |
328 |
} |
248 |
28 Mar 07 |
enell |
329 |
|
248 |
28 Mar 07 |
enell |
330 |
public final Map<String, String> getHeaders() |
248 |
28 Mar 07 |
enell |
331 |
{ |
248 |
28 Mar 07 |
enell |
332 |
return Collections.unmodifiableMap(this.headers); |
248 |
28 Mar 07 |
enell |
333 |
} |
6 |
10 Oct 05 |
enell |
334 |
|
97 |
20 Apr 06 |
enell |
335 |
public final String removeHeader(Object key) |
6 |
10 Oct 05 |
enell |
336 |
{ |
18 |
18 Oct 05 |
enell |
337 |
if (key.equals("section")) |
18 |
18 Oct 05 |
enell |
338 |
{ |
18 |
18 Oct 05 |
enell |
339 |
return ""; |
18 |
18 Oct 05 |
enell |
340 |
} |
6 |
10 Oct 05 |
enell |
341 |
return headers.remove(key.toString()); |
6 |
10 Oct 05 |
enell |
342 |
} |
6 |
10 Oct 05 |
enell |
343 |
|
248 |
28 Mar 07 |
enell |
344 |
final boolean setHeaders(Map<String, String> headers) |
97 |
20 Apr 06 |
enell |
345 |
{ |
185 |
12 Oct 06 |
enell |
346 |
if (headers == null) |
185 |
12 Oct 06 |
enell |
347 |
{ |
185 |
12 Oct 06 |
enell |
348 |
return false; |
185 |
12 Oct 06 |
enell |
349 |
} |
185 |
12 Oct 06 |
enell |
350 |
this.headers.clear(); |
185 |
12 Oct 06 |
enell |
351 |
for (String key : headers.keySet()) |
185 |
12 Oct 06 |
enell |
352 |
{ |
248 |
28 Mar 07 |
enell |
353 |
this.setHeader(key, headers.get(key)); |
185 |
12 Oct 06 |
enell |
354 |
} |
97 |
20 Apr 06 |
enell |
355 |
return true; |
97 |
20 Apr 06 |
enell |
356 |
} |
248 |
28 Mar 07 |
enell |
357 |
|
248 |
28 Mar 07 |
enell |
358 |
public int getColIndex(String header, String col) throws BASEFileException |
248 |
28 Mar 07 |
enell |
359 |
{ |
248 |
28 Mar 07 |
enell |
360 |
List<String> l = this.findFieldList(header); |
248 |
28 Mar 07 |
enell |
361 |
if (l == null) throw new BASEFileException("Can't find header "+header); |
248 |
28 Mar 07 |
enell |
362 |
int index = l.indexOf(col); |
248 |
28 Mar 07 |
enell |
363 |
if (index == -1) throw new BASEFileException("Can't find column "+col+" in header "+header); |
248 |
28 Mar 07 |
enell |
364 |
return index; |
248 |
28 Mar 07 |
enell |
365 |
} |
97 |
20 Apr 06 |
enell |
366 |
|
6 |
10 Oct 05 |
enell |
367 |
/** |
97 |
20 Apr 06 |
enell |
* Get the type of the section. |
6 |
10 Oct 05 |
enell |
369 |
* |
97 |
20 Apr 06 |
enell |
* @return The value of the header 'section' |
6 |
10 Oct 05 |
enell |
371 |
*/ |
97 |
20 Apr 06 |
enell |
372 |
public final String getType() |
6 |
10 Oct 05 |
enell |
373 |
{ |
248 |
28 Mar 07 |
enell |
374 |
return type; |
6 |
10 Oct 05 |
enell |
375 |
} |
250 |
30 Mar 07 |
enell |
376 |
|
250 |
30 Mar 07 |
enell |
377 |
protected boolean isInitiated() |
250 |
30 Mar 07 |
enell |
378 |
{ |
250 |
30 Mar 07 |
enell |
379 |
return init; |
250 |
30 Mar 07 |
enell |
380 |
} |
6 |
10 Oct 05 |
enell |
381 |
|
97 |
20 Apr 06 |
enell |
382 |
/** |
248 |
28 Mar 07 |
enell |
* Checks the type of this section. |
248 |
28 Mar 07 |
enell |
384 |
* |
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 |
387 |
*/ |
97 |
20 Apr 06 |
enell |
388 |
public final boolean isType(String string) |
97 |
20 Apr 06 |
enell |
389 |
{ |
97 |
20 Apr 06 |
enell |
390 |
return getType().equals(string); |
97 |
20 Apr 06 |
enell |
391 |
} |
248 |
28 Mar 07 |
enell |
392 |
|
248 |
28 Mar 07 |
enell |
393 |
/** |
248 |
28 Mar 07 |
enell |
* Sets the type of this section. |
248 |
28 Mar 07 |
enell |
395 |
* |
248 |
28 Mar 07 |
enell |
* @return the new type |
248 |
28 Mar 07 |
enell |
397 |
*/ |
250 |
30 Mar 07 |
enell |
398 |
@Deprecated |
248 |
28 Mar 07 |
enell |
399 |
public final void setType(String type) |
248 |
28 Mar 07 |
enell |
400 |
{ |
248 |
28 Mar 07 |
enell |
401 |
this.type = type; |
248 |
28 Mar 07 |
enell |
402 |
} |
105 |
02 Jun 06 |
enell |
403 |
|
97 |
20 Apr 06 |
enell |
404 |
public final int getDataStartLine() |
97 |
20 Apr 06 |
enell |
405 |
{ |
97 |
20 Apr 06 |
enell |
406 |
return dataStartLine; |
97 |
20 Apr 06 |
enell |
407 |
} |
97 |
20 Apr 06 |
enell |
408 |
|
248 |
28 Mar 07 |
enell |
409 |
@Deprecated |
97 |
20 Apr 06 |
enell |
410 |
public final void setDataStartLine(int dataStartLine) |
97 |
20 Apr 06 |
enell |
411 |
{ |
97 |
20 Apr 06 |
enell |
412 |
this.dataStartLine = dataStartLine; |
97 |
20 Apr 06 |
enell |
413 |
} |
97 |
20 Apr 06 |
enell |
414 |
public final int getStartLine() |
97 |
20 Apr 06 |
enell |
415 |
{ |
97 |
20 Apr 06 |
enell |
416 |
return startLine; |
97 |
20 Apr 06 |
enell |
417 |
} |
248 |
28 Mar 07 |
enell |
418 |
|
97 |
20 Apr 06 |
enell |
419 |
public final void setStartLine(int startLine) |
97 |
20 Apr 06 |
enell |
420 |
{ |
97 |
20 Apr 06 |
enell |
421 |
this.startLine = startLine; |
97 |
20 Apr 06 |
enell |
422 |
} |
97 |
20 Apr 06 |
enell |
423 |
|
103 |
01 Jun 06 |
enell |
424 |
public void clear() |
103 |
01 Jun 06 |
enell |
425 |
{ |
103 |
01 Jun 06 |
enell |
426 |
this.headers.clear(); |
103 |
01 Jun 06 |
enell |
427 |
startLine = -1; |
103 |
01 Jun 06 |
enell |
428 |
dataStartLine = -1; |
103 |
01 Jun 06 |
enell |
429 |
} |
103 |
01 Jun 06 |
enell |
430 |
|
31 |
08 Nov 05 |
enell |
431 |
@Override |
6 |
10 Oct 05 |
enell |
432 |
public String toString() |
6 |
10 Oct 05 |
enell |
433 |
{ |
6 |
10 Oct 05 |
enell |
434 |
String ret = "section\t" + this.getType() + "\n"; |
6 |
10 Oct 05 |
enell |
435 |
|
6 |
10 Oct 05 |
enell |
436 |
for (String key : headers.keySet()) |
6 |
10 Oct 05 |
enell |
437 |
{ |
248 |
28 Mar 07 |
enell |
438 |
ret += key + "\t" + headers.get(key) + "\n"; |
6 |
10 Oct 05 |
enell |
439 |
} |
6 |
10 Oct 05 |
enell |
440 |
ret += "%"; |
6 |
10 Oct 05 |
enell |
441 |
|
6 |
10 Oct 05 |
enell |
442 |
return ret; |
6 |
10 Oct 05 |
enell |
443 |
} |
250 |
30 Mar 07 |
enell |
444 |
|
250 |
30 Mar 07 |
enell |
445 |
protected void init() throws BASEFileException |
250 |
30 Mar 07 |
enell |
446 |
{ |
250 |
30 Mar 07 |
enell |
447 |
if (init) |
250 |
30 Mar 07 |
enell |
448 |
{ |
250 |
30 Mar 07 |
enell |
449 |
throw new BASEFileException("This section has already been initiated"); |
250 |
30 Mar 07 |
enell |
450 |
} |
250 |
30 Mar 07 |
enell |
451 |
init = true; |
250 |
30 Mar 07 |
enell |
452 |
} |
250 |
30 Mar 07 |
enell |
453 |
|
250 |
30 Mar 07 |
enell |
454 |
public void validate() throws BASEFileException |
250 |
30 Mar 07 |
enell |
455 |
{} |
6 |
10 Oct 05 |
enell |
456 |
} |