Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentDensityParser.java @ 6745:bd437771ea00 double-precision
Sediment density parser: fetch year from metaline and parse
author | Tom Gottfried <tom.gottfried@intevation.de> |
---|---|
date | Fri, 02 Aug 2013 11:36:33 +0200 |
parents | 4c3ccf2b0304 |
children | d3c609581313 |
comparison
equal
deleted
inserted
replaced
6742:30c4276d09f8 | 6745:bd437771ea00 |
---|---|
37 NumberFormat.getInstance(DEFAULT_LOCALE); | 37 NumberFormat.getInstance(DEFAULT_LOCALE); |
38 | 38 |
39 public static final Pattern META_DEPTH = | 39 public static final Pattern META_DEPTH = |
40 Pattern.compile("^Tiefe: (\\w++)-(\\w++)( (\\w++))?.*"); | 40 Pattern.compile("^Tiefe: (\\w++)-(\\w++)( (\\w++))?.*"); |
41 | 41 |
42 public static final Pattern META_YEAR = | |
43 Pattern.compile("^Jahr: (\\d{4}).*"); | |
44 | |
42 protected List<ImportSedimentDensity> sedimentDensities; | 45 protected List<ImportSedimentDensity> sedimentDensities; |
43 | 46 |
44 protected ImportSedimentDensity current; | 47 protected ImportSedimentDensity current; |
45 | 48 |
46 protected String currentDescription; | 49 protected String currentDescription; |
47 | 50 |
51 protected String yearString; | |
48 | 52 |
49 public SedimentDensityParser() { | 53 public SedimentDensityParser() { |
50 sedimentDensities = new ArrayList<ImportSedimentDensity>(); | 54 sedimentDensities = new ArrayList<ImportSedimentDensity>(); |
51 } | 55 } |
52 | 56 |
86 | 90 |
87 protected void handleMetaLine(String line) { | 91 protected void handleMetaLine(String line) { |
88 if (handleMetaDepth(line)) { | 92 if (handleMetaDepth(line)) { |
89 return; | 93 return; |
90 } | 94 } |
95 else if (handleMetaYear(line)) { | |
96 return; | |
97 } | |
91 else { | 98 else { |
92 log.warn("Unknown meta line: '" + line + "'"); | 99 log.warn("Unknown meta line: '" + line + "'"); |
93 } | 100 } |
94 } | 101 } |
95 | 102 |
117 log.warn("Unparseable numbers in: '" + line + "'"); | 124 log.warn("Unparseable numbers in: '" + line + "'"); |
118 } | 125 } |
119 } | 126 } |
120 else { | 127 else { |
121 log.debug("Meta line doesn't contain depth information: " + line); | 128 log.debug("Meta line doesn't contain depth information: " + line); |
129 } | |
130 | |
131 return false; | |
132 } | |
133 | |
134 protected boolean handleMetaYear(String line) { | |
135 Matcher m = META_YEAR.matcher(line); | |
136 | |
137 if (m.matches()) { | |
138 yearString = m.group(1); | |
139 | |
140 log.info("Found sediment density year: " + yearString); | |
141 | |
142 return true; | |
143 } | |
144 else { | |
145 log.debug("Meta line doesn't contain year: " + line); | |
122 } | 146 } |
123 | 147 |
124 return false; | 148 return false; |
125 } | 149 } |
126 | 150 |
151 log.warn("SDP: No km nor density given. Skip line"); | 175 log.warn("SDP: No km nor density given. Skip line"); |
152 return; | 176 return; |
153 } | 177 } |
154 | 178 |
155 BigDecimal year = null; | 179 BigDecimal year = null; |
180 try { | |
181 year = new BigDecimal(nf.parse(yearString).doubleValue()); | |
182 } | |
183 catch (ParseException pe) { | |
184 log.warn("Unparseable year string"); | |
185 } | |
156 | 186 |
157 current.addValue(new ImportSedimentDensityValue( | 187 current.addValue(new ImportSedimentDensityValue( |
158 km, | 188 km, |
159 shoreOffset, | 189 shoreOffset, |
160 density, | 190 density, |