Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedHeightData.java @ 7391:9513d1af7d58
Renamed artifacts/**/BedHeight(Single) to BedHeight(Single)Data, to resolve
class name conflict with class in backend.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 17 Oct 2013 15:08:59 +0200 |
parents | artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedHeight.java@3c8147ba35a6 |
children | d0ea092a32f5 |
comparison
equal
deleted
inserted
replaced
7390:45e3bb00ce1a | 7391:9513d1af7d58 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts.model.minfo; | |
10 | |
11 import org.apache.log4j.Logger; | |
12 | |
13 import gnu.trove.TDoubleArrayList; | |
14 import org.dive4elements.river.artifacts.model.NamedObjectImpl; | |
15 | |
16 public class BedHeightData | |
17 extends NamedObjectImpl | |
18 { | |
19 private static Logger log = Logger.getLogger(BedHeightData.class); | |
20 | |
21 protected TDoubleArrayList heights; | |
22 protected TDoubleArrayList station; | |
23 | |
24 public BedHeightData() { | |
25 heights = new TDoubleArrayList(); | |
26 station = new TDoubleArrayList(); | |
27 } | |
28 | |
29 public BedHeightData(String name) { | |
30 super(name); | |
31 heights = new TDoubleArrayList(); | |
32 station = new TDoubleArrayList(); | |
33 } | |
34 | |
35 public BedHeightData(int capacity) { | |
36 this(capacity, ""); | |
37 } | |
38 | |
39 public BedHeightData(int capacity, String name) { | |
40 super(name); | |
41 heights = new TDoubleArrayList(capacity); | |
42 station = new TDoubleArrayList(capacity); | |
43 } | |
44 | |
45 public void add(double value, double station) { | |
46 this.heights.add(value); | |
47 this.station.add(station); | |
48 } | |
49 | |
50 public int size() { | |
51 return heights.size(); | |
52 } | |
53 | |
54 public double getHeight(int idx) { | |
55 return heights.getQuick(idx); | |
56 } | |
57 | |
58 public double [] getHeights() { | |
59 return heights.toNativeArray(); | |
60 } | |
61 | |
62 public double [] get(int idx) { | |
63 return get(idx, new double [3]); | |
64 } | |
65 | |
66 public double [] get(int idx, double [] dst) { | |
67 dst[0] = heights.getQuick(idx); | |
68 dst[1] = station.getQuick(idx); | |
69 return dst; | |
70 } | |
71 | |
72 public double minHeights() { | |
73 return heights.min(); | |
74 } | |
75 | |
76 public TDoubleArrayList getStations() { | |
77 return this.station; | |
78 } | |
79 | |
80 public double getHeight(double station) { | |
81 int index = this.station.indexOf(station); | |
82 return index >= 0 ? heights.getQuick(index) : Double.NaN; | |
83 } | |
84 | |
85 | |
86 public static void removeNaNs(TDoubleArrayList [] arrays) { | |
87 | |
88 int dest = 0; | |
89 | |
90 int A = arrays.length; | |
91 int N = arrays[0].size(); | |
92 | |
93 OUTER: for (int i = 0; i < N; ++i) { | |
94 for (int j = 0; j < A; ++j) { | |
95 TDoubleArrayList a = arrays[j]; | |
96 double v = a.getQuick(i); | |
97 if (Double.isNaN(v)) { | |
98 continue OUTER; | |
99 } | |
100 a.setQuick(dest, v); | |
101 } | |
102 ++dest; | |
103 } | |
104 | |
105 if (dest < N) { | |
106 for (int i = 0; i < A; ++i) { | |
107 arrays[i].remove(dest, N-dest); | |
108 } | |
109 } | |
110 } | |
111 | |
112 public void removeNaNs() { | |
113 removeNaNs(new TDoubleArrayList [] { heights }); | |
114 } | |
115 } |