changeset 8047:c835f3cf098e

Sediment load: Added join to fetch measurement station via ranges which know the river. Added a visitor for values, too.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 17 Jul 2014 11:19:59 +0200
parents 8c14588d1f78
children cde6d2a9ec32
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java
diffstat 2 files changed, 25 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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 List<Value> filterGrainFraction(int grainFraction, Value.Filter filter) {
+        public void filterGrainFraction(
+            int           grainFraction,
+            Value.Filter  filter,
+            Value.Visitor visitor
+        ) {
             List<Value> values = grainFractions.get(grainFraction);
-            if (values == null || values.isEmpty()) {
-                return Collections.<Value>emptyList();
+            if (values != null && !values.isEmpty()) {
+                for (Value value: values) {
+                    if (filter.accept(value)) {
+                        visitor.visit(value);
+                    }
+                }
             }
-            List<Value> result = new ArrayList<Value>(values.size());
-            for (Value value: values) {
-                if (filter.accept(value)) {
+        }
+
+        public List<Value> filterGrainFraction(int grainFraction, Value.Filter filter) {
+            final List<Value> result = new ArrayList<Value>();
+            filterGrainFraction(grainFraction, filter, new Value.Visitor() {
+                @Override
+                public void visit(Value value) {
                     result.add(value);
                 }
-            }
+            });
             return result;
         }
 
--- 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";
 

http://dive4elements.wald.intevation.org