comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java @ 6932:b78d110135ec

(issue1451) Use distinct values for single_wq mode filtering instead of ranges.
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 27 Aug 2013 18:37:24 +0200
parents 862c7f511c35
children 1dff8e71c4d6
comparison
equal deleted inserted replaced
6931:2c8e5bad8699 6932:b78d110135ec
272 } 272 }
273 } 273 }
274 return list; 274 return list;
275 } 275 }
276 276
277 private static List<ValueRange> filterByQValues(double[] values, List<ValueRange> ranges) {
278 List<ValueRange> list = new ArrayList<ValueRange>(ranges.size());
279 for (ValueRange r: ranges) {
280 for (double val: values) {
281 if (r.sameValue(val) && !list.contains(r)) {
282 list.add(r);
283 }
284 }
285 }
286 return list;
287 }
288
277 private static boolean isQ(D4EArtifact artifact) { 289 private static boolean isQ(D4EArtifact artifact) {
278 Boolean b = artifact.getDataAsBoolean("wq_isq"); 290 Boolean b = artifact.getDataAsBoolean("wq_isq");
279 return b != null && b; 291 return b != null && b;
280 } 292 }
281 293
284 return b != null && b; 296 return b != null && b;
285 } 297 }
286 298
287 public static final Range Q_OUT_OF_RANGE = new Range(-10000, -9999); 299 public static final Range Q_OUT_OF_RANGE = new Range(-10000, -9999);
288 300
289 private static Range singleQs(D4EArtifact artifact) { 301 private static double[] singleQs(D4EArtifact artifact) {
290 String singleData = nn(artifact.getDataAsString("wq_single")); 302 String singleData = nn(artifact.getDataAsString("wq_single"));
291 double min = Double.MAX_VALUE; 303 String[] values = singleData.split(" ");
292 double max = -Double.MAX_VALUE; 304 double[] ret = new double[values.length];
293 305 int i = 0;
294 for (String value: singleData.split(" ")) { 306
307 for (String value: values) {
295 try { 308 try {
296 double x = Double.parseDouble(value); 309 ret[i] = Double.parseDouble(value);
297 if (x < min) min = x;
298 if (x > max) max = x;
299 } 310 }
300 catch (NumberFormatException nfe) { 311 catch (NumberFormatException nfe) {
301 } 312 ret[i] = -1; // INVALID_Q_VALUE
302 } 313 }
303 314 i++;
304 return min == Double.MAX_VALUE 315 }
305 ? Q_OUT_OF_RANGE 316
306 : new Range(min, max); 317 return ret;
307
308 } 318 }
309 319
310 private static Range qRange(D4EArtifact artifact) { 320 private static Range qRange(D4EArtifact artifact) {
311 try { 321 try {
312 Double from = artifact.getDataAsDouble("wq_from"); 322 Double from = artifact.getDataAsDouble("wq_from");
381 391
382 if (ranges.isEmpty()) { 392 if (ranges.isEmpty()) {
383 return Collections.<ValueRange>emptyList(); 393 return Collections.<ValueRange>emptyList();
384 } 394 }
385 395
386 Range qRange = isRange(artifact) 396 if (isRange(artifact)) {
387 ? qRange(artifact) 397 Range qRange = qRange(artifact);
388 : singleQs(artifact); 398 if (qRange == Q_OUT_OF_RANGE) {
389 399 qRange = tripleQRange(artifact);
390 if (qRange == Q_OUT_OF_RANGE) { 400 }
391 qRange = tripleQRange(artifact); 401 ranges = filterByQRange(qRange, ranges);
392 } 402 if (debug) {
393 403 log.debug("Q range filter: " + qRange);
394 if (debug) { 404 }
395 log.debug("Q range filter: " + qRange); 405 } else {
396 } 406 ranges = filterByQValues(singleQs(artifact), ranges);
397 407 }
398 ranges = filterByQRange(qRange, ranges);
399 408
400 if (debug) { 409 if (debug) {
401 log.debug("After q range filter: " + ranges); 410 log.debug("After q range filter: " + ranges);
402 } 411 }
403 412

http://dive4elements.wald.intevation.org