Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugesFactory.java @ 3082:9e03960b3ab8
FixA: Lowered log level in parameter interpolation.
flys-artifacts/trunk@4678 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 18 Jun 2012 08:10:44 +0000 |
parents | 7e19449d7826 |
children |
line wrap: on
line source
package de.intevation.flys.artifacts.model; import java.util.List; import java.util.ArrayList; import de.intevation.flys.backend.SessionHolder; import de.intevation.flys.model.River; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.Range; import org.hibernate.Session; import org.hibernate.Query; public class GaugesFactory { public static List<Gauge> getGauges(River river) { return getGauges(river.getName()); } public static Gauge getGauge(String gaugeName) { Session session = SessionHolder.HOLDER.get(); Query query = session.createQuery( "from Gauge where name=:name"); query.setParameter("name", gaugeName); List<Gauge> res = query.list(); return res.isEmpty() ? null : res.get(0); } public static List<Gauge> getGauges(String river) { Session session = SessionHolder.HOLDER.get(); Query query = session.createQuery( "from Gauge where river.name=:name"); query.setParameter("name", river); return query.list(); } public static List<Gauge> filterRanges( List<Gauge> gauges, List<double []> ranges ) { // XXX: Inefficent! ArrayList<Range> rs = new ArrayList<Range>(); for (double [] range: ranges) { double a = range[0]; double b = range[1]; rs.add(new Range(Math.min(a, b), Math.max(a, b), null)); } return filter(gauges, rs); } public static List<Gauge> filter(List<Gauge> gauges, List<Range> ranges) { // TODO: Make it an HQL filter! ArrayList<Gauge> out = new ArrayList<Gauge>(); for (Gauge gauge: gauges) { Range range = gauge.getRange(); for (Range cmp: ranges) { if (range.intersects(cmp)) { out.add(gauge); break; } } } return out; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :