Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java @ 2060:3ffb7195173f
Validate user defined Qs based on the start kilometer ('Q free').
flys-artifacts/trunk@3553 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 28 Dec 2011 12:39:35 +0000 |
parents | 522826b41ffa |
children | 87f9153bb7ca |
comparison
equal
deleted
inserted
replaced
2059:522826b41ffa | 2060:3ffb7195173f |
---|---|
220 String name, | 220 String name, |
221 CallContext context) | 221 CallContext context) |
222 { | 222 { |
223 // TODO Insert correct min/max values! | 223 // TODO Insert correct min/max values! |
224 double[] minmaxW = determineMinMaxW(artifact); | 224 double[] minmaxW = determineMinMaxW(artifact); |
225 double[] minmaxQ = determineMinMaxQ(artifact); | 225 double[] minmaxQ = determineMinMaxQAtGauge(artifact); |
226 | 226 |
227 if (name.equals("wq_from")) { | 227 if (name.equals("wq_from")) { |
228 Element minW = createItem( | 228 Element minW = createItem( |
229 cr, new String[] {"minW", new Double(minmaxW[0]).toString()}); | 229 cr, new String[] {"minW", new Double(minmaxW[0]).toString()}); |
230 Element minQ = createItem( | 230 Element minQ = createItem( |
354 * | 354 * |
355 * @param artifact The FLYSArtifact. | 355 * @param artifact The FLYSArtifact. |
356 * | 356 * |
357 * @return the min and max Q values for the current gauge. | 357 * @return the min and max Q values for the current gauge. |
358 */ | 358 */ |
359 protected double[] determineMinMaxQ(Artifact artifact) { | 359 protected double[] determineMinMaxQAtGauge(Artifact artifact) { |
360 logger.debug("WQSelect.determineMinMaxQ"); | 360 logger.debug("WQSelect.determineMinMaxQAtGauge"); |
361 | 361 |
362 WINFOArtifact flysArtifact = (WINFOArtifact) artifact; | 362 WINFOArtifact flysArtifact = (WINFOArtifact) artifact; |
363 | 363 |
364 River river = FLYSUtils.getRiver(flysArtifact); | 364 River river = FLYSUtils.getRiver(flysArtifact); |
365 Gauge gauge = flysArtifact.getGauge(); | 365 Gauge gauge = flysArtifact.getGauge(); |
371 | 371 |
372 double minQ = minmaxQ != null ? minmaxQ[0] : Double.MIN_VALUE; | 372 double minQ = minmaxQ != null ? minmaxQ[0] : Double.MIN_VALUE; |
373 double maxQ = minmaxQ != null ? minmaxQ[1] : Double.MAX_VALUE; | 373 double maxQ = minmaxQ != null ? minmaxQ[1] : Double.MAX_VALUE; |
374 | 374 |
375 return new double[] { minQ, maxQ }; | 375 return new double[] { minQ, maxQ }; |
376 } | |
377 | |
378 | |
379 /** | |
380 * Determines the min and max Q value for the current kilometer range. If no | |
381 * min and max values could be determined, this method will return | |
382 * | |
383 * @param artifact The FLYSArtifact. | |
384 * | |
385 * @return the min and max Q values for the current kilometer range. | |
386 */ | |
387 protected double[] determineMinMaxQ(Artifact artifact) { | |
388 logger.debug("WQSelect.determineMinMaxQ"); | |
389 | |
390 FLYSArtifact flys = (FLYSArtifact) artifact; | |
391 double[] kms = FLYSUtils.getKmRange(flys); | |
392 | |
393 if (kms == null || kms.length == 0) { | |
394 return new double[] { Double.MIN_VALUE, Double.MAX_VALUE }; | |
395 } | |
396 | |
397 River river = FLYSUtils.getRiver(flys); | |
398 Wst wst = WstFactory.getWst(river); | |
399 | |
400 logger.debug("User defined KMs: " + kms[0] + " - " + kms[kms.length-1]); | |
401 | |
402 double[] minmaxQ = wst.determineMinMaxQ(kms[0], kms[0]); | |
403 | |
404 return minmaxQ != null | |
405 ? minmaxQ | |
406 : new double[] { Double.MIN_VALUE, Double.MAX_VALUE }; | |
376 } | 407 } |
377 | 408 |
378 | 409 |
379 @Override | 410 @Override |
380 public boolean validate(Artifact artifact) | 411 public boolean validate(Artifact artifact) |
444 } | 475 } |
445 } | 476 } |
446 | 477 |
447 all.sort(); | 478 all.sort(); |
448 | 479 |
449 StateData dMode = getData(flys, WQ_MODE); | 480 FLYSUtils.WQ_MODE mode = FLYSUtils.getWQMode(flys); |
450 String mode = dMode != null ? (String) data.getValue() : null; | |
451 | 481 |
452 logger.debug("WQ Mode: " + mode); | 482 logger.debug("WQ Mode: " + mode); |
453 | 483 |
454 double[] minmax = null; | 484 double[] minmax = null; |
455 | 485 |
456 if (mode != null && mode.trim().toLowerCase().equals("w")) { | 486 if (mode == FLYSUtils.WQ_MODE.WGAUGE) { |
457 minmax = determineMinMaxW(artifact); | 487 minmax = determineMinMaxW(artifact); |
488 } | |
489 else if (mode == FLYSUtils.WQ_MODE.QGAUGE) { | |
490 minmax = determineMinMaxQAtGauge(artifact); | |
458 } | 491 } |
459 else { | 492 else { |
460 minmax = determineMinMaxQ(artifact); | 493 minmax = determineMinMaxQ(artifact); |
461 } | 494 } |
462 | 495 |
472 | 505 |
473 protected boolean validateRange(Artifact artifact) | 506 protected boolean validateRange(Artifact artifact) |
474 throws IllegalArgumentException | 507 throws IllegalArgumentException |
475 { | 508 { |
476 logger.debug("WQSelect.validateRange"); | 509 logger.debug("WQSelect.validateRange"); |
477 WINFOArtifact flys = (WINFOArtifact) artifact; | 510 |
478 | 511 WINFOArtifact flys = (WINFOArtifact) artifact; |
479 StateData data = flys.getData(WQ_MODE); | 512 FLYSUtils.WQ_MODE mode = FLYSUtils.getWQMode(flys); |
480 String mode = data != null ? (String) data.getValue() : null; | 513 |
481 logger.debug("WQ Mode: " + mode); | 514 if (mode == null) { |
482 | |
483 if (mode == null || mode.length() == 0) { | |
484 throw new IllegalArgumentException("error_feed_invalid_wq_mode"); | 515 throw new IllegalArgumentException("error_feed_invalid_wq_mode"); |
485 } | 516 } |
486 | 517 |
487 StateData dFrom = flys.getData(WQ_FROM); | 518 StateData dFrom = flys.getData(WQ_FROM); |
488 StateData dTo = flys.getData(WQ_TO); | 519 StateData dTo = flys.getData(WQ_TO); |
499 try { | 530 try { |
500 double from = Double.parseDouble(fromStr); | 531 double from = Double.parseDouble(fromStr); |
501 double to = Double.parseDouble(toStr); | 532 double to = Double.parseDouble(toStr); |
502 double step = Double.parseDouble(stepStr); | 533 double step = Double.parseDouble(stepStr); |
503 | 534 |
504 if (mode != null && mode.trim().toLowerCase().equals("w")) { | 535 if (mode == FLYSUtils.WQ_MODE.WGAUGE) { |
505 return validateW(artifact, from, to, step); | 536 return validateGaugeW(artifact, from, to, step); |
506 } | 537 } |
507 else if (mode != null && mode.trim().toLowerCase().equals("q")) { | 538 else if (mode == FLYSUtils.WQ_MODE.QGAUGE) { |
508 return validateQ(artifact, from, to, step); | 539 return validateGaugeQ(artifact, from, to, step); |
540 } | |
541 else if (mode == FLYSUtils.WQ_MODE.QFREE) { | |
542 return validateFreeQ(artifact, from, to, step); | |
509 } | 543 } |
510 else { | 544 else { |
511 throw new IllegalArgumentException( | 545 throw new IllegalArgumentException( |
512 "error_feed_invalid_wq_mode"); | 546 "error_feed_invalid_wq_mode"); |
513 } | 547 } |
526 * @param to The upper value of the W range. | 560 * @param to The upper value of the W range. |
527 * @param step The step width. | 561 * @param step The step width. |
528 * | 562 * |
529 * @return true, if everything was fine, otherwise an exception is thrown. | 563 * @return true, if everything was fine, otherwise an exception is thrown. |
530 */ | 564 */ |
531 protected boolean validateW( | 565 protected boolean validateGaugeW( |
532 Artifact artifact, | 566 Artifact artifact, |
533 double from, | 567 double from, |
534 double to, | 568 double to, |
535 double step) | 569 double step) |
536 throws IllegalArgumentException | 570 throws IllegalArgumentException |
537 { | 571 { |
538 logger.debug("WQSelect.validateW"); | 572 logger.debug("WQSelect.validateGaugeW"); |
539 | 573 |
540 double[] minmaxW = determineMinMaxW(artifact); | 574 double[] minmaxW = determineMinMaxW(artifact); |
541 | 575 |
542 return validateBounds(minmaxW[0], minmaxW[1], from, to, step); | 576 return validateBounds(minmaxW[0], minmaxW[1], from, to, step); |
543 } | 577 } |
544 | 578 |
545 | 579 |
546 /** | 580 /** |
547 * Validates the inserted Q values. | 581 * Validates the inserted Q values based on the Q range for the current |
582 * gauge. | |
548 * | 583 * |
549 * @param artifact The owner artifact. | 584 * @param artifact The owner artifact. |
550 * @param from The lower value of the Q range. | 585 * @param from The lower value of the Q range. |
551 * @param to The upper value of the Q range. | 586 * @param to The upper value of the Q range. |
552 * @param step The step width. | 587 * @param step The step width. |
553 * | 588 * |
554 * @return true, if everything was fine, otherwise an exception is thrown. | 589 * @return true, if everything was fine, otherwise an exception is thrown. |
555 */ | 590 */ |
556 protected boolean validateQ( | 591 protected boolean validateGaugeQ( |
557 Artifact artifact, | 592 Artifact artifact, |
558 double from, | 593 double from, |
559 double to, | 594 double to, |
560 double step) | 595 double step) |
561 throws IllegalArgumentException | 596 throws IllegalArgumentException |
562 { | 597 { |
563 logger.debug("WQSelect.validateQ"); | 598 logger.debug("WQSelect.validateGaugeQ"); |
599 | |
600 double[] minmaxQ = determineMinMaxQAtGauge(artifact); | |
601 | |
602 return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); | |
603 } | |
604 | |
605 | |
606 /** | |
607 * Validates the inserted Q values based on the Q range for the current | |
608 * kilometer range. | |
609 * | |
610 * @param artifact The owner artifact. | |
611 * @param from The lower value of the Q range. | |
612 * @param to The upper value of the Q range. | |
613 * @param step The step width. | |
614 * | |
615 * @return true, if everything was fine, otherwise an exception is thrown. | |
616 */ | |
617 protected boolean validateFreeQ( | |
618 Artifact artifact, | |
619 double from, | |
620 double to, | |
621 double step) | |
622 throws IllegalArgumentException | |
623 { | |
624 logger.debug("WQSelect.validateFreeQ"); | |
564 | 625 |
565 double[] minmaxQ = determineMinMaxQ(artifact); | 626 double[] minmaxQ = determineMinMaxQ(artifact); |
566 | 627 |
567 return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); | 628 return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); |
568 } | 629 } |