changeset 7180:e0b6b6cf4708

issue1435: Minor refactoring that will come handy to load SedimentLoads for "standalone" sedimentyield artifact.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 26 Sep 2013 21:30:19 +0200
parents 6d4578fe4696
children 805021c04861
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
diffstat 1 files changed, 35 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Thu Sep 26 19:55:49 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Thu Sep 26 21:30:19 2013 +0200
@@ -346,6 +346,7 @@
      * Get sediment loads from db.
      * @param river the river
      * @param type the sediment load type (year, epoch or off_epoch)
+     *
      * @return according sediment loads.
      */
     public static SedimentLoad getSedimentLoadWithDataUncached(
@@ -551,32 +552,48 @@
                 continue;
             }
             double v = -1;
+
             if (row[2] != null) {
                 v = ((Double)row[2]).doubleValue();
             }
-            if (fraction.equals("coarse")) {
-                load.setCoarse(km, v, range);
-            }
-            else if (fraction.equals("sand")) {
-                load.setSand(km, v, range);
-            }
-            else if (fraction.equals("fine_middle")) {
-                load.setFineMiddle(km, v, range);
-            }
-            else if (fraction.equals("suspended_sediment")) {
-                load.setSuspSediment(km, v, range);
-            }
-            else if (fraction.equals("susp_sand")) {
-                load.setSuspSand(km, v, range);
-            }
-            else if (fraction.equals("susp_sand_bed")) {
-                load.setSuspSandBed(km, v, range);
-            }
+
+            setLoadFraction(load, km, v, range, fraction);
+        }
+
+        if (results.isEmpty()) {
+            log.warn("No " + fraction + " values found.");
         }
 
         return load;
     }
 
+
+    /** Set a fraction value of load to given km, value and range. */
+    private static void setLoadFraction(
+        SedimentLoad load, double km, double v, Range range, String fraction) {
+        if (fraction.equals("coarse")) {
+            load.setCoarse(km, v, range);
+        }
+        else if (fraction.equals("sand")) {
+            load.setSand(km, v, range);
+        }
+        else if (fraction.equals("fine_middle")) {
+            load.setFineMiddle(km, v, range);
+        }
+        else if (fraction.equals("suspended_sediment")) {
+            load.setSuspSediment(km, v, range);
+        }
+        else if (fraction.equals("susp_sand")) {
+            load.setSuspSand(km, v, range);
+        }
+        else if (fraction.equals("susp_sand_bed")) {
+            load.setSuspSandBed(km, v, range);
+        }
+        else {
+            log.error("Unknown fraction type " + fraction);
+        }
+    }
+
     public static SedimentLoad getLoadUnknown(
         String river,
         String description

http://dive4elements.wald.intevation.org