annotate backend/src/main/java/org/dive4elements/river/importer/parsers/HYKParser.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents 139b057a39dd
children 0a5239a1e46e
rev   line source
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
6 * documentation coming with Dive4Elements River for details.
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
9 package org.dive4elements.river.importer.parsers;
1234
c5c48f52dc7b Removed FileTools that has been moved to artifacts-common module.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1225
diff changeset
10
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
11 import org.dive4elements.artifacts.common.utils.FileTools;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
12
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
13 import org.dive4elements.river.importer.ImportHYK;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
14 import org.dive4elements.river.importer.ImportHYKEntry;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
15 import org.dive4elements.river.importer.ImportHYKFormation;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
16 import org.dive4elements.river.importer.ImportHYKFlowZone;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
17 import org.dive4elements.river.importer.ImportHYKFlowZoneType;
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import java.io.File;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import java.io.IOException;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import java.io.FileInputStream;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 import java.io.InputStreamReader;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 import java.io.LineNumberReader;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 import java.util.HashMap;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 import java.util.Map;
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
27 import java.util.Date;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
28 import java.util.Calendar;
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 import java.math.BigDecimal;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 import org.apache.log4j.Logger;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public class HYKParser
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 private static Logger log = Logger.getLogger(HYKParser.class);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
38 public interface Callback {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
39 boolean hykAccept(File file);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
40 void hykParsed(HYKParser parser);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
41 } // interface Callback
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
42
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 public static enum State {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 LINE_1, LINE_2, LINE_3, LINE_4, LINE_5, LINE_6
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 };
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 private static final String ENCODING = "ISO-8859-1";
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 protected Map<String, ImportHYKFlowZoneType> flowZoneTypes;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
51 protected ImportHYK hyk;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
52
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 public HYKParser() {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 flowZoneTypes = new HashMap<String, ImportHYKFlowZoneType>();
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
57 public ImportHYK getHYK() {
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
58 return hyk;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
59 }
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
60
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
61 private static Date yearToDate(Integer year) {
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
62 if (year == null) {
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
63 return null;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
64 }
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
65 Calendar cal = Calendar.getInstance();
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
66 cal.set(year, 0, 1, 12, 0, 0);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
67 long ms = cal.getTimeInMillis();
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
68 cal.setTimeInMillis(ms - ms%1000);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
69 return cal.getTime();
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
70 }
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
71
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 public boolean parse(File file) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
74 boolean debug = log.isDebugEnabled();
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
75
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 log.info("Parsing HYK file '" + file + "'");
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 LineNumberReader in = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
80 String description =
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
81 file.getParentFile().getName() + "/" + file.getName();
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
82
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
83 hyk = new ImportHYK(null, description);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
84
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 in =
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 new LineNumberReader(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 new InputStreamReader(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 new FileInputStream(file), ENCODING));
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 String line;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 State state = State.LINE_1;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 int numFormations = 0;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 BigDecimal km = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 BigDecimal top = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 BigDecimal bottom = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 BigDecimal distanceVL = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 BigDecimal distanceHF = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 BigDecimal distanceVR = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 Integer year = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 int numZones = 0;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 ImportHYKFlowZoneType [] fzts = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 BigDecimal [] coords = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 int coordPos = 0;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
111 ImportHYKEntry entry = null;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
112 ImportHYKFormation formation = null;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
113
8020
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
114 BigDecimal lastZoneEnd = null;
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
115
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 while ((line = in.readLine()) != null) {
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
117
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
118 if (line.startsWith("*") || line.startsWith("----")) {
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 continue;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 }
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
121
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
122 line = line.trim();
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
123
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
124 if (state != State.LINE_5 && line.length() == 0) {
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 continue;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 }
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
127
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 String [] parts = line.split("\\s+");
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
130 if (debug) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
131 log.debug("'" + line + "': " + state);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
132 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
133
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 switch (state) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 case LINE_1:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 if (parts.length < 2) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
137 log.error("HYK 1: not enough elements in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 if (parts.length == 2) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 // no year given
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 year = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 else {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 year = Integer.valueOf(parts[1]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 catch (NumberFormatException nfe) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 log.error(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 "year is not an integer in line " +
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 km = new BigDecimal(parts[0]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 numFormations = Integer.parseInt(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 parts[parts.length > 2 ? 2 : 1]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 catch (NumberFormatException nfe) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 log.error(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 "parsing number of formations " +
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 "or km failed in line " + in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 }
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
168 entry = new ImportHYKEntry(hyk, km, yearToDate(year));
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
169 hyk.addEntry(entry);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 state = State.LINE_2;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 case LINE_2:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 if (parts.length < 3) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
176 log.error("HYK 2: not enough elements in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 numZones = Integer.parseInt(parts[0]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 bottom = new BigDecimal(parts[1]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 top = new BigDecimal(parts[2]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 catch (NumberFormatException nfe) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 log.error(
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
187 "HYK: parsing num zones, bottom or top height "
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
188 + "failed in line " + in.getLineNumber());
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 }
8020
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
191
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
192 if (parts.length > 3) {
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
193 try {
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
194 lastZoneEnd = new BigDecimal(parts[3]);
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
195 }
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
196 catch (NumberFormatException nfe) {
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
197 log.error(
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
198 "HYK: parsing last flow zone end in " +
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
199 "failed in line " + in.getLineNumber());
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
200 return false;
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
201 }
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
202 }
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
203 else {
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
204 lastZoneEnd = null;
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
205 }
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
206
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
207 formation = new ImportHYKFormation();
1224
ca7d461a53f1 HYK importer: Various small fixes and some extra logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1219
diff changeset
208 formation.setBottom(bottom);
ca7d461a53f1 HYK importer: Various small fixes and some extra logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1219
diff changeset
209 formation.setTop(top);
ca7d461a53f1 HYK importer: Various small fixes and some extra logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1219
diff changeset
210 entry.addFormation(formation);
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
211
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 state = State.LINE_3;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215 case LINE_3:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216 if (parts.length != numZones) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 log.error(
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
218 "HYK: number of flow zones mismatches " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219 "in line " + in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 fzts = new ImportHYKFlowZoneType[parts.length];
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 for (int i = 0; i < fzts.length; ++i) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 fzts[i] = getFlowZoneType(parts[i]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 }
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
227 coords = new BigDecimal[numZones];
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228 state = State.LINE_4;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 case LINE_4:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233 int N = Math.min(parts.length, coords.length);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 for (coordPos = 0; coordPos < N; ++coordPos) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235 coords[coordPos] =
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 new BigDecimal(parts[coordPos]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 catch (NumberFormatException nfe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
240 log.error("HYK: cannot parse number in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
241 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
242 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
243 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
244 state = State.LINE_5;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
245 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
246
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
247 case LINE_5:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
248 if (parts.length + coordPos < coords.length) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
249 log.error("HYK 5: not enough elements in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
250 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
251 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
253 try {
3334
2ae732e2c65c FLYS backend: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1234
diff changeset
254 for (int i = 0;
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
255 i < parts.length && coordPos < coords.length;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
256 ++i, ++coordPos
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
257 ) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
258 coords[coordPos] = new BigDecimal(parts[i]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
259 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
260 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
261 catch (NumberFormatException nfe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
262 log.error("HYK: cannot parse number in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
263 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
264 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
265 }
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
266 for (int i = 0; i < coords.length; ++i) {
1225
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
267 BigDecimal a = coords[i];
8020
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
268 BigDecimal b = i == coords.length-1
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
269 ? (lastZoneEnd != null
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
270 ? lastZoneEnd
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
271 : coords[i])
8020
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
272 : coords[i+1];
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
273
1225
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
274 if (a.compareTo(b) > 0) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
275 log.warn(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
276 "HYK: zone coordinates swapped in line " +
1225
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
277 in.getLineNumber());
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
278 BigDecimal c = a; a = b; b = c;
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
279 }
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
280 ImportHYKFlowZone zone = new ImportHYKFlowZone(
1225
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
281 formation, fzts[i], a, b);
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
282 formation.addFlowZone(zone);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
283 }
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
284 state = State.LINE_6;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
285 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
286
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
287 case LINE_6:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
288 if (parts.length < 3) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
289 log.error("HYK 6: not enough elements in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
290 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
292 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
293 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
294 distanceVL = new BigDecimal(parts[0]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
295 distanceHF = new BigDecimal(parts[1]);
1224
ca7d461a53f1 HYK importer: Various small fixes and some extra logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1219
diff changeset
296 distanceVR = new BigDecimal(parts[2]);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
297 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
298 catch (NumberFormatException nfe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
299 log.error("HYK: cannot parse number in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
300 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
301 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
302 }
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
303 formation.setDistanceVL(distanceVL);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
304 formation.setDistanceHF(distanceHF);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
305 formation.setDistanceVR(distanceVR);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
306
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
307 // continue with next formation.
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
308 state = --numFormations > 0 // formations left?
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
309 ? State.LINE_2
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
310 : State.LINE_1;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
311 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
312 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
313 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
314 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
315 catch (IOException ioe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
316 log.error("HYK: Error reading file.", ioe);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
317 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
318 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
319 finally {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
320 if (in != null) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
321 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
322 in.close();
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
323 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
324 catch (IOException ioe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
325 log.error("HYK: Error closing file.", ioe);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
326 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
327 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
328 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
329 return true;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
330 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
331
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
332 protected ImportHYKFlowZoneType getFlowZoneType(String name) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
333 name = name.toUpperCase();
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
334 ImportHYKFlowZoneType fzt = flowZoneTypes.get(name);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
335 if (fzt == null) {
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
336 log.info("New flow zone type: " + name);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
337 fzt = new ImportHYKFlowZoneType(name);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
338 flowZoneTypes.put(name, fzt);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
339 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
340 return fzt;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
341 }
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
342
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
343 protected void reset() {
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
344 hyk = null;
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
345 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
346
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
347 public void parseHYKs(File root, final Callback callback) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
348
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
349 FileTools.walkTree(root, new FileTools.FileVisitor() {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
350 @Override
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
351 public boolean visit(File file) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
352 if (file.isFile() && file.canRead()
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
353 && file.getName().toLowerCase().endsWith(".hyk")
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
354 && (callback == null || callback.hykAccept(file))) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
355 reset();
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
356 boolean success = parse(file);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
357 log.info("parsing " + (success ? "succeeded" : "failed"));
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
358 if (success && callback != null) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
359 callback.hykParsed(HYKParser.this);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
360 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
361 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
362 return true;
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
363 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
364 });
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
365 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
366
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
367 public static void main(String [] args) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
368
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
369 HYKParser parser = new HYKParser();
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
370
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
371 for (String arg: args) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
372 parser.parseHYKs(new File(arg), null);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
373 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
374 }
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
375 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
376 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org