comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java @ 4715:2f7a509f5acf

Implement new CrossSectionParser interface.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 19 Dec 2012 14:59:14 +0100
parents 70842db72ee4
children e67d396ed65d
comparison
equal deleted inserted replaced
4714:47c1d656a152 4715:2f7a509f5acf
21 21
22 /** 22 /**
23 * To create cross-sections, generate: Map<double,list<xy>> from files 23 * To create cross-sections, generate: Map<double,list<xy>> from files
24 * in da66 format. 24 * in da66 format.
25 */ 25 */
26 public class DA66Parser extends LineParser 26 public class DA66Parser extends LineParser implements CrossSectionParser
27 { 27 {
28 /** Private logger. */ 28 /** Private logger. */
29 private static Logger logger = Logger.getLogger(DA66Parser.class); 29 private static Logger logger = Logger.getLogger(DA66Parser.class);
30 30
31 private static String HEAD_HEAD = "00"; 31 private static String HEAD_HEAD = "00";
158 158
159 /** The current line to which add points. */ 159 /** The current line to which add points. */
160 private List<XY> currentLine; 160 private List<XY> currentLine;
161 161
162 162
163 // TODO refactor, its shared with PRFParser.
164 public interface Callback {
165 boolean da66Accept(File file);
166 void da66Parsed(DA66Parser parser);
167 } // interface Parser
168
169
170 /** Data collected so far, last element will be currentLine. */ 163 /** Data collected so far, last element will be currentLine. */
171 protected Map<Double, List<XY>> data; 164 protected Map<Double, List<XY>> data;
172 165
173 166
174 public DA66Parser() { 167 public DA66Parser() {
175 data = new TreeMap<Double, List<XY>>(); 168 data = new TreeMap<Double, List<XY>>();
176 } 169 }
177 170
171 @Override
172 public String getDescription() {
173 return "da66-dummy";
174 }
175
176 @Override
177 public Integer getYear() {
178 return 2012;
179 }
180
181 @Override
178 public Map<Double, List<XY>> getData() { 182 public Map<Double, List<XY>> getData() {
179 return data; 183 return data;
180 } 184 }
181 185
182 public void setData(Map<Double, List<XY>> data) { 186 public void setData(Map<Double, List<XY>> data) {
196 FileTools.walkTree(root, new FileTools.FileVisitor() { 200 FileTools.walkTree(root, new FileTools.FileVisitor() {
197 @Override 201 @Override
198 public boolean visit(File file) { 202 public boolean visit(File file) {
199 if (file.isFile() && file.canRead() 203 if (file.isFile() && file.canRead()
200 && file.getName().toLowerCase().endsWith(".d66") 204 && file.getName().toLowerCase().endsWith(".d66")
201 && (callback == null || callback.da66Accept(file))) { 205 && (callback == null || callback.accept(file))) {
202 reset(); 206 reset();
203 try { 207 try {
204 parse(file); 208 parse(file);
205 logger.info("parsing done"); 209 logger.info("parsing done");
206 if (callback != null) { 210 if (callback != null) {
207 callback.da66Parsed(DA66Parser.this); 211 callback.parsed(DA66Parser.this);
208 } 212 }
209 } 213 }
210 catch (IOException ioe) { 214 catch (IOException ioe) {
211 logger.error("IOException while parsing file"); 215 logger.error("IOException while parsing file");
212 return false; 216 return false;
282 */ 286 */
283 @Override 287 @Override
284 protected void handleLine(int lineNum, String line) { 288 protected void handleLine(int lineNum, String line) {
285 String head = line.substring(0,2); 289 String head = line.substring(0,2);
286 if (HEAD_HEAD.equals(head)) { 290 if (HEAD_HEAD.equals(head)) {
287 logger.debug("Hit a 00"); 291 //logger.debug("New station");
288 Matcher m = LINE_PATTERN.matcher(line); 292 Matcher m = LINE_PATTERN.matcher(line);
289 if (m.find()) { 293 if (m.find()) {
290 // Actually matches! 294 // Actually matches!
291 currentLine = new ArrayList<XY>(); 295 currentLine = new ArrayList<XY>();
292 data.put(Double.parseDouble(m.group(FIELD.STATION.getIdx())), 296 data.put(Double.parseDouble(m.group(FIELD.STATION.getIdx())),

http://dive4elements.wald.intevation.org