annotate backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java @ 8989:2693bfaf503d

Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
author mschaefer
date Mon, 09 Apr 2018 09:07:00 +0200
parents 5e38e2924c07
children c43d8c1a4455
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;
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
11 import java.io.File;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
12 import java.io.IOException;
5049
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
13 import java.math.BigDecimal;
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
14 import java.text.NumberFormat;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
15 import java.util.ArrayList;
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import java.util.List;
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
17 import java.util.regex.Matcher;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
18 import java.util.regex.Pattern;
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
20 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
21 import org.dive4elements.river.backend.utils.DateUtil;
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.ImportRange;
6319
550cb41d37d9 issue1354: TimeIntervals in Waterlevels from csv files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6282
diff changeset
23 import org.dive4elements.river.importer.ImportTimeInterval;
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
24 import org.dive4elements.river.importer.ImportUnit;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
25 import org.dive4elements.river.importer.ImportWst;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
26 import org.dive4elements.river.importer.ImportWstColumn;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
27 import org.dive4elements.river.importer.ImportWstColumnValue;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
28 import org.dive4elements.river.importer.ImportWstQRange;
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
29 import org.dive4elements.river.importer.common.AbstractParser;
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
5049
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
31
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
32 /**
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
33 * Parse CSV Waterlevel files.
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
34 * As these waterlevels are probably used in fixation analysis
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
35 * only, functionality to export them to "fixation"-wsts
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
36 * has been added (the ImportWaterlevel*- stuff is actually
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
37 * not needed to do so.)
b5e3df1feeb4 WaterlevelParser: Add Wst-Converting functionality.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5016
diff changeset
38 */
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 public class WaterlevelParser extends LineParser {
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
41 private static final Logger log = Logger.getLogger(WaterlevelParser.class);
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
42
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
43 private 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
44 NumberFormat.getInstance(DEFAULT_LOCALE);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
45
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
46 private static final Pattern META_Q_RANGE =
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
47 Pattern.compile("Abfluss\\s\\[(.*)\\];(.*)");
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
48
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
49 public static final Pattern META_UNIT =
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
50 Pattern.compile("^Einheit: \\[(.*)\\].*");
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
51
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
52 public static final BigDecimal INTERVAL_GAP = new BigDecimal("0.00001");
7377
ad2fdc34910a Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
Tom Gottfried <tom@intevation.de>
parents: 6319
diff changeset
53
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
54 private final List<ImportWst> waterlevels;
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
56 private ImportWst current;
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
57
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
58 /** The Waterlevel-Wst s will always have but one column. */
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
59 private ImportWstColumn column;
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
60
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
61 /** The current (incomplete) Q Range. */
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
62 private ImportWstQRange currentQRange;
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
63
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
64 /** The current (incomplete) km range for Q Range. */
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
65 private ImportRange currentRange;
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
66
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
67 private String currentDescription;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
68
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
69
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 public WaterlevelParser() {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
71 this.waterlevels = new ArrayList<>();
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 }
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
75 public List<ImportWst> getWaterlevels() {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
76 return this.waterlevels;
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 }
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 @Override
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
81 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
82 this.currentDescription = file.getName();
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
83
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
84 super.parse(file);
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
85 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
86
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
87
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
88 @Override
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 protected void reset() {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
90 this.currentQRange = null;
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
91 this.current = new ImportWst(this.currentDescription);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
92 this.current.setNumberColumns(1);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
93 this.column = this.current.getColumn(0);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
94 this.column.setName(this.currentDescription);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
95 this.column.setDescription(this.currentDescription);
6319
550cb41d37d9 issue1354: TimeIntervals in Waterlevels from csv files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6282
diff changeset
96
550cb41d37d9 issue1354: TimeIntervals in Waterlevels from csv files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6282
diff changeset
97 // Try to extract and set the TimeInterval.
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
98 final Matcher m = WaterlevelDifferencesParser.YEARS_IN_COLUMN.matcher(
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
99 this.currentDescription);
6319
550cb41d37d9 issue1354: TimeIntervals in Waterlevels from csv files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6282
diff changeset
100
550cb41d37d9 issue1354: TimeIntervals in Waterlevels from csv files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6282
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 int startYear = Integer.parseInt(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 int endYear = Integer.parseInt(m.group(2));
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
104 final ImportTimeInterval time = new ImportTimeInterval(
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
105 DateUtil.getStartDateFromYear(startYear),
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
106 DateUtil.getEndDateFromYear(endYear)
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
107 );
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
108 this.column.setTimeInterval(time);
6319
550cb41d37d9 issue1354: TimeIntervals in Waterlevels from csv files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6282
diff changeset
109 } else {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
110 log.debug("No time interval in column header found: "
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
111 + this.currentDescription);
6319
550cb41d37d9 issue1354: TimeIntervals in Waterlevels from csv files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6282
diff changeset
112 }
550cb41d37d9 issue1354: TimeIntervals in Waterlevels from csv files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6282
diff changeset
113
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
114 this.current.setKind(7);
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 }
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 @Override
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 protected void finish() {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
120 if (this.current != null) {
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
121 if (this.currentQRange != null) {
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
122 final List<ImportWstColumnValue> cValues = this.column.getColumnValues();
7377
ad2fdc34910a Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
Tom Gottfried <tom@intevation.de>
parents: 6319
diff changeset
123 // Set end of range to last station
ad2fdc34910a Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
Tom Gottfried <tom@intevation.de>
parents: 6319
diff changeset
124 // or expand range to minimal length in case it would be 0
7883
fc8d5b5f2c99 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7377
diff changeset
125 // TODO: should otherwise be extended to
fc8d5b5f2c99 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7377
diff changeset
126 // (first station of next range - INTERVAL_GAP),
7377
ad2fdc34910a Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
Tom Gottfried <tom@intevation.de>
parents: 6319
diff changeset
127 // assuming always ascending stations
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
128 final BigDecimal lastStation = cValues.get(cValues.size() -1)
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
129 .getPosition();
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
130 if (lastStation.compareTo(this.currentRange.getA()) == 0) {
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
131 this.currentRange.setB(lastStation.add(INTERVAL_GAP));
7377
ad2fdc34910a Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
Tom Gottfried <tom@intevation.de>
parents: 6319
diff changeset
132 }
ad2fdc34910a Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
Tom Gottfried <tom@intevation.de>
parents: 6319
diff changeset
133 else {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
134 this.currentRange.setB(lastStation);
7377
ad2fdc34910a Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
Tom Gottfried <tom@intevation.de>
parents: 6319
diff changeset
135 }
ad2fdc34910a Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
Tom Gottfried <tom@intevation.de>
parents: 6319
diff changeset
136
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
137 this.currentQRange.setRange(this.currentRange);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
138 this.column.addColumnQRange(this.currentQRange);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
139 }
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
141 this.waterlevels.add(this.current);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
142 }
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 }
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 @Override
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
146 protected void handleLine(final int lineNum, final String line) {
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
147 if (line.startsWith(START_META_CHAR)) {
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
148 handleMetaLine(stripMetaLine(line));
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
149 return;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
150 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
151 else if (handleQRange(line)) {
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
152 return;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
153 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
154 else {
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
155 handleDataLine(line);
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
156 return;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
157 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
158 }
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
160
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
161 private void handleMetaLine(final String meta) {
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
162 final Matcher m = META_UNIT.matcher(meta);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
163
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
164 if (m.matches()) {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
165 final String unit = m.group(1);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
166 log.debug("Found unit: '" + unit + "'");
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
167
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
168 this.current.setUnit(new ImportUnit(unit));
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
169 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
170 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
171
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
172
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
173 private boolean handleQRange(final String line) {
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
174 final Matcher m = META_Q_RANGE.matcher(line);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
175
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
176 if (m.matches()) {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
177 final String unitStr = m.group(1);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
178 final String valueStr = m.group(2);
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
179 try {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
180 if (this.currentQRange != null) {
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
181 // Finish off the last one.
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
182 final List<ImportWstColumnValue> cValues = this.column
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
183 .getColumnValues();
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
184 // Set end of range to last station.
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
185 this.currentRange.setB(cValues.get(cValues.size() -1)
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
186 .getPosition());
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
187 this.currentQRange.setRange(this.currentRange);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
188 this.column.addColumnQRange(this.currentQRange);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
189 }
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
190 this.currentQRange = new ImportWstQRange(null,
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
191 AbstractParser.parseDecimal(valueStr));
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
192 this.currentRange = new ImportRange();
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
193
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
194 log.debug("Found new Q range: Q=" + valueStr);
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
195
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
196 return true;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
197 }
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
198 catch (final NumberFormatException pe) {
5490
b3dd14fc13a6 Parsers: do not call warnings error
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5264
diff changeset
199 log.warn("Unparseable Q range: '" + line + "'");
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
200 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
201 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
202
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
203 return false;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
204 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
205
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
206
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
207 private 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
208 final String[] cols = line.split(SEPERATOR_CHAR);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
209
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
210 if (cols == null || cols.length < 2) {
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
211 log.warn("skip invalid waterlevel line: '" + line + "'");
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
212 return;
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
213 }
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
214
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
215 try {
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
216 // Store the value and remember the position for QRange, if needed.
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
217 final BigDecimal station = AbstractParser.parseDecimal(cols[0]);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
218 final BigDecimal value = AbstractParser.parseDecimal(cols[1]);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
219
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
220 this.column.addColumnValue(station, value);
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
221
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
222 if (this.currentRange.getA() == null) {
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
223 this.currentRange.setA(station);
5240
9c024718bffb WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5231
diff changeset
224 }
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
225 }
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8856
diff changeset
226 catch (final NumberFormatException pe) {
5490
b3dd14fc13a6 Parsers: do not call warnings error
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5264
diff changeset
227 log.warn("Unparseable number in data row: " + line);
2845
a65b5b0ade6f Completed the MINFO waterlevel import.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2844
diff changeset
228 }
2844
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229 }
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 }
c4db0f75a94a Prepared the importer to import MINFO specific waterlevel values and added a stub for a parser.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
231 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org