Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugesFactory.java @ 1839:c3b44da22a3a
Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
flys-artifacts/trunk@3175 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 07 Nov 2011 12:37:41 +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 :