[PATCH] Sediment load: converted grain fraction name to an array lookup

Wald Commits scm-commit at wald.intevation.org
Fri Sep 5 18:23:40 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1409934216 -7200
# Node ID 2badb2ca5f895a5cebc74dc5f6ccb0b4d8230ec5
# Parent  de280599dd2fb2f45d82fadbaf7fcb9ee1c09f8a
Sediment load: converted grain fraction name to an array lookup.

diff -r de280599dd2f -r 2badb2ca5f89 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java
--- 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);
     }


More information about the Dive4Elements-commits mailing list