Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java @ 7377:ad2fdc34910a
Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 17 Oct 2013 17:47:58 +0200 |
parents | 550cb41d37d9 |
children | fc8d5b5f2c99 |
comparison
equal
deleted
inserted
replaced
7376:4b26fd60105f | 7377:ad2fdc34910a |
---|---|
47 private static final Pattern META_Q_RANGE = | 47 private static final Pattern META_Q_RANGE = |
48 Pattern.compile("Abfluss\\s\\[(.*)\\];(.*)"); | 48 Pattern.compile("Abfluss\\s\\[(.*)\\];(.*)"); |
49 | 49 |
50 public static final Pattern META_UNIT = | 50 public static final Pattern META_UNIT = |
51 Pattern.compile("^Einheit: \\[(.*)\\].*"); | 51 Pattern.compile("^Einheit: \\[(.*)\\].*"); |
52 | |
53 public static final double INTERVAL_GAP = 0.00001d; | |
52 | 54 |
53 private List<ImportWst> waterlevels; | 55 private List<ImportWst> waterlevels; |
54 | 56 |
55 private ImportWst current; | 57 private ImportWst current; |
56 | 58 |
115 @Override | 117 @Override |
116 protected void finish() { | 118 protected void finish() { |
117 if (current != null) { | 119 if (current != null) { |
118 if (currentQRange != null) { | 120 if (currentQRange != null) { |
119 List<ImportWstColumnValue> cValues = column.getColumnValues(); | 121 List<ImportWstColumnValue> cValues = column.getColumnValues(); |
120 // Set end of range to last station. | 122 // Set end of range to last station |
121 currentRange.setB(cValues.get(cValues.size() -1).getPosition()); | 123 // or expand range to minimal length in case it would be 0 |
124 // TODO: should otherwise be extended to | |
125 // (first station of next range - INTERVAL_GAP), | |
126 // assuming always ascending stations | |
127 BigDecimal lastStation = cValues.get(cValues.size() -1).getPosition(); | |
128 if (lastStation.compareTo(currentRange.getA()) == 0) { | |
129 currentRange.setB(new BigDecimal(lastStation.doubleValue() | |
130 + INTERVAL_GAP)); | |
131 } | |
132 else { | |
133 currentRange.setB(lastStation); | |
134 } | |
135 | |
122 currentQRange.setRange(currentRange); | 136 currentQRange.setRange(currentRange); |
123 column.addColumnQRange(currentQRange); | 137 column.addColumnQRange(currentQRange); |
124 } | 138 } |
125 | 139 |
126 waterlevels.add(current); | 140 waterlevels.add(current); |