[PATCH] Sediment load: Added join to fetch measurement station via ranges which know the river. Added a visitor for values, too

Wald Commits scm-commit at wald.intevation.org
Thu Jul 17 11:20:16 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1405588799 -7200
# Node ID c835f3cf098e032bd440982ea1a26eff209030cd
# Parent  8c14588d1f78afdf252d289c9a2cf7e9c327794f
Sediment load: Added join to fetch measurement station via ranges which know the river. Added a visitor for values, too.

diff -r 8c14588d1f78 -r c835f3cf098e 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	Thu Jul 17 10:56:38 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Thu Jul 17 11:19:59 2014 +0200
@@ -55,6 +55,10 @@
             boolean accept(Value value);
         }
 
+        public interface Visitor {
+            void visit(Value value);
+        }
+
         private double value;
 
         private Load load;
@@ -240,17 +244,29 @@
             return values != null && !values.isEmpty();
         }
 
+        public void filterGrainFraction(
+            int           grainFraction,
+            Value.Filter  filter,
+            Value.Visitor visitor
+        ) {
+            List<Value> values = grainFractions.get(grainFraction);
+            if (values != null && !values.isEmpty()) {
+                for (Value value: values) {
+                    if (filter.accept(value)) {
+                        visitor.visit(value);
+                    }
+                }
+            }
+        }
+
         public List<Value> filterGrainFraction(int grainFraction, Value.Filter filter) {
-            List<Value> values = grainFractions.get(grainFraction);
-            if (values == null || values.isEmpty()) {
-                return Collections.<Value>emptyList();
-            }
-            List<Value> result = new ArrayList<Value>(values.size());
-            for (Value value: values) {
-                if (filter.accept(value)) {
+            final List<Value> result = new ArrayList<Value>();
+            filterGrainFraction(grainFraction, filter, new Value.Visitor() {
+                @Override
+                public void visit(Value value) {
                     result.add(value);
                 }
-            }
+            });
             return result;
         }
 
diff -r 8c14588d1f78 -r c835f3cf098e artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java	Thu Jul 17 10:56:38 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java	Thu Jul 17 11:19:59 2014 +0200
@@ -45,7 +45,8 @@
           "JOIN time_intervals ti ON sl.time_interval_id = ti.id " +
           "JOIN grain_fraction gf ON sl.grain_fraction_id = gf.id " +
           "JOIN measurement_station ms ON slv.measurement_station_id = ms.id " +
-          "JOIN rivers r ON ms.river_id = r.id " +
+          "JOIN ranges rng ON ms.range_id = rng.id " +
+          "JOIN rivers r ON rng.river_id = r.id " +
         "WHERE r.name = :river " +
         "ORDER BY sl.id";
 


More information about the Dive4Elements-commits mailing list