Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/model/River.java @ 465:c2c3ad4fda58
Added a method to River that returns the min and max distance of the river.
flys-backend/trunk@1698 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 14 Apr 2011 13:43:53 +0000 |
parents | 003ac16812dd |
children | 1e196c75563b |
comparison
equal
deleted
inserted
replaced
464:d37ccb04ab5d | 465:c2c3ad4fda58 |
---|---|
1 package de.intevation.flys.model; | 1 package de.intevation.flys.model; |
2 | 2 |
3 import java.io.Serializable; | 3 import java.io.Serializable; |
4 | |
5 import java.math.BigDecimal; | |
4 | 6 |
5 import javax.persistence.Entity; | 7 import javax.persistence.Entity; |
6 import javax.persistence.Id; | 8 import javax.persistence.Id; |
7 import javax.persistence.Table; | 9 import javax.persistence.Table; |
8 import javax.persistence.GeneratedValue; | 10 import javax.persistence.GeneratedValue; |
69 } | 71 } |
70 | 72 |
71 public String toString() { | 73 public String toString() { |
72 return name != null ? name : ""; | 74 return name != null ? name : ""; |
73 } | 75 } |
76 | |
77 /** | |
78 * Returns the min and max distance of this river. The first position in the | |
79 * resulting array contains the min distance, the second position the max | |
80 * distance. | |
81 * | |
82 * @return the min and max distance of this river. | |
83 */ | |
84 public double[] determineMinMaxDistance() { | |
85 if (gauges == null) { | |
86 return null; | |
87 } | |
88 | |
89 double minmax[] = new double[] { Double.MAX_VALUE, Double.MIN_VALUE }; | |
90 | |
91 for (Gauge g: gauges) { | |
92 Range r = g.getRange(); | |
93 | |
94 double a = r.getA().doubleValue(); | |
95 minmax[0] = minmax[0] < a ? minmax[0] : a; | |
96 | |
97 BigDecimal bigB = r.getB(); | |
98 if (bigB != null) { | |
99 double b = bigB.doubleValue(); | |
100 minmax[1] = minmax[1] > b ? minmax[1] : b; | |
101 } | |
102 } | |
103 | |
104 return minmax; | |
105 } | |
74 } | 106 } |
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |