Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java @ 4715:2f7a509f5acf
Implement new CrossSectionParser interface.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 19 Dec 2012 14:59:14 +0100 |
parents | e8381265871f |
children | 0df1cac6c4b5 |
comparison
equal
deleted
inserted
replaced
4714:47c1d656a152 | 4715:2f7a509f5acf |
---|---|
24 | 24 |
25 /** | 25 /** |
26 * Parse files in .prf format and generate a mapping of double | 26 * Parse files in .prf format and generate a mapping of double |
27 * (km) to List of Points (XY). | 27 * (km) to List of Points (XY). |
28 */ | 28 */ |
29 public class PRFParser | 29 public class PRFParser implements CrossSectionParser |
30 { | 30 { |
31 private static Logger log = Logger.getLogger(PRFParser.class); | 31 private static Logger log = Logger.getLogger(PRFParser.class); |
32 | 32 |
33 public static final String ENCODING = | 33 public static final String ENCODING = |
34 System.getProperty("flys.backend.prf.encoding", "ISO-8859-1"); | 34 System.getProperty("flys.backend.prf.encoding", "ISO-8859-1"); |
44 public static final Pattern YEAR_PATTERN = | 44 public static final Pattern YEAR_PATTERN = |
45 Pattern.compile("(\\d{4})"); | 45 Pattern.compile("(\\d{4})"); |
46 | 46 |
47 public static final int MIN_YEAR = 1800; | 47 public static final int MIN_YEAR = 1800; |
48 public static final int MAX_YEAR = 2100; | 48 public static final int MAX_YEAR = 2100; |
49 | |
50 public interface Callback { | |
51 boolean prfAccept(File file); | |
52 void prfParsed(PRFParser parser); | |
53 } // interface Parser | |
54 | 49 |
55 public static class DataFormat { | 50 public static class DataFormat { |
56 | 51 |
57 protected int deleteChars; | 52 protected int deleteChars; |
58 protected int maxRepetitions; | 53 protected int maxRepetitions; |
186 | 181 |
187 public PRFParser() { | 182 public PRFParser() { |
188 data = new TreeMap<Double, List<XY>>(); | 183 data = new TreeMap<Double, List<XY>>(); |
189 } | 184 } |
190 | 185 |
186 @Override | |
191 public Integer getYear() { | 187 public Integer getYear() { |
192 return year; | 188 return year; |
193 } | 189 } |
194 | 190 |
195 public void setYear(Integer year) { | 191 public void setYear(Integer year) { |
196 this.year = year; | 192 this.year = year; |
197 } | 193 } |
198 | 194 |
195 @Override | |
199 public String getDescription() { | 196 public String getDescription() { |
200 return description; | 197 return description; |
201 } | 198 } |
202 | 199 |
203 public void setDescription(String description) { | 200 public void setDescription(String description) { |
204 this.description = description; | 201 this.description = description; |
205 } | 202 } |
206 | 203 |
204 @Override | |
207 public Map<Double, List<XY>> getData() { | 205 public Map<Double, List<XY>> getData() { |
208 return data; | 206 return data; |
209 } | 207 } |
210 | 208 |
211 public void setData(Map<Double, List<XY>> data) { | 209 public void setData(Map<Double, List<XY>> data) { |
394 data.clear(); | 392 data.clear(); |
395 year = null; | 393 year = null; |
396 description = null; | 394 description = null; |
397 } | 395 } |
398 | 396 |
399 public void parsePRFs(File root, final Callback callback) { | 397 public void parsePRFs(File root, final CrossSectionParser.Callback callback) { |
400 | 398 |
401 FileTools.walkTree(root, new FileTools.FileVisitor() { | 399 FileTools.walkTree(root, new FileTools.FileVisitor() { |
402 @Override | 400 @Override |
403 public boolean visit(File file) { | 401 public boolean visit(File file) { |
404 if (file.isFile() && file.canRead() | 402 if (file.isFile() && file.canRead() |
405 && file.getName().toLowerCase().endsWith(".prf") | 403 && file.getName().toLowerCase().endsWith(".prf") |
406 && (callback == null || callback.prfAccept(file))) { | 404 && (callback == null || callback.accept(file))) { |
407 reset(); | 405 reset(); |
408 boolean success = parse(file); | 406 boolean success = parse(file); |
409 log.info("parsing " + (success ? "succeeded" : "failed")); | 407 log.info("parsing " + (success ? "succeeded" : "failed")); |
410 if (success && callback != null) { | 408 if (success && callback != null) { |
411 callback.prfParsed(PRFParser.this); | 409 callback.parsed(PRFParser.this); |
412 } | 410 } |
413 } | 411 } |
414 return true; | 412 return true; |
415 } | 413 } |
416 }); | 414 }); |