annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HistoricalWQTimerange.java @ 4171:1d8faeedda0c

Sort calculation results of a historical discharge calculation based on their start date. Therefore, there are two new inner classes TimerangeItem and HistoricalTimerangeItem that wrap a W, Q, Timerange (and delta Q). WQTimerange and HistoricalWQTimerange now implement a sort() that return the results (TimerangeItem or HistoricalWQTimerangeItem) sorted by their start date.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 18 Oct 2012 09:28:51 +0200
parents b8df8d1476ba
children 9fd17cb69047
rev   line source
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import gnu.trove.TDoubleArrayList;
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
4171
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
5 import java.util.ArrayList;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
6 import java.util.Collections;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
7 import java.util.List;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
8
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 /**
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 * A subclass of WQTimerange that stores besides W, Q and Timerange values
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 * another double value.
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 *
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 */
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 public class HistoricalWQTimerange extends WQTimerange {
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
4171
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
18 public static class HistoricalTimerangeItem extends TimerangeItem {
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
19 public double diff;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
20
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
21 public HistoricalTimerangeItem (Timerange timerange, double q, double w, double diff) {
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
22 super(timerange, q, w);
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
23 this.diff = diff;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
24 }
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
25
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
26 public double[] get(double[] wq) {
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
27 if (wq.length >= 3) {
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
28 wq[0] = w;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
29 wq[1] = q;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
30 }
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
31 else if (wq.length >= 2) {
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
32 return super.get(wq);
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
33 }
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
34
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
35 return wq;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
36 }
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
37 }
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
38
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 protected TDoubleArrayList diffs;
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 public HistoricalWQTimerange(String name) {
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 super(name);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 diffs = new TDoubleArrayList();
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 public void add(double w, double q, double diff, Timerange t) {
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 ws.add(w);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 qs.add(q);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 ts.add(t);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 diffs.add(diff);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 /**
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 * This method requires a 3dim double array for <i>res</i>!
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 */
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 @Override
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 public double[] get(int idx, double[] res) {
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 res[0] = ws.getQuick(idx);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 res[1] = qs.getQuick(idx);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 res[2] = diffs.getQuick(idx);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 return res;
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 public double[] getDiffs() {
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 return diffs.toNativeArray();
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 }
4171
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
73
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
74 @Override
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
75 public List<TimerangeItem> sort() {
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
76 ArrayList<TimerangeItem> items = new ArrayList<TimerangeItem>(ts.size());
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
77 for (int i = 0, n = size(); i < n; i++) {
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
78 items.add(new HistoricalTimerangeItem(getTimerange(i), getQ(i), getW(i), diffs.get(i)));
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
79 }
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
80
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
81 Collections.sort(items);
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
82 return items;
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
83 }
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org