comparison artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents a1ceacf15d3a
children 0d3d018fc632
comparison
equal deleted inserted replaced
8201:4b8c5a08de04 8202:e4606eae8ea5
56 * Instead use and/or create a {@link Access} class hierarchy. 56 * Instead use and/or create a {@link Access} class hierarchy.
57 **/ 57 **/
58 @Deprecated 58 @Deprecated
59 public class RiverUtils { 59 public class RiverUtils {
60 60
61 /** The logger that is used in this utility. */ 61 /** The log that is used in this utility. */
62 private static Logger logger = Logger.getLogger(RiverUtils.class); 62 private static Logger log = Logger.getLogger(RiverUtils.class);
63 63
64 /** 64 /**
65 * An enum that represents the 5 possible WQ modes in FLYS. The 5 values are 65 * An enum that represents the 5 possible WQ modes in FLYS. The 5 values are
66 * <i>QFREE</i> <i>QGAUGE</i> <i>WGAUGE</i> <i>WFREE</i> and <i>NONE</i>. 66 * <i>QFREE</i> <i>QGAUGE</i> <i>WGAUGE</i> <i>WFREE</i> and <i>NONE</i>.
67 */ 67 */
118 public static D4EArtifact getArtifact(String uuid, CallContext context) { 118 public static D4EArtifact getArtifact(String uuid, CallContext context) {
119 try { 119 try {
120 Artifact artifact = context.getDatabase().getRawArtifact(uuid); 120 Artifact artifact = context.getDatabase().getRawArtifact(uuid);
121 121
122 if (artifact == null) { 122 if (artifact == null) {
123 logger.error("Artifact '" + uuid + "' does not exist."); 123 log.error("Artifact '" + uuid + "' does not exist.");
124 return null; 124 return null;
125 } 125 }
126 126
127 if (!(artifact instanceof D4EArtifact)) { 127 if (!(artifact instanceof D4EArtifact)) {
128 logger.error("Artifact '" +uuid+ "' is no valid D4EArtifact."); 128 log.error("Artifact '" +uuid+ "' is no valid D4EArtifact.");
129 return null; 129 return null;
130 } 130 }
131 131
132 return (D4EArtifact) artifact; 132 return (D4EArtifact) artifact;
133 } 133 }
134 // TODO: catch more selective 134 // TODO: catch more selective
135 catch (Exception e) { 135 catch (Exception e) {
136 logger.error("Cannot get D4EArtifact " + uuid 136 log.error("Cannot get D4EArtifact " + uuid
137 + " from database (" + e.getMessage() + ")."); 137 + " from database (" + e.getMessage() + ").");
138 return null; 138 return null;
139 } 139 }
140 } 140 }
141 141
249 249
250 if (riverName == null) { 250 if (riverName == null) {
251 riverName = ""; 251 riverName = "";
252 } 252 }
253 253
254 logger.debug("Search for the min/max distances of '" + riverName + "'"); 254 log.debug("Search for the min/max distances of '" + riverName + "'");
255 255
256 // Why not use getRiver(flysArtifact) ? 256 // Why not use getRiver(flysArtifact) ?
257 River river = RiverFactory.getRiver(riverName); 257 River river = RiverFactory.getRiver(riverName);
258 258
259 return river != null 259 return river != null
317 for (String l: tmp) { 317 for (String l: tmp) {
318 try { 318 try {
319 locations.add(Double.parseDouble(l)); 319 locations.add(Double.parseDouble(l));
320 } 320 }
321 catch (NumberFormatException nfe) { 321 catch (NumberFormatException nfe) {
322 logger.debug(nfe.getLocalizedMessage(), nfe); 322 log.debug(nfe.getLocalizedMessage(), nfe);
323 } 323 }
324 } 324 }
325 325
326 locations.sort(); 326 locations.sort();
327 327
341 // XXX this is not nice! 341 // XXX this is not nice!
342 if (flys instanceof WINFOArtifact) { 342 if (flys instanceof WINFOArtifact) {
343 return ((WINFOArtifact) flys).getQs(); 343 return ((WINFOArtifact) flys).getQs();
344 } 344 }
345 345
346 logger.warn("This method (getQs) currently supports WINFOArtifact only!"); 346 log.warn("This method (getQs) currently supports WINFOArtifact only!");
347 347
348 return null; 348 return null;
349 } 349 }
350 350
351 351
361 // XXX this is not nice! 361 // XXX this is not nice!
362 if (flys instanceof WINFOArtifact) { 362 if (flys instanceof WINFOArtifact) {
363 return ((WINFOArtifact) flys).getWs(); 363 return ((WINFOArtifact) flys).getWs();
364 } 364 }
365 365
366 logger.warn("This method (getWs) currently supports WINFOArtifact only!"); 366 log.warn("This method (getWs) currently supports WINFOArtifact only!");
367 367
368 return null; 368 return null;
369 } 369 }
370 370
371 371
440 */ 440 */
441 public static Gauge getGauge(D4EArtifact flys) { 441 public static Gauge getGauge(D4EArtifact flys) {
442 River river = getRiver(flys); 442 River river = getRiver(flys);
443 443
444 if (river == null) { 444 if (river == null) {
445 logger.debug("no river found"); 445 log.debug("no river found");
446 return null; 446 return null;
447 } 447 }
448 448
449 RangeAccess rangeAccess = new RangeAccess(flys); 449 RangeAccess rangeAccess = new RangeAccess(flys);
450 double[] dist = rangeAccess.getKmRange(); 450 double[] dist = rangeAccess.getKmRange();
451 451
452 if (dist == null) { 452 if (dist == null) {
453 logger.debug("no range found"); 453 log.debug("no range found");
454 return null; 454 return null;
455 } 455 }
456 456
457 if (logger.isDebugEnabled()) { 457 if (log.isDebugEnabled()) {
458 logger.debug("Determine gauge for:"); 458 log.debug("Determine gauge for:");
459 logger.debug("... river: " + river.getName()); 459 log.debug("... river: " + river.getName());
460 logger.debug("... distance: " + dist[0] + " - " + dist[1]); 460 log.debug("... distance: " + dist[0] + " - " + dist[1]);
461 } 461 }
462 462
463 Gauge gauge = river.determineGauge(dist[0], dist[1]); 463 Gauge gauge = river.determineGauge(dist[0], dist[1]);
464 464
465 String name = gauge != null ? gauge.getName() : "'n/a"; 465 String name = gauge != null ? gauge.getName() : "'n/a";
466 logger.debug("Found gauge: " + name); 466 log.debug("Found gauge: " + name);
467 467
468 return gauge; 468 return gauge;
469 } 469 }
470 470
471 471
504 } 504 }
505 505
506 Matcher m = NUMBERS_PATTERN.matcher(wq.getName()); 506 Matcher m = NUMBERS_PATTERN.matcher(wq.getName());
507 507
508 if (m.matches()) { 508 if (m.matches()) {
509 logger.debug("Found a number."); 509 log.debug("Found a number.");
510 510
511 String raw = m.group(1); 511 String raw = m.group(1);
512 512
513 try { 513 try {
514 return Double.valueOf(raw); 514 return Double.valueOf(raw);
544 v = Double.valueOf(parts[1]); 544 v = Double.valueOf(parts[1]);
545 545
546 namedMainValue = getNamedMainValue(winfo.getGauge(), v); 546 namedMainValue = getNamedMainValue(winfo.getGauge(), v);
547 } 547 }
548 catch (NumberFormatException nfe) { 548 catch (NumberFormatException nfe) {
549 logger.warn("Cannot parse Double of: '" + parts[1] + "'"); 549 log.warn("Cannot parse Double of: '" + parts[1] + "'");
550 return name; 550 return name;
551 } 551 }
552 552
553 String prefix = null; 553 String prefix = null;
554 554
586 v = Double.valueOf(parts[1]); 586 v = Double.valueOf(parts[1]);
587 587
588 namedMainValue = getNamedMainValue(winfo.getGauge(), v); 588 namedMainValue = getNamedMainValue(winfo.getGauge(), v);
589 } 589 }
590 catch (NumberFormatException nfe) { 590 catch (NumberFormatException nfe) {
591 logger.warn("Cannot parse Double of: '" + parts[1] + "'"); 591 log.warn("Cannot parse Double of: '" + parts[1] + "'");
592 return name; 592 return name;
593 } 593 }
594 594
595 String prefix = null; 595 String prefix = null;
596 596
629 } 629 }
630 630
631 631
632 public static String getNamedMainValue(Gauge gauge, double value) { 632 public static String getNamedMainValue(Gauge gauge, double value) {
633 List<MainValue> mainValues = gauge.getMainValues(); 633 List<MainValue> mainValues = gauge.getMainValues();
634 logger.debug("Search named main value for: " + value); 634 log.debug("Search named main value for: " + value);
635 635
636 for (MainValue mv: mainValues) { 636 for (MainValue mv: mainValues) {
637 if (mv.getValue().doubleValue() == value) { 637 if (mv.getValue().doubleValue() == value) {
638 logger.debug("Found named main value: " + mv.getMainValue().getName()); 638 log.debug("Found named main value: " + mv.getMainValue().getName());
639 return mv.getMainValue().getName(); 639 return mv.getMainValue().getName();
640 } 640 }
641 } 641 }
642 642
643 logger.debug("Did not find a named main value for: " + value); 643 log.debug("Did not find a named main value for: " + value);
644 return null; 644 return null;
645 } 645 }
646 646
647 647
648 /** 648 /**
753 diffs += ";\n"; 753 diffs += ";\n";
754 } 754 }
755 return diffs; 755 return diffs;
756 } 756 }
757 else { 757 else {
758 logger.warn("Not a valid state for differences."); 758 log.warn("Not a valid state for differences.");
759 return ""; 759 return "";
760 } 760 }
761 } 761 }
762 762
763 /** 763 /**
770 */ 770 */
771 public static int[] intArrayFromString(String raw) { 771 public static int[] intArrayFromString(String raw) {
772 String[] splitted = raw != null ? raw.split(";") : null; 772 String[] splitted = raw != null ? raw.split(";") : null;
773 773
774 if (splitted == null || splitted.length == 0) { 774 if (splitted == null || splitted.length == 0) {
775 logger.warn("No integer values found in '" + raw + "'"); 775 log.warn("No integer values found in '" + raw + "'");
776 return new int[0]; 776 return new int[0];
777 } 777 }
778 778
779 TIntArrayList integers = new TIntArrayList(splitted.length); 779 TIntArrayList integers = new TIntArrayList(splitted.length);
780 780
781 for (String value: splitted) { 781 for (String value: splitted) {
782 try { 782 try {
783 integers.add(Integer.parseInt(value)); 783 integers.add(Integer.parseInt(value));
784 } 784 }
785 catch (NumberFormatException nfe) { 785 catch (NumberFormatException nfe) {
786 logger.warn("Parsing integer failed: " + nfe); 786 log.warn("Parsing integer failed: " + nfe);
787 } 787 }
788 } 788 }
789 789
790 return integers.toNativeArray(); 790 return integers.toNativeArray();
791 } 791 }
801 */ 801 */
802 public static long[] longArrayFromString(String raw) { 802 public static long[] longArrayFromString(String raw) {
803 String[] splitted = raw != null ? raw.split(";") : null; 803 String[] splitted = raw != null ? raw.split(";") : null;
804 804
805 if (splitted == null || splitted.length == 0) { 805 if (splitted == null || splitted.length == 0) {
806 logger.warn("No long values found in '" + raw + "'"); 806 log.warn("No long values found in '" + raw + "'");
807 return new long[0]; 807 return new long[0];
808 } 808 }
809 809
810 TLongArrayList longs = new TLongArrayList(splitted.length); 810 TLongArrayList longs = new TLongArrayList(splitted.length);
811 811
812 for (String value: splitted) { 812 for (String value: splitted) {
813 try { 813 try {
814 longs.add(Long.valueOf(value)); 814 longs.add(Long.valueOf(value));
815 } 815 }
816 catch (NumberFormatException nfe) { 816 catch (NumberFormatException nfe) {
817 logger.warn("Parsing long failed: " + nfe); 817 log.warn("Parsing long failed: " + nfe);
818 } 818 }
819 } 819 }
820 820
821 return longs.toNativeArray(); 821 return longs.toNativeArray();
822 } 822 }
833 */ 833 */
834 public static double[] doubleArrayFromString(String raw) { 834 public static double[] doubleArrayFromString(String raw) {
835 String[] splitted = raw != null ? raw.split(";") : null; 835 String[] splitted = raw != null ? raw.split(";") : null;
836 836
837 if (splitted == null || splitted.length == 0) { 837 if (splitted == null || splitted.length == 0) {
838 logger.warn("No double values found in '" + raw + "'"); 838 log.warn("No double values found in '" + raw + "'");
839 return new double[0]; 839 return new double[0];
840 } 840 }
841 841
842 TDoubleArrayList doubles = new TDoubleArrayList(splitted.length); 842 TDoubleArrayList doubles = new TDoubleArrayList(splitted.length);
843 843
844 for (String value: splitted) { 844 for (String value: splitted) {
845 try { 845 try {
846 doubles.add(Double.valueOf(value)); 846 doubles.add(Double.valueOf(value));
847 } 847 }
848 catch (NumberFormatException nfe) { 848 catch (NumberFormatException nfe) {
849 logger.warn("Parsing double failed: " + nfe); 849 log.warn("Parsing double failed: " + nfe);
850 } 850 }
851 } 851 }
852 852
853 return doubles.toNativeArray(); 853 return doubles.toNativeArray();
854 } 854 }
864 */ 864 */
865 public static List<Gauge> getGauges(D4EArtifact flys) { 865 public static List<Gauge> getGauges(D4EArtifact flys) {
866 866
867 River river = getRiver(flys); 867 River river = getRiver(flys);
868 if (river == null) { 868 if (river == null) {
869 logger.debug("getGauges: no river!"); 869 log.debug("getGauges: no river!");
870 return null; 870 return null;
871 } 871 }
872 872
873 RangeAccess rangeAccess = new RangeAccess(flys); 873 RangeAccess rangeAccess = new RangeAccess(flys);
874 double[] dist = rangeAccess.getKmRange(); 874 double[] dist = rangeAccess.getKmRange();
875 if (dist == null) { 875 if (dist == null) {
876 logger.debug("getGauges: no dist!"); 876 log.debug("getGauges: no dist!");
877 return null; 877 return null;
878 } 878 }
879 logger.debug("getGauges: " + dist[0] + " - " + dist[1]); 879 log.debug("getGauges: " + dist[0] + " - " + dist[1]);
880 880
881 return river.determineGauges(dist[0], dist[1]); 881 return river.determineGauges(dist[0], dist[1]);
882 } 882 }
883 883
884 /** Round a Q in the AT format style **/ 884 /** Round a Q in the AT format style **/
908 dKm = Double.valueOf(km); 908 dKm = Double.valueOf(km);
909 } catch (NumberFormatException nfe) { 909 } catch (NumberFormatException nfe) {
910 return; 910 return;
911 } 911 }
912 912
913 if (logger.isDebugEnabled()) { 913 if (log.isDebugEnabled()) {
914 logger.debug("currentKm = " + dKm); 914 log.debug("currentKm = " + dKm);
915 } 915 }
916 context.putContextValue(CURRENT_KM, dKm); 916 context.putContextValue(CURRENT_KM, dKm);
917 } 917 }
918 } 918 }
919 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 919 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org