Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentDensityParser.java @ 8991:c43d8c1a4455
Parse via decimalformat instead of bigdecimal constructor (to cope with strings with chars after the actual number)
author | mschaefer |
---|---|
date | Tue, 10 Apr 2018 16:43:32 +0200 |
parents | 2693bfaf503d |
children |
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; |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
2817
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
11 import java.io.File; |
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
12 import java.io.IOException; |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
13 import java.math.BigDecimal; |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
14 import java.text.NumberFormat; |
8991
c43d8c1a4455
Parse via decimalformat instead of bigdecimal constructor (to cope with strings with chars after the actual number)
mschaefer
parents:
8989
diff
changeset
|
15 import java.text.ParseException; |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import java.util.ArrayList; |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import java.util.List; |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
18 import java.util.regex.Matcher; |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
19 import java.util.regex.Pattern; |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 import org.apache.log4j.Logger; |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
22 import org.dive4elements.river.importer.ImportDepth; |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
23 import org.dive4elements.river.importer.ImportSedimentDensity; |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
24 import org.dive4elements.river.importer.ImportSedimentDensityValue; |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
25 import org.dive4elements.river.importer.common.AbstractParser; |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 public class SedimentDensityParser extends LineParser { |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 private static final Logger log = |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
30 Logger.getLogger(SedimentDensityParser.class); |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
5565
a44a3f997ec8
Cleanup whitespace. Removed unused variable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5564
diff
changeset
|
32 public static final NumberFormat nf = |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
33 NumberFormat.getInstance(DEFAULT_LOCALE); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
34 |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
35 public static final Pattern META_DEPTH = |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
36 Pattern.compile("^Tiefe: (\\d++)-(\\d++).*"); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
37 |
6745
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
38 public static final Pattern META_YEAR = |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
39 Pattern.compile("^Jahr: (\\d{4}).*"); |
6745
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
40 |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 protected List<ImportSedimentDensity> sedimentDensities; |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 protected ImportSedimentDensity current; |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
2817
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
45 protected String currentDescription; |
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
46 |
6745
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
47 protected String yearString; |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 public SedimentDensityParser() { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
50 this.sedimentDensities = new ArrayList<>(); |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 } |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 @Override |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
55 public void parse(final File file) throws IOException { |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
56 this.currentDescription = file.getName(); |
2817
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
57 |
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
58 super.parse(file); |
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
59 } |
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
60 |
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
61 |
8979f2294af9
Finished parsing MINFO specific sediment density.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2816
diff
changeset
|
62 @Override |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 protected void reset() { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
64 this.current = new ImportSedimentDensity(this.currentDescription); |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 } |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 @Override |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 protected void finish() { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
70 if (this.current != null) { |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
71 this.sedimentDensities.add(this.current); |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 } |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 @Override |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
77 protected void handleLine(final int lineNum, final String line) { |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
78 if (line.startsWith(START_META_CHAR)) { |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
79 handleMetaLine(stripMetaLine(line)); |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
80 } |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
81 else { |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
82 handleDataLine(line); |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
83 } |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
84 } |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
85 |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
86 |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
87 protected void handleMetaLine(final String line) { |
5441
7c1dd9c3f6bd
remove unit from sediment density and depths (always t/m3 respectively cm, otherwise a typo)
Tom Gottfried <tom.gottfried@intevation.de>
parents:
4550
diff
changeset
|
88 if (handleMetaDepth(line)) { |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
89 return; |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
90 } |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
91 if (handleMetaYear(line)) { |
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
92 return; |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
93 } |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
94 log.warn("Unknown meta line: '" + line + "'"); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
95 } |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
96 |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
97 |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
98 protected boolean handleMetaDepth(final String line) { |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
99 final Matcher m = META_DEPTH.matcher(line); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
100 |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
101 if (m.matches()) { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
102 final String lo = m.group(1); |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
103 final String up = m.group(2); |
3942
43aa1ac8614b
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3940
diff
changeset
|
104 |
8856 | 105 log.info("Found sediment density depth: " |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
106 + lo + " - " + up + " cm"); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
107 |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
108 try { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
109 final ImportDepth depth = new ImportDepth( |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
110 AbstractParser.parseDecimal(lo), |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
111 AbstractParser.parseDecimal(up)); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
112 |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
113 this.current.setDepth(depth); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
114 |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
115 return true; |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
116 } |
8991
c43d8c1a4455
Parse via decimalformat instead of bigdecimal constructor (to cope with strings with chars after the actual number)
mschaefer
parents:
8989
diff
changeset
|
117 catch (final ParseException pe) { |
5490
b3dd14fc13a6
Parsers: do not call warnings error
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5441
diff
changeset
|
118 log.warn("Unparseable numbers in: '" + line + "'"); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
119 } |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
120 } |
3940
aed7aba93718
Improved logging and stabilized minfo import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2835
diff
changeset
|
121 else { |
aed7aba93718
Improved logging and stabilized minfo import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2835
diff
changeset
|
122 log.debug("Meta line doesn't contain depth information: " + line); |
aed7aba93718
Improved logging and stabilized minfo import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2835
diff
changeset
|
123 } |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
124 |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
125 return false; |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
126 } |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
127 |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
128 protected boolean handleMetaYear(final String line) { |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
129 final Matcher m = META_YEAR.matcher(line); |
6745
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
130 |
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
131 if (m.matches()) { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
132 this.yearString = m.group(1); |
6745
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
133 |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
134 log.info("Found sediment density year: " + this.yearString); |
6745
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
135 |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
136 return true; |
6745
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
137 } |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
138 |
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
139 log.debug("Meta line doesn't contain year: " + line); |
6745
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
140 |
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
141 return false; |
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
142 } |
bd437771ea00
Sediment density parser: fetch year from metaline and parse
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
143 |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
144 |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
145 protected void handleDataLine(final String line) { |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
146 final String[] vals = line.split(SEPERATOR_CHAR); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
147 |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
148 if (vals == null || vals.length < 3) { |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
149 log.warn("skip invalid data line: '" + line + "'"); |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
150 return; |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
151 } |
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
152 |
5507
db6c7268b08e
Schema change: add shore offset to sediment density values and be more rigid with input files in parser
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5505
diff
changeset
|
153 BigDecimal km = null; |
db6c7268b08e
Schema change: add shore offset to sediment density values and be more rigid with input files in parser
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5505
diff
changeset
|
154 BigDecimal shoreOffset = null; |
db6c7268b08e
Schema change: add shore offset to sediment density values and be more rigid with input files in parser
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5505
diff
changeset
|
155 BigDecimal density = null; |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
156 try { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
157 km = AbstractParser.parseDecimal(vals[0]); |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
158 density = AbstractParser.parseDecimal(vals[2]); |
5565
a44a3f997ec8
Cleanup whitespace. Removed unused variable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5564
diff
changeset
|
159 if (!vals[1].isEmpty()) { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
160 shoreOffset = AbstractParser.parseDecimal(vals[1]); |
5565
a44a3f997ec8
Cleanup whitespace. Removed unused variable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5564
diff
changeset
|
161 } |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
162 } |
8991
c43d8c1a4455
Parse via decimalformat instead of bigdecimal constructor (to cope with strings with chars after the actual number)
mschaefer
parents:
8989
diff
changeset
|
163 catch (final ParseException pe) { |
5490
b3dd14fc13a6
Parsers: do not call warnings error
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5441
diff
changeset
|
164 log.warn("Unparseable numbers in '" + line + "'"); |
2816
70b4a31a3306
Implemented the method stubs of the parser for sediment density and made some db schema adaptions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2815
diff
changeset
|
165 } |
4524
be9e28cff0c4
Parse and store year in sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
4193
diff
changeset
|
166 |
5565
a44a3f997ec8
Cleanup whitespace. Removed unused variable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5564
diff
changeset
|
167 if (km == null || density == null) { |
a44a3f997ec8
Cleanup whitespace. Removed unused variable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5564
diff
changeset
|
168 log.warn("SDP: No km nor density given. Skip line"); |
a44a3f997ec8
Cleanup whitespace. Removed unused variable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5564
diff
changeset
|
169 return; |
a44a3f997ec8
Cleanup whitespace. Removed unused variable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5564
diff
changeset
|
170 } |
5507
db6c7268b08e
Schema change: add shore offset to sediment density values and be more rigid with input files in parser
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5505
diff
changeset
|
171 |
4524
be9e28cff0c4
Parse and store year in sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
4193
diff
changeset
|
172 BigDecimal year = null; |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
173 if (this.yearString != null) { |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
174 try { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
175 year = AbstractParser.parseDecimal(this.yearString); |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
176 } |
8991
c43d8c1a4455
Parse via decimalformat instead of bigdecimal constructor (to cope with strings with chars after the actual number)
mschaefer
parents:
8989
diff
changeset
|
177 catch (final ParseException pe) { |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
178 log.warn("Unparseable year string"); |
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
179 } |
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6746
diff
changeset
|
180 } |
4524
be9e28cff0c4
Parse and store year in sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
4193
diff
changeset
|
181 |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
182 this.current.addValue(new ImportSedimentDensityValue( |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
183 km, |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
184 shoreOffset, |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
185 density, |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
186 year, |
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
187 this.currentDescription)); |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
188 } |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
189 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
190 |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
191 public List<ImportSedimentDensity> getSedimentDensities() { |
8989
2693bfaf503d
Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents:
8856
diff
changeset
|
192 return this.sedimentDensities; |
2815
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
193 } |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 } |
3febaed762b8
Added new parser (stub) to read MINFO sediment density files; prepared import process to handle those files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
195 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |