comparison flys-backend/src/main/java/de/intevation/flys/model/River.java @ 769:321b9e480f72

Added a method to river to find the gauge with the max overlap with a given interval. flys-backend/trunk@2235 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 26 Jun 2011 16:13:08 +0000
parents 87ac543c7ab9
children c3ea91aee989
comparison
equal deleted inserted replaced
768:87ac543c7ab9 769:321b9e480f72
111 111
112 Query query = session.createQuery( 112 Query query = session.createQuery(
113 "from Gauge where river=:river " + 113 "from Gauge where river=:river " +
114 "and not (range.a > :b or range.b < :a) order by a"); 114 "and not (range.a > :b or range.b < :a) order by a");
115 query.setParameter("river", this); 115 query.setParameter("river", this);
116 query.setParameter("a", new BigDecimal(a)); 116 query.setParameter("a", new BigDecimal(a, PRECISION));
117 query.setParameter("b", new BigDecimal(b)); 117 query.setParameter("b", new BigDecimal(b, PRECISION));
118 118
119 return query.list(); 119 return query.list();
120 }
121
122 public Gauge maxOverlap(double a, double b) {
123 List<Gauge> gauges = determineGauges(a, b);
124 if (gauges == null) {
125 return null;
126 }
127
128 if (a > b) { double t = a; a = b; b = t; }
129
130 double max = -Double.MAX_VALUE;
131
132 Gauge result = null;
133
134 for (Gauge gauge: gauges) {
135 Range r = gauge.getRange();
136 double c = r.getA().doubleValue();
137 double d = r.getB().doubleValue();
138
139 double start = c >= a ? c : a;
140 double stop = d <= b ? d : b;
141
142 double length = stop - start;
143
144 if (length > max) {
145 max = length;
146 result = gauge;
147 }
148 }
149
150 return result;
120 } 151 }
121 152
122 public Gauge determineGaugeByName(String name) { 153 public Gauge determineGaugeByName(String name) {
123 Session session = SessionHolder.HOLDER.get(); 154 Session session = SessionHolder.HOLDER.get();
124 Query query = session.createQuery( 155 Query query = session.createQuery(

http://dive4elements.wald.intevation.org