comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation5.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents 5642a83420f2
children
comparison
equal deleted inserted replaced
2987:98c7a46ec5ae 3318:dbe2f85bf160
1 package de.intevation.flys.artifacts.model;
2
3 import de.intevation.artifacts.CallContext;
4 import de.intevation.artifacts.CallMeta;
5
6 import de.intevation.flys.utils.Formatter;
7
8 import java.text.NumberFormat;
9
10 import java.util.ArrayList;
11 import java.util.Map;
12
13 import org.apache.log4j.Logger;
14
15 public class Calculation5
16 extends Calculation
17 {
18 private static Logger log = Logger.getLogger(Calculation5.class);
19
20 protected double startKm;
21 protected double [] endKms;
22
23 public Calculation5() {
24 }
25
26 public Calculation5(double startKm, double [] endKms) {
27 this.startKm = startKm;
28 this.endKms = endKms;
29 }
30
31 public CalculationResult calculate(
32 WstValueTable wst,
33 Map<Double, Double> kms2gaugeDatums,
34 CallContext context
35 ) {
36 ArrayList<WWQQ> results = new ArrayList<WWQQ>();
37
38 int numProblems = numProblems();
39
40 CallMeta meta = context.getMeta();
41
42 for (double endKm: endKms) {
43
44 double [][] wws = wst.relateWs(startKm, endKm, this);
45 int newNumProblems = numProblems();
46
47 if (wws.length == 4) {
48 WWQQ wwqq = new WWQQ(
49 generateName(meta, startKm, endKm),
50 startKm, kms2gaugeDatums.get(startKm), wws[0], wws[1],
51 endKm, kms2gaugeDatums.get(endKm), wws[2], wws[3]);
52
53 if (newNumProblems > numProblems) {
54 wwqq.removeNaNs();
55 }
56
57 results.add(wwqq);
58 }
59 numProblems = newNumProblems;
60 }
61
62 return new CalculationResult(
63 results.toArray(new WWQQ[results.size()]),
64 this);
65 }
66
67 protected static String generateName(
68 CallMeta meta,
69 double startKm,
70 double endKm
71 ) {
72 NumberFormat nf = Formatter.getCalculationKm(meta);
73 return "W(km " + nf.format(startKm) +
74 ") ~ W(km " + nf.format(endKm) + ")";
75 }
76 }
77 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org