changeset 8208:2badb2ca5f89

Sediment load: converted grain fraction name to an array lookup.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 18:23:36 +0200 (2014-09-05)
parents de280599dd2f
children 5114b643a6d6
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java
diffstat 1 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Fri Sep 05 16:54:45 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Fri Sep 05 18:23:36 2014 +0200
@@ -37,6 +37,18 @@
     public static final int GF_BED_LOAD_SUSP_SAND =  8;
     public static final int GF_MAX                =  8;
 
+    public static final String [] GF_NAMES = {
+        "coarse",
+        "fine_middle",
+        "sand",
+        "susp_sand",
+        "susp_sand_bed",
+        "suspended_sediment",
+        "total",
+        "bed_load",
+        "bed_load_susp_sand"
+    };
+
     public static final int [] MEASUREMENT_STATION_GF = {
         /* GF_COARSE             */ Station.BED_LOAD,
         /* GF_FINE_MIDDLE        */ Station.BED_LOAD,
@@ -49,25 +61,22 @@
         /* GF_BED_LOAD_SUSP_SAND */ Station.BED_LOAD
     };
 
-    public static final int measurementStationType(int grainFraction) {
-        return grainFraction < 0 || grainFraction >= MEASUREMENT_STATION_GF.length
-            ? Station.UNKNOWN
-            : MEASUREMENT_STATION_GF[grainFraction];
+    public static final int grainFractionIndex(String name) {
+        for (int i = 0; i < GF_NAMES.length; ++i) {
+            if (GF_NAMES[i].equals(name)) {
+                return i;
+            }
+        }
+        return GF_UNKNOWN;
     }
 
-    public static final int grainFractionIndex(String name) {
-        if ("coarse".equals(name))             return GF_COARSE;
-        if ("fine_middle".equals(name))        return GF_FINE_MIDDLE;
-        if ("sand".equals(name))               return GF_SAND;
-        if ("susp_sand".equals(name))          return GF_SUSP_SAND;
-        if ("susp_sand_bed".equals(name))      return GF_SUSP_SAND_BED;
-        if ("suspended_sediment".equals(name)) return GF_SUSP_SEDIMENT;
-        if ("total".equals(name))              return GF_TOTAL;
-        if ("bed_load".equals(name))           return GF_BED_LOAD;
-        if ("bed_load_susp_sand".equals(name)) return GF_BED_LOAD_SUSP_SAND;
-        return GF_UNKNOWN;
+    public static final String grainFractionName(int index) {
+        return index >= 0 && index < GF_NAMES.length
+            ? GF_NAMES[index]
+            : "unknown";
     }
 
+
     public interface Visitor {
         void visit(Station station);
     }

http://dive4elements.wald.intevation.org