# HG changeset patch # User Sascha L. Teichmann # Date 1328282718 0 # Node ID 6605dcd6745fceaea988fc785adbf7f10091957e # Parent c5791de0c49569635a2e6d1638407cdab7fdbb02 Added a method to build a map from gauge stations to the datums of the gauges. flys-backend/trunk@3907 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r c5791de0c495 -r 6605dcd6745f flys-backend/ChangeLog --- a/flys-backend/ChangeLog Thu Jan 19 13:36:06 2012 +0000 +++ b/flys-backend/ChangeLog Fri Feb 03 15:25:18 2012 +0000 @@ -1,3 +1,10 @@ +2012-01-18 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/model/River.java(getGaugeDatumsKMs): + New method to build a map of gauge stattion km to + the datums (PNP) of the gauge. Useful look if a km + is a gauge station. + 2012-01-18 Sascha L. Teichmann * src/main/java/de/intevation/flys/model/FastAnnotations.java: diff -r c5791de0c495 -r 6605dcd6745f flys-backend/src/main/java/de/intevation/flys/model/River.java --- a/flys-backend/src/main/java/de/intevation/flys/model/River.java Thu Jan 19 13:36:06 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java Fri Feb 03 15:25:18 2012 +0000 @@ -17,6 +17,9 @@ import javax.persistence.GenerationType; import java.util.List; +import java.util.Comparator; +import java.util.Map; +import java.util.TreeMap; import org.hibernate.Session; import org.hibernate.Query; @@ -31,6 +34,18 @@ { public static final MathContext PRECISION = new MathContext(6); + public static final double EPSILON = 1e-5; + + public static final Comparator KM_CMP = new Comparator() { + @Override + public int compare(Double a, Double b) { + double diff = a - b; + if (diff < -EPSILON) return -1; + if (diff > EPSILON) return +1; + return 0; + } + }; + private Integer id; private String name; @@ -258,5 +273,20 @@ return minmax; } + + public Map getGaugeDatumsKMs() { + List gauges = getGauges(); + Map result = new TreeMap(KM_CMP); + + for (Gauge gauge: gauges) { + BigDecimal km = gauge.getStation(); + BigDecimal datum = gauge.getDatum(); + if (km != null && datum != null) { + result.put(km.doubleValue(), datum.doubleValue()); + } + } + + return result; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :