Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/model/River.java @ 756:ca13926b8871
River: Make search for gauges independent of from/to order.
flys-backend/trunk@2011 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 26 May 2011 15:00:04 +0000 |
parents | ce9c6f05f464 |
children | c19d4c643526 |
comparison
equal
deleted
inserted
replaced
755:a29fd0916803 | 756:ca13926b8871 |
---|---|
102 * @return the intersecting gauges. | 102 * @return the intersecting gauges. |
103 */ | 103 */ |
104 public List<Gauge> determineGauges(double a, double b) { | 104 public List<Gauge> determineGauges(double a, double b) { |
105 Session session = SessionHolder.HOLDER.get(); | 105 Session session = SessionHolder.HOLDER.get(); |
106 | 106 |
107 if (a > b) { double t = a; a = b; b = t; } | |
108 | |
107 Query query = session.createQuery( | 109 Query query = session.createQuery( |
108 "from Gauge where river=:river " + | 110 "from Gauge where river=:river " + |
109 "and not (range.a > :b or range.b < :a) order by a"); | 111 "and not (range.a > :b or range.b < :a) order by a"); |
110 query.setParameter("river", this); | 112 query.setParameter("river", this); |
111 query.setParameter("a", new BigDecimal(a)); | 113 query.setParameter("a", new BigDecimal(a)); |
125 * @return the first intersecting gauge. | 127 * @return the first intersecting gauge. |
126 */ | 128 */ |
127 public Gauge determineGauge(double a, double b) { | 129 public Gauge determineGauge(double a, double b) { |
128 List<Gauge> gauges = determineGauges(a, b); | 130 List<Gauge> gauges = determineGauges(a, b); |
129 | 131 |
130 return gauges != null && gauges.size() > 0 ? gauges.get(0) : null; | 132 return gauges.isEmpty() ? null : gauges.get(0); |
131 } | 133 } |
132 | 134 |
133 /** | 135 /** |
134 * Returns the min and max distance of this river. The first position in the | 136 * Returns the min and max distance of this river. The first position in the |
135 * resulting array contains the min distance, the second position the max | 137 * resulting array contains the min distance, the second position the max |