comparison backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java @ 6298:f095b58c95d9 double-precision

Bedheight single parser: do not reject lines with missing values
author Tom Gottfried <tom.gottfried@intevation.de>
date Wed, 12 Jun 2013 14:25:58 +0200
parents e7526a074c0d
children 6c003cbb27f1
comparison
equal deleted inserted replaced
6274:3d8f9e3bbf2e 6298:f095b58c95d9
37 * Create ImportBedHeightSingleValue from a line of csv file, add 37 * Create ImportBedHeightSingleValue from a line of csv file, add
38 * it to the ImportBedHeight. 38 * it to the ImportBedHeight.
39 */ 39 */
40 @Override 40 @Override
41 protected void handleDataLine(ImportBedHeight obj, String line) { 41 protected void handleDataLine(ImportBedHeight obj, String line) {
42 log.debug(line);
42 String[] values = line.split(SEPERATOR_CHAR); 43 String[] values = line.split(SEPERATOR_CHAR);
43 44
44 if (values == null || (values.length != 1 && values.length < 6)) { 45 if (values == null || (values.length != 1 && values.length < 6)) {
45 //log.warn("BSP: Error while parsing data line: '" + line + "'"); 46 //log.warn("BSP: Error while parsing data line: '" + line + "'");
46 return; 47 return;
74 } 75 }
75 76
76 // Because we cannot enforce consistency of values with complete data 77 // Because we cannot enforce consistency of values with complete data
77 // via null constraints in the database (as there are "gap" values), 78 // via null constraints in the database (as there are "gap" values),
78 // do this checks manually. 79 // do this checks manually.
79 if (values[3].length() == 0 || values[4].length() == 0 80 // if (values[3].length() == 0 || values[4].length() == 0
80 || values[5].length() == 0) { 81 // || values[5].length() == 0) {
81 //log.warn("BSP: Error while parsing data row (manual null constraint violated)."); 82 //log.warn("BSP: Error while parsing data row (manual null constraint violated).");
82 return; 83 // return;
83 } 84 //}
84 85
85 try { 86 Double height = null;
86 ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( 87 if (values[1].length() > 0) {
87 (ImportBedHeightSingle) obj, 88 try {
88 km, 89 height = new Double(nf.parse(values[1]).doubleValue());
89 new Double(nf.parse(values[1]).doubleValue()), 90 }
90 new Double(nf.parse(values[2]).doubleValue()), 91 catch (ParseException e) {
91 new Double(nf.parse(values[3]).doubleValue()), 92 log.warn("BSP: unparseable height " + values[1]);
92 parseBigDecimal(values[4], line), 93 }
93 new Double(nf.parse(values[5]).doubleValue()) 94 }
94 );
95 95
96 obj.addValue(value); 96 Double uncertainty = null;
97 } 97 if (values[2].length() > 0) {
98 catch (ParseException e) { 98 try {
99 log.warn("BSP: unparseable value in data row.", e); 99 uncertainty = new Double(nf.parse(values[2]).doubleValue());
100 } 100 }
101 catch (ParseException e) {
102 log.warn("BSP: unparseable uncertainty value " + values[2]);
103 }
104 }
105
106 Double dataGap = null;
107 if (values[3].length() > 0) {
108 try {
109 dataGap = new Double(nf.parse(values[3]).doubleValue());
110 }
111 catch (ParseException e) {
112 log.warn("BSP: unparseable data gap " + values[3]);
113 }
114 }
115
116 Double soundingWidth = null;
117 if (values[4].length() > 0) {
118 try {
119 soundingWidth = new Double(nf.parse(values[4]).doubleValue());
120 }
121 catch (ParseException e) {
122 log.warn("BSP: unparseable sounding width " + values[4]);
123 }
124 }
125
126 Double width = null;
127 if (values[5].length() > 0) {
128 try {
129 width = new Double(nf.parse(values[5]).doubleValue());
130 }
131 catch (ParseException e) {
132 log.warn("BSP: unparseable width " + values[5]);
133 }
134 }
135
136 // try {
137 ImportBedHeightSingleValue value = new ImportBedHeightSingleValue(
138 (ImportBedHeightSingle) obj,
139 km,
140 height,//new Double(nf.parse(values[1]).doubleValue()),
141 uncertainty,
142 dataGap,
143 soundingWidth,
144 // parseBigDecimal(values[4], line),
145 width
146 );
147
148 obj.addValue(value);
149 // }
150 // catch (ParseException e) {
151 // log.warn("BSP: unparseable value in data row.", e);
152 //}
101 } 153 }
102 154
103 private BigDecimal parseBigDecimal(String value, String line) { 155 // private BigDecimal parseBigDecimal(String value, String line) {
104 BigDecimal result = null; 156 // BigDecimal result = null;
105 try { 157 // try {
106 Double dValue = Double.valueOf(value.replace(",", ".")); 158 // Double dValue = Double.valueOf(value.replace(",", "."));
107 result = new BigDecimal(dValue.doubleValue()); 159 // result = new BigDecimal(dValue.doubleValue());
108 } 160 // }
109 catch (NumberFormatException nfe) { 161 // catch (NumberFormatException nfe) {
110 log.warn( 162 // log.warn(
111 "Could not parse " + 163 // "Could not parse " +
112 value + 164 // value +
113 " in bed heigt single row: " 165 // " in bed heigt single row: "
114 + line); 166 // + line);
115 } 167 // }
116 return result; 168 // return result;
117 } 169 // }
118 } 170 }
119 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 171 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org