Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/model/River.java @ 2383:6605dcd6745f
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
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 03 Feb 2012 15:25:18 +0000 |
parents | 056b3a5aa181 |
children | 385170ff7b34 |
comparison
equal
deleted
inserted
replaced
2382:c5791de0c495 | 2383:6605dcd6745f |
---|---|
15 import javax.persistence.OneToOne; | 15 import javax.persistence.OneToOne; |
16 import javax.persistence.JoinColumn; | 16 import javax.persistence.JoinColumn; |
17 import javax.persistence.GenerationType; | 17 import javax.persistence.GenerationType; |
18 | 18 |
19 import java.util.List; | 19 import java.util.List; |
20 import java.util.Comparator; | |
21 import java.util.Map; | |
22 import java.util.TreeMap; | |
20 | 23 |
21 import org.hibernate.Session; | 24 import org.hibernate.Session; |
22 import org.hibernate.Query; | 25 import org.hibernate.Query; |
23 | 26 |
24 import de.intevation.flys.backend.SessionHolder; | 27 import de.intevation.flys.backend.SessionHolder; |
28 @Table(name = "rivers") | 31 @Table(name = "rivers") |
29 public class River | 32 public class River |
30 implements Serializable | 33 implements Serializable |
31 { | 34 { |
32 public static final MathContext PRECISION = new MathContext(6); | 35 public static final MathContext PRECISION = new MathContext(6); |
36 | |
37 public static final double EPSILON = 1e-5; | |
38 | |
39 public static final Comparator KM_CMP = new Comparator<Double>() { | |
40 @Override | |
41 public int compare(Double a, Double b) { | |
42 double diff = a - b; | |
43 if (diff < -EPSILON) return -1; | |
44 if (diff > EPSILON) return +1; | |
45 return 0; | |
46 } | |
47 }; | |
33 | 48 |
34 private Integer id; | 49 private Integer id; |
35 | 50 |
36 private String name; | 51 private String name; |
37 | 52 |
256 } | 271 } |
257 } | 272 } |
258 | 273 |
259 return minmax; | 274 return minmax; |
260 } | 275 } |
276 | |
277 public Map<Double, Double> getGaugeDatumsKMs() { | |
278 List<Gauge> gauges = getGauges(); | |
279 Map result = new TreeMap<Double, Double>(KM_CMP); | |
280 | |
281 for (Gauge gauge: gauges) { | |
282 BigDecimal km = gauge.getStation(); | |
283 BigDecimal datum = gauge.getDatum(); | |
284 if (km != null && datum != null) { | |
285 result.put(km.doubleValue(), datum.doubleValue()); | |
286 } | |
287 } | |
288 | |
289 return result; | |
290 } | |
261 } | 291 } |
262 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 292 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |