comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4082:d13011e53022

Make DIPS check more verbose flys-aft/trunk@3496 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 20 Dec 2011 14:36:36 +0000
parents 7a7b0f0cb653
children 44dc38ca8492
comparison
equal deleted inserted replaced
4081:7a7b0f0cb653 4082:d13011e53022
12 import org.w3c.dom.NodeList; 12 import org.w3c.dom.NodeList;
13 import org.w3c.dom.Element; 13 import org.w3c.dom.Element;
14 14
15 import de.intevation.db.ConnectedStatements; 15 import de.intevation.db.ConnectedStatements;
16 16
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19
20 public class River 17 public class River
21 extends IdPair 18 extends IdPair
22 { 19 {
23 private static Logger log = Logger.getLogger(River.class); 20 private static Logger log = Logger.getLogger(River.class);
24
25 public static final Pattern NUMBER = Pattern.compile("0*([0-9]+)");
26 21
27 protected String name; 22 protected String name;
28 23
29 public River() { 24 public River() {
30 } 25 }
37 public String getName() { 32 public String getName() {
38 return name; 33 return name;
39 } 34 }
40 35
41 public static Long numberToLong(String s) { 36 public static Long numberToLong(String s) {
42 Matcher m = NUMBER.matcher(s); 37 try {
43 if (!m.matches()) return null; 38 return Long.valueOf(s.trim());
44 String ns = m.group(1); 39 }
45 return Long.valueOf(ns.length() == 0 ? "0": ns); 40 catch (NumberFormatException nfe) {
41 }
42 return null;
46 } 43 }
47 44
48 public static Map<Long, DIPSGauge> indexByNumber(Document document) { 45 public static Map<Long, DIPSGauge> indexByNumber(Document document) {
49 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>(); 46 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>();
50 NodeList nodes = document.getElementsByTagName("PEGELSTATION"); 47 NodeList nodes = document.getElementsByTagName("PEGELSTATION");
51 for (int i = nodes.getLength()-1; i >= 0; --i) { 48 for (int i = nodes.getLength()-1; i >= 0; --i) {
52 Element element = (Element)nodes.item(i); 49 Element element = (Element)nodes.item(i);
53 Long number = numberToLong(element.getAttribute("NUMMER")); 50 String numberString = element.getAttribute("NUMMER");
51 Long number = numberToLong(numberString);
54 if (number != null) { 52 if (number != null) {
55 map.put(number, new DIPSGauge(element)); 53 DIPSGauge newG = new DIPSGauge(element);
54 DIPSGauge oldG = map.put(number, newG);
55 if (oldG != null) {
56 log.warn("DIPS: '" + newG.getName() +
57 "' collides with '" + oldG.getName() +
58 "' on gauge number " + number + ".");
59 }
60 }
61 else {
62 log.warn("DIPS: gauge '" + element.getAttribute("NAME") +
63 "' has invalid gauge number '" + numberString + "'");
56 } 64 }
57 } 65 }
58 return map; 66 return map;
59 } 67 }
60 68

http://dive4elements.wald.intevation.org