Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java @ 5507:db6c7268b08e
Schema change: add shore offset to sediment density values and be more rigid with input files in parser
author | Tom Gottfried <tom.gottfried@intevation.de> |
---|---|
date | Thu, 28 Mar 2013 16:41:30 +0100 |
parents | 1b036a409575 |
children | c6e552348934 |
comparison
equal
deleted
inserted
replaced
5506:57f802db5c5a | 5507:db6c7268b08e |
---|---|
83 | 83 |
84 protected void handleMetaLine(String line) { | 84 protected void handleMetaLine(String line) { |
85 if (handleMetaDepth(line)) { | 85 if (handleMetaDepth(line)) { |
86 return; | 86 return; |
87 } | 87 } |
88 else if (handleMetaColumns(line)) { | |
89 return; | |
90 } | |
91 else { | 88 else { |
92 log.warn("Unknown meta line: '" + line + "'"); | 89 log.warn("Unknown meta line: '" + line + "'"); |
93 } | 90 } |
94 } | |
95 | |
96 | |
97 private boolean handleMetaColumns(String line) { | |
98 String[] columns = line.split(";"); | |
99 for (int i = 0; i < columns.length; i++) { | |
100 if (columns[i].contains("Sedimentdichte")) { | |
101 this.densitsyColumn = i; | |
102 return true; | |
103 } | |
104 } | |
105 return false; | |
106 } | 91 } |
107 | 92 |
108 | 93 |
109 protected boolean handleMetaDepth(String line) { | 94 protected boolean handleMetaDepth(String line) { |
110 Matcher m = META_DEPTH.matcher(line); | 95 Matcher m = META_DEPTH.matcher(line); |
143 if (vals == null || vals.length < 3) { | 128 if (vals == null || vals.length < 3) { |
144 log.warn("skip invalid data line: '" + line + "'"); | 129 log.warn("skip invalid data line: '" + line + "'"); |
145 return; | 130 return; |
146 } | 131 } |
147 | 132 |
148 BigDecimal km; | 133 BigDecimal km = null; |
149 BigDecimal density; | 134 BigDecimal shoreOffset = null; |
135 BigDecimal density = null; | |
150 try { | 136 try { |
151 km = new BigDecimal(nf.parse(vals[0]).doubleValue()); | 137 km = new BigDecimal(nf.parse(vals[0]).doubleValue()); |
152 density = new BigDecimal(nf.parse(vals[this.densitsyColumn]).doubleValue()); | 138 density = new BigDecimal(nf.parse(vals[2]).doubleValue()); |
153 | 139 if (!vals[1].isEmpty()) { |
140 shoreOffset = new BigDecimal(nf.parse(vals[1]).doubleValue()); | |
141 } | |
154 } | 142 } |
155 catch (ParseException pe) { | 143 catch (ParseException pe) { |
156 log.warn("Unparseable numbers in '" + line + "'"); | 144 log.warn("Unparseable numbers in '" + line + "'"); |
157 return; | |
158 } | 145 } |
146 | |
147 if (km == null || density == null) { | |
148 log.warn("SDP: No km nor density given. Skip line"); | |
149 return; | |
150 } | |
159 | 151 |
160 BigDecimal year = null; | 152 BigDecimal year = null; |
161 try { | 153 try { |
162 year = | 154 year = |
163 new BigDecimal(nf.parse(vals[vals.length - 1]).doubleValue()); | 155 new BigDecimal(nf.parse(vals[vals.length - 1]).doubleValue()); |
174 } | 166 } |
175 } | 167 } |
176 | 168 |
177 current.addValue(new ImportSedimentDensityValue( | 169 current.addValue(new ImportSedimentDensityValue( |
178 km, | 170 km, |
171 shoreOffset, | |
179 density, | 172 density, |
180 year, | 173 year, |
181 vals[vals.length - 1]) | 174 currentDescription) |
182 ); | 175 ); |
183 } | 176 } |
184 | 177 |
185 | 178 |
186 public List<ImportSedimentDensity> getSedimentDensities() { | 179 public List<ImportSedimentDensity> getSedimentDensities() { |