Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation5.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 5642a83420f2 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation5.java Fri Sep 28 12:14:39 2012 +0200 @@ -0,0 +1,77 @@ +package de.intevation.flys.artifacts.model; + +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; + +import de.intevation.flys.utils.Formatter; + +import java.text.NumberFormat; + +import java.util.ArrayList; +import java.util.Map; + +import org.apache.log4j.Logger; + +public class Calculation5 +extends Calculation +{ + private static Logger log = Logger.getLogger(Calculation5.class); + + protected double startKm; + protected double [] endKms; + + public Calculation5() { + } + + public Calculation5(double startKm, double [] endKms) { + this.startKm = startKm; + this.endKms = endKms; + } + + public CalculationResult calculate( + WstValueTable wst, + Map<Double, Double> kms2gaugeDatums, + CallContext context + ) { + ArrayList<WWQQ> results = new ArrayList<WWQQ>(); + + int numProblems = numProblems(); + + CallMeta meta = context.getMeta(); + + for (double endKm: endKms) { + + double [][] wws = wst.relateWs(startKm, endKm, this); + int newNumProblems = numProblems(); + + if (wws.length == 4) { + WWQQ wwqq = new WWQQ( + generateName(meta, startKm, endKm), + startKm, kms2gaugeDatums.get(startKm), wws[0], wws[1], + endKm, kms2gaugeDatums.get(endKm), wws[2], wws[3]); + + if (newNumProblems > numProblems) { + wwqq.removeNaNs(); + } + + results.add(wwqq); + } + numProblems = newNumProblems; + } + + return new CalculationResult( + results.toArray(new WWQQ[results.size()]), + this); + } + + protected static String generateName( + CallMeta meta, + double startKm, + double endKm + ) { + NumberFormat nf = Formatter.getCalculationKm(meta); + return "W(km " + nf.format(startKm) + + ") ~ W(km " + nf.format(endKm) + ")"; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :