248 |
28 Mar 07 |
enell |
1 |
/* |
248 |
28 Mar 07 |
enell |
$Id$ |
248 |
28 Mar 07 |
enell |
3 |
|
248 |
28 Mar 07 |
enell |
Copyright (C) 2006 Johan Enell |
248 |
28 Mar 07 |
enell |
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 |
248 |
28 Mar 07 |
enell |
10 |
|
782 |
18 Sep 08 |
jari |
This is free software; you can redistribute it and/or modify it |
248 |
28 Mar 07 |
enell |
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 |
248 |
28 Mar 07 |
enell |
(at your option) any later version. |
248 |
28 Mar 07 |
enell |
15 |
|
782 |
18 Sep 08 |
jari |
The software is distributed in the hope that it will be useful, but |
248 |
28 Mar 07 |
enell |
WITHOUT ANY WARRANTY; without even the implied warranty of |
782 |
18 Sep 08 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
248 |
28 Mar 07 |
enell |
General Public License for more details. |
248 |
28 Mar 07 |
enell |
20 |
|
248 |
28 Mar 07 |
enell |
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/>. |
248 |
28 Mar 07 |
enell |
23 |
*/ |
248 |
28 Mar 07 |
enell |
24 |
package basefile; |
248 |
28 Mar 07 |
enell |
25 |
|
265 |
27 Apr 07 |
enell |
26 |
import java.util.List; |
265 |
27 Apr 07 |
enell |
27 |
|
248 |
28 Mar 07 |
enell |
28 |
public abstract class BASEFileDataSection extends BASEFileSection |
248 |
28 Mar 07 |
enell |
29 |
{ |
248 |
28 Mar 07 |
enell |
30 |
|
248 |
28 Mar 07 |
enell |
31 |
protected int height; |
248 |
28 Mar 07 |
enell |
32 |
|
248 |
28 Mar 07 |
enell |
33 |
protected int width; |
248 |
28 Mar 07 |
enell |
34 |
|
248 |
28 Mar 07 |
enell |
35 |
public BASEFileDataSection(BASEFileSection bfs) throws BASEFileException |
248 |
28 Mar 07 |
enell |
36 |
{ |
248 |
28 Mar 07 |
enell |
37 |
super(bfs); |
248 |
28 Mar 07 |
enell |
38 |
} |
248 |
28 Mar 07 |
enell |
39 |
|
248 |
28 Mar 07 |
enell |
40 |
public BASEFileDataSection(BASEFileDataSection bfds) throws BASEFileException |
248 |
28 Mar 07 |
enell |
41 |
{ |
250 |
30 Mar 07 |
enell |
42 |
this((BASEFileSection)bfds); |
250 |
30 Mar 07 |
enell |
43 |
this.setWidth(bfds.getWidth()); |
250 |
30 Mar 07 |
enell |
44 |
this.setHeight(bfds.getHeight()); |
248 |
28 Mar 07 |
enell |
45 |
} |
248 |
28 Mar 07 |
enell |
46 |
|
250 |
30 Mar 07 |
enell |
47 |
protected BASEFileDataSection(String type) |
250 |
30 Mar 07 |
enell |
48 |
{ |
250 |
30 Mar 07 |
enell |
49 |
super(type); |
265 |
27 Apr 07 |
enell |
50 |
this.setCount(0); |
265 |
27 Apr 07 |
enell |
51 |
this.setColumns(); |
250 |
30 Mar 07 |
enell |
52 |
} |
250 |
30 Mar 07 |
enell |
53 |
|
248 |
28 Mar 07 |
enell |
54 |
public int getCount() |
248 |
28 Mar 07 |
enell |
55 |
{ |
248 |
28 Mar 07 |
enell |
56 |
return this.findIntOpt("count"); |
248 |
28 Mar 07 |
enell |
57 |
} |
248 |
28 Mar 07 |
enell |
58 |
|
248 |
28 Mar 07 |
enell |
59 |
public final int getHeight() |
248 |
28 Mar 07 |
enell |
60 |
{ |
248 |
28 Mar 07 |
enell |
61 |
return height; |
248 |
28 Mar 07 |
enell |
62 |
} |
248 |
28 Mar 07 |
enell |
63 |
|
248 |
28 Mar 07 |
enell |
64 |
public final int getWidth() |
248 |
28 Mar 07 |
enell |
65 |
{ |
248 |
28 Mar 07 |
enell |
66 |
return width; |
248 |
28 Mar 07 |
enell |
67 |
} |
250 |
30 Mar 07 |
enell |
68 |
|
265 |
27 Apr 07 |
enell |
69 |
public final List<String> getColumns() |
265 |
27 Apr 07 |
enell |
70 |
{ |
265 |
27 Apr 07 |
enell |
71 |
return this.findFieldList("columns"); |
265 |
27 Apr 07 |
enell |
72 |
} |
265 |
27 Apr 07 |
enell |
73 |
|
265 |
27 Apr 07 |
enell |
74 |
public final int getColumnsColIndex(String col) throws BASEFileException |
265 |
27 Apr 07 |
enell |
75 |
{ |
265 |
27 Apr 07 |
enell |
76 |
return this.getColIndex("columns", col); |
265 |
27 Apr 07 |
enell |
77 |
} |
265 |
27 Apr 07 |
enell |
78 |
|
265 |
27 Apr 07 |
enell |
79 |
public final String setColumns(Object... values) |
265 |
27 Apr 07 |
enell |
80 |
{ |
265 |
27 Apr 07 |
enell |
81 |
return setHeader("columns", values); |
265 |
27 Apr 07 |
enell |
82 |
} |
265 |
27 Apr 07 |
enell |
83 |
|
250 |
30 Mar 07 |
enell |
84 |
public final String setCount(int c) |
248 |
28 Mar 07 |
enell |
85 |
{ |
250 |
30 Mar 07 |
enell |
86 |
return setHeader("count", c); |
248 |
28 Mar 07 |
enell |
87 |
} |
248 |
28 Mar 07 |
enell |
88 |
|
248 |
28 Mar 07 |
enell |
89 |
public final void setHeight(int height) |
248 |
28 Mar 07 |
enell |
90 |
{ |
248 |
28 Mar 07 |
enell |
91 |
this.height = height; |
248 |
28 Mar 07 |
enell |
92 |
} |
248 |
28 Mar 07 |
enell |
93 |
|
248 |
28 Mar 07 |
enell |
94 |
public final void setWidth(int width) |
248 |
28 Mar 07 |
enell |
95 |
{ |
248 |
28 Mar 07 |
enell |
96 |
this.width = width; |
248 |
28 Mar 07 |
enell |
97 |
} |
248 |
28 Mar 07 |
enell |
98 |
|
248 |
28 Mar 07 |
enell |
99 |
public abstract int getDataLineLength(); |
250 |
30 Mar 07 |
enell |
100 |
|
250 |
30 Mar 07 |
enell |
101 |
public abstract String getDataLine(int i); |
250 |
30 Mar 07 |
enell |
102 |
|
250 |
30 Mar 07 |
enell |
103 |
public void addData(Object... data) |
250 |
30 Mar 07 |
enell |
104 |
throws BASEFileException |
250 |
30 Mar 07 |
enell |
105 |
{ |
250 |
30 Mar 07 |
enell |
106 |
if (!isInitiated()) |
250 |
30 Mar 07 |
enell |
107 |
{ |
250 |
30 Mar 07 |
enell |
108 |
init(); |
250 |
30 Mar 07 |
enell |
109 |
} |
250 |
30 Mar 07 |
enell |
110 |
} |
250 |
30 Mar 07 |
enell |
111 |
|
250 |
30 Mar 07 |
enell |
112 |
@Override |
250 |
30 Mar 07 |
enell |
113 |
protected void init() throws BASEFileException |
250 |
30 Mar 07 |
enell |
114 |
{ |
250 |
30 Mar 07 |
enell |
115 |
super.init(); |
250 |
30 Mar 07 |
enell |
116 |
} |
250 |
30 Mar 07 |
enell |
117 |
|
250 |
30 Mar 07 |
enell |
118 |
@Override |
250 |
30 Mar 07 |
enell |
119 |
public void validate() throws BASEFileException |
250 |
30 Mar 07 |
enell |
120 |
{ |
250 |
30 Mar 07 |
enell |
121 |
super.validate(); |
250 |
30 Mar 07 |
enell |
122 |
if (getHeader("count") == null) throw new BadSectionException("Data section must contain count header"); |
250 |
30 Mar 07 |
enell |
123 |
} |
248 |
28 Mar 07 |
enell |
124 |
} |