comparison 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
comparison
equal deleted inserted replaced
4170:c0cc002d52ca 4171:1d8faeedda0c
1 package de.intevation.flys.artifacts.model; 1 package de.intevation.flys.artifacts.model;
2 2
3 import gnu.trove.TDoubleArrayList; 3 import gnu.trove.TDoubleArrayList;
4
5 import java.util.ArrayList;
6 import java.util.Collections;
7 import java.util.List;
4 8
5 9
6 /** 10 /**
7 * A subclass of WQTimerange that stores besides W, Q and Timerange values 11 * A subclass of WQTimerange that stores besides W, Q and Timerange values
8 * another double value. 12 * another double value.
9 * 13 *
10 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
11 */ 15 */
12 public class HistoricalWQTimerange extends WQTimerange { 16 public class HistoricalWQTimerange extends WQTimerange {
17
18 public static class HistoricalTimerangeItem extends TimerangeItem {
19 public double diff;
20
21 public HistoricalTimerangeItem (Timerange timerange, double q, double w, double diff) {
22 super(timerange, q, w);
23 this.diff = diff;
24 }
25
26 public double[] get(double[] wq) {
27 if (wq.length >= 3) {
28 wq[0] = w;
29 wq[1] = q;
30 }
31 else if (wq.length >= 2) {
32 return super.get(wq);
33 }
34
35 return wq;
36 }
37 }
13 38
14 protected TDoubleArrayList diffs; 39 protected TDoubleArrayList diffs;
15 40
16 41
17 public HistoricalWQTimerange(String name) { 42 public HistoricalWQTimerange(String name) {
43 68
44 69
45 public double[] getDiffs() { 70 public double[] getDiffs() {
46 return diffs.toNativeArray(); 71 return diffs.toNativeArray();
47 } 72 }
73
74 @Override
75 public List<TimerangeItem> sort() {
76 ArrayList<TimerangeItem> items = new ArrayList<TimerangeItem>(ts.size());
77 for (int i = 0, n = size(); i < n; i++) {
78 items.add(new HistoricalTimerangeItem(getTimerange(i), getQ(i), getW(i), diffs.get(i)));
79 }
80
81 Collections.sort(items);
82 return items;
83 }
48 } 84 }
49 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org