[PATCH 04 of 19] issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc

Wald Commits scm-commit at wald.intevation.org
Mon Sep 30 17:30:29 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1380554938 -7200
# Node ID 483cae8915f60611f4cb28808a3dd18f5999c814
# Parent  baf04164fcc616a365d990626f02ab21296208f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.

diff -r baf04164fcc6 -r 483cae8915f6 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java	Mon Sep 30 09:38:09 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java	Mon Sep 30 17:28:58 2013 +0200
@@ -14,10 +14,12 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 
 import org.apache.log4j.Logger;
 
 
+/** Sediment Densities for multiple years. */
 public class SedimentDensity
 {
     private static final Logger logger = Logger
@@ -67,8 +69,8 @@
 
     /**
      * Get the density at year.
-     * measured densities are valid until the next measurement.
-     * if no measurement was found 1.8 is returned.
+     * Measured densities are valid until the next measurement.
+     * If no measurement was found 1.8 is returned.
      */
     public double getDensity(double km, int year) {
         Collections.sort(this.years);
@@ -91,6 +93,45 @@
         return 1.8d;
     }
 
+    /** Get (sorted) map of km to density of all years. */
+    protected double[][] getAllDensities()
+    {
+        TreeMap<Double, Double> map = new TreeMap<Double,Double>();
+        for (int year: years) {
+            for (SedimentDensityValue sdv: densities.get(year)) {
+                map.put(sdv.getKm(), sdv.getDensity());
+            }
+        }
+        double[][] points = new double[2][map.keySet().size()];
+        int i = 0;
+        for (Map.Entry<Double, Double> kmDens: map.entrySet()) {
+            points[0][i] = kmDens.getKey();
+            points[2][i] = kmDens.getValue();
+            i++;
+        }
+
+        return points;
+    }
+
+    /** Get points  km,density (sorted by km), for a given year. */
+    public double[][] getDensities(int year)
+    {
+        TreeMap<Double, Double> map = new TreeMap<Double,Double>();
+        for (SedimentDensityValue sdv: densities.get(year)) {
+            map.put(sdv.getKm(), sdv.getDensity());
+        }
+        double[][] points = new double[2][map.keySet().size()];
+        int i = 0;
+        for (Map.Entry<Double, Double> kmDens: map.entrySet()) {
+            points[0][i] = kmDens.getKey();
+            points[1][i] = kmDens.getValue();
+            i++;
+        }
+
+        return points;
+    }
+
+    /** Get value at km, interpolated. */
     private double getDensityAtKm(
         List<SedimentDensityValue> values,
         double km
@@ -111,6 +152,7 @@
         return spline(prev, next, km);
     }
 
+    /** Linearly interpolate between density values. */
     private static double spline(
         SedimentDensityValue prev,
         SedimentDensityValue next,


More information about the Dive4elements-commits mailing list