comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedHeight.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedHeight.java@bce2dd4310a6
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.model.minfo;
2
3 import org.apache.log4j.Logger;
4
5 import gnu.trove.TDoubleArrayList;
6 import org.dive4elements.river.artifacts.model.NamedObjectImpl;
7
8 public class BedHeight
9 extends NamedObjectImpl
10 {
11 private static Logger log = Logger.getLogger(BedHeight.class);
12
13 protected TDoubleArrayList heights;
14 protected TDoubleArrayList station;
15
16 public BedHeight() {
17 heights = new TDoubleArrayList();
18 station = new TDoubleArrayList();
19 }
20
21 public BedHeight(String name) {
22 super(name);
23 heights = new TDoubleArrayList();
24 station = new TDoubleArrayList();
25 }
26
27 public BedHeight(int capacity) {
28 this(capacity, "");
29 }
30
31 public BedHeight(int capacity, String name) {
32 super(name);
33 heights = new TDoubleArrayList(capacity);
34 station = new TDoubleArrayList(capacity);
35 }
36
37 public void add(double value, double station) {
38 this.heights.add(value);
39 this.station.add(station);
40 }
41
42 public int size() {
43 return heights.size();
44 }
45
46 public double getHeight(int idx) {
47 return heights.getQuick(idx);
48 }
49
50 public double [] getHeights() {
51 return heights.toNativeArray();
52 }
53
54 public double [] get(int idx) {
55 return get(idx, new double [3]);
56 }
57
58 public double [] get(int idx, double [] dst) {
59 dst[0] = heights.getQuick(idx);
60 dst[1] = station.getQuick(idx);
61 return dst;
62 }
63
64 public double minHeights() {
65 return heights.min();
66 }
67
68 public TDoubleArrayList getStations() {
69 return this.station;
70 }
71
72 public double getHeight(double station) {
73 if (this.station.indexOf(station) >= 0) {
74 return this.heights.get(this.station.indexOf(station));
75 }
76 return Double.NaN;
77 }
78
79
80 public static void removeNaNs(TDoubleArrayList [] arrays) {
81
82 int dest = 0;
83
84 int A = arrays.length;
85 int N = arrays[0].size();
86
87 OUTER: for (int i = 0; i < N; ++i) {
88 for (int j = 0; j < A; ++j) {
89 TDoubleArrayList a = arrays[j];
90 double v = a.getQuick(i);
91 if (Double.isNaN(v)) {
92 continue OUTER;
93 }
94 a.setQuick(dest, v);
95 }
96 ++dest;
97 }
98
99 if (dest < N) {
100 for (int i = 0; i < A; ++i) {
101 arrays[i].remove(dest, N-dest);
102 }
103 }
104 }
105
106 public void removeNaNs() {
107 removeNaNs(new TDoubleArrayList [] { heights });
108 }
109 }

http://dive4elements.wald.intevation.org