Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/GaugeDischargeZoneFinder.java @ 9347:08f46ccd37ba
salix.regional refactoring
author | gernotbelger |
---|---|
date | Tue, 31 Jul 2018 16:04:01 +0200 |
parents | a4121ec450d6 |
children |
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.sinfo.collision; import java.util.Map.Entry; import java.util.NavigableMap; import java.util.TreeMap; import org.dive4elements.river.artifacts.model.Calculation; import org.dive4elements.river.model.Gauge; import org.dive4elements.river.model.MainValue; import org.dive4elements.river.model.MainValueType.MainValueTypeKey; /** * Loading and search the discharge zones of a gauge * * @author Matthias Schäfer * */ public final class GaugeDischargeZoneFinder { /***** FIELDS *****/ // private static Logger log = Logger.getLogger(GaugeDischargeZoneFinder.class); private final Gauge gauge; private final Calculation problems; private final NavigableMap<Double, MainValue> qZones; private final String approxPrefix = "\u2248";// "ca."; /***** CONSTRUCTORS *****/ private GaugeDischargeZoneFinder(final Gauge gauge, final Calculation problems) { this.gauge = gauge; this.problems = problems; this.qZones = new TreeMap<>(); for (final MainValue mainValue : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.Q)) this.qZones.put(Double.valueOf(mainValue.getValue().doubleValue()), mainValue); } /***** METHODS *****/ /** * Loads the the main discharge table of a gauge (GAUGE.at) * * @return The discharge table values finder of the gauge, or null */ public static GaugeDischargeZoneFinder loadValues(final Gauge gauge, final Calculation problems) { return new GaugeDischargeZoneFinder(gauge, problems); } /** * If this provider may return valid data at all. */ public boolean isValid() { return (this.qZones != null); } /** * Discharge zone for a Q. */ public String getDischargeZone(final double q) { if (Double.isNaN(q)) return ""; // Exact match if (this.qZones.containsKey(Double.valueOf(q))) return this.qZones.get(Double.valueOf(q)).getMainValue().getName(); // Clearly below or just (max. 10%) below lowest named discharge final Entry<Double, MainValue> lowerZone = this.qZones.floorEntry(Double.valueOf(q)); if (lowerZone == null) { if (q >= this.qZones.firstKey().doubleValue() * 0.9) return this.approxPrefix + this.qZones.firstEntry().getValue().getMainValue().getName(); else return "<" + this.qZones.firstEntry().getValue().getMainValue().getName(); } // Clearly above or just (max. 10%) above highest named discharge final Entry<Double, MainValue> higherZone = this.qZones.ceilingEntry(Double.valueOf(q)); if (higherZone == null) { if (q <= this.qZones.lastKey().doubleValue() * 1.1) return this.approxPrefix + this.qZones.lastEntry().getValue().getMainValue().getName(); else return ">" + this.qZones.lastEntry().getValue().getMainValue().getName(); } // Near (10%) one of the borders of a zone interval, or clearly within a zone if (q <= lowerZone.getKey().doubleValue() * 1.1) return this.approxPrefix + lowerZone.getValue().getMainValue().getName(); else if (q >= higherZone.getKey().doubleValue() * 0.9) return this.approxPrefix + higherZone.getValue().getMainValue().getName(); else return lowerZone.getValue().getMainValue().getName() + "-" + higherZone.getValue().getMainValue().getName(); } }