comparison flys-backend/src/main/java/de/intevation/flys/importer/PRFParser.java @ 1200:7c88650ff548

PRFParser: Added a callback to be called from parsePRFs() if a PRF was parsed successfully. flys-backend/trunk@2304 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 07 Jul 2011 14:51:08 +0000
parents cc8f770796cb
children 22858e7cca79
comparison
equal deleted inserted replaced
1199:cc8f770796cb 1200:7c88650ff548
38 38
39 public static final int MIN_YEAR = 1800; 39 public static final int MIN_YEAR = 1800;
40 public static final int MAX_YEAR = 2100; 40 public static final int MAX_YEAR = 2100;
41 41
42 public static final double X_EPSILON = 1e-4; 42 public static final double X_EPSILON = 1e-4;
43
44 public interface PRFCallback {
45 void found(PRFParser parser);
46 } // interface PRFParser
43 47
44 public static final class XY 48 public static final class XY
45 implements Comparable<XY> 49 implements Comparable<XY>
46 { 50 {
47 protected double x; 51 protected double x;
63 if (x > other.x + X_EPSILON) return +1; 67 if (x > other.x + X_EPSILON) return +1;
64 if (index < other.index) return -1; 68 if (index < other.index) return -1;
65 if (index > other.index) return +1; 69 if (index > other.index) return +1;
66 return 0; 70 return 0;
67 } 71 }
72
73 public double getX() {
74 return x;
75 }
76
77 public void setX(double x) {
78 this.x = x;
79 }
80
81 public double getY() {
82 return y;
83 }
84
85 public void setY(double y) {
86 this.y = y;
87 }
88
89 public int getIndex() {
90 return index;
91 }
92
93 public void setIndex(int index) {
94 this.index = index;
95 }
68 } // class XY 96 } // class XY
69 97
70 public static class DataFormat { 98 public static class DataFormat {
71 99
72 protected int deleteChars; 100 protected int deleteChars;
402 data.clear(); 430 data.clear();
403 year = null; 431 year = null;
404 description = null; 432 description = null;
405 } 433 }
406 434
407 public static void parsePRFs(File root) { 435 public static void parsePRFs(File root, PRFCallback callback) {
408 436
409 PRFParser parser = new PRFParser(); 437 PRFParser parser = new PRFParser();
410 438
411 Stack<File> stack = new Stack<File>(); 439 Stack<File> stack = new Stack<File>();
412 stack.push(root); 440 stack.push(root);
425 && file.getName().toLowerCase().endsWith(".prf") 453 && file.getName().toLowerCase().endsWith(".prf")
426 ) { 454 ) {
427 parser.reset(); 455 parser.reset();
428 boolean success = parser.parse(file); 456 boolean success = parser.parse(file);
429 log.info("parsing " + (success ? "succeeded" : "failed")); 457 log.info("parsing " + (success ? "succeeded" : "failed"));
458 if (success && callback != null) {
459 callback.found(parser);
460 }
430 } 461 }
431 } 462 }
432 } 463 }
433 464
434 public static void main(String [] args) { 465 public static void main(String [] args) {
435 466
436 for (String arg: args) { 467 for (String arg: args) {
437 parsePRFs(new File(arg)); 468 parsePRFs(new File(arg), null);
438 } 469 }
439 } 470 }
440 } 471 }
441 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 472 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org