Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/MiddleBedHeightData.java @ 7983:62befca02480 facet-metadata
Moved MiddleBedHeight classes to minfo package. Facet now returns double[][] data.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 01 Jul 2014 13:25:46 +0200 |
parents | |
children | 98e25342df73 |
comparison
equal
deleted
inserted
replaced
7981:45cced06490c | 7983:62befca02480 |
---|---|
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 java.io.Serializable; | |
12 | |
13 import java.util.ArrayList; | |
14 | |
15 import gnu.trove.TDoubleArrayList; | |
16 | |
17 import org.dive4elements.artifacts.CallContext; | |
18 | |
19 import org.dive4elements.river.artifacts.resources.Resources; | |
20 | |
21 import org.apache.log4j.Logger; | |
22 | |
23 | |
24 public class MiddleBedHeightData implements Serializable, | |
25 Comparable<MiddleBedHeightData> { | |
26 | |
27 /** Very private logger. */ | |
28 private static final Logger logger = Logger.getLogger(MiddleBedHeightData.class); | |
29 | |
30 public static final String I18N_SINGLE_NAME = "facet.bedheight_middle.single"; | |
31 public static final String I18N_EPOCH_NAME = "facet.bedheight_middle.epoch"; | |
32 | |
33 private int startYear; | |
34 private int endYear; | |
35 private String evaluatedBy; | |
36 private String description; | |
37 | |
38 private TDoubleArrayList km; | |
39 private TDoubleArrayList middleHeight; | |
40 private TDoubleArrayList uncertainty; | |
41 private TDoubleArrayList soundingWidth; | |
42 private TDoubleArrayList dataGap; | |
43 private TDoubleArrayList width; | |
44 private ArrayList empty; | |
45 | |
46 | |
47 protected MiddleBedHeightData(int start, int end, String eval, String desc) { | |
48 this.startYear = start; | |
49 this.endYear = end; | |
50 this.evaluatedBy = eval; | |
51 this.description = desc; | |
52 | |
53 this.km = new TDoubleArrayList(); | |
54 this.middleHeight = new TDoubleArrayList(); | |
55 this.uncertainty = new TDoubleArrayList(); | |
56 this.soundingWidth = new TDoubleArrayList(); | |
57 this.dataGap = new TDoubleArrayList(); | |
58 this.width = new TDoubleArrayList(); | |
59 this.empty = new ArrayList(); | |
60 } | |
61 | |
62 public void addAll(double station, double height, double uncertainty, | |
63 double soundingWidth, double dataGap, double width, boolean isEmpty) { | |
64 addKM(station); | |
65 addMiddleHeight(height); | |
66 addUncertainty(uncertainty); | |
67 addSoundingWidth(soundingWidth); | |
68 addDataGap(dataGap); | |
69 addWidth(width); | |
70 addIsEmpty(isEmpty); | |
71 } | |
72 | |
73 | |
74 public int getStartYear() { | |
75 return startYear; | |
76 } | |
77 | |
78 public int getEndYear() { | |
79 return endYear; | |
80 } | |
81 | |
82 public String getEvaluatedBy() { | |
83 return evaluatedBy; | |
84 } | |
85 | |
86 public String getDescription() { | |
87 return description; | |
88 } | |
89 | |
90 | |
91 protected void addKM(double km) { | |
92 this.km.add(km); | |
93 } | |
94 | |
95 public double getKM(int idx) { | |
96 return km.get(idx); | |
97 } | |
98 | |
99 public TDoubleArrayList getStations() { | |
100 return this.km; | |
101 } | |
102 | |
103 protected void addMiddleHeight(double middleHeight) { | |
104 this.middleHeight.add(middleHeight); | |
105 } | |
106 | |
107 public double getMiddleHeight(int idx) { | |
108 return middleHeight.get(idx); | |
109 } | |
110 | |
111 protected void addUncertainty(double uncertainty) { | |
112 this.uncertainty.add(uncertainty); | |
113 } | |
114 | |
115 public double getUncertainty(int idx) { | |
116 return uncertainty.get(idx); | |
117 } | |
118 | |
119 protected void addSoundingWidth(double soundingWidth) { | |
120 this.soundingWidth.add(soundingWidth); | |
121 } | |
122 | |
123 public double getSoundingWidth(int idx) { | |
124 return soundingWidth.get(idx); | |
125 } | |
126 | |
127 protected void addDataGap(double gap) { | |
128 this.dataGap.add(gap); | |
129 } | |
130 | |
131 public double getDataGap(int idx) { | |
132 return dataGap.get(idx); | |
133 } | |
134 | |
135 protected void addIsEmpty(boolean empty) { | |
136 this.empty.add(empty); | |
137 } | |
138 | |
139 public boolean isEmpty(int idx) { | |
140 return (Boolean) empty.get(idx); | |
141 } | |
142 | |
143 | |
144 protected void addWidth(double width) { | |
145 this.width.add(width); | |
146 } | |
147 | |
148 public double getWidth(int idx) { | |
149 return width.get(idx); | |
150 } | |
151 | |
152 public int size() { | |
153 return km.size(); | |
154 } | |
155 | |
156 | |
157 /** | |
158 * Get the points, ready to be drawn | |
159 * @return [[km1, km2,...],[height1,height2,...]] | |
160 */ | |
161 public double[][] getMiddleHeightsPoints() { | |
162 double[][] points = new double[2][size()]; | |
163 | |
164 for (int i = 0, n = size(); i < n; i++) { | |
165 if (isEmpty(i)) { | |
166 points[0][i] = getKM(i); | |
167 points[1][i] = Double.NaN; | |
168 } | |
169 else { | |
170 points[0][i] = getKM(i); | |
171 points[1][i] = getMiddleHeight(i); | |
172 } | |
173 } | |
174 | |
175 return points; | |
176 } | |
177 | |
178 | |
179 public String getSoundingName(CallContext context) { | |
180 if (getStartYear() == getEndYear()) { | |
181 return Resources.getMsg( | |
182 context.getMeta(), | |
183 I18N_SINGLE_NAME, | |
184 I18N_SINGLE_NAME, | |
185 new Object[] { getStartYear() } | |
186 ); | |
187 } | |
188 else { | |
189 return Resources.getMsg( | |
190 context.getMeta(), | |
191 I18N_EPOCH_NAME, | |
192 I18N_EPOCH_NAME, | |
193 new Object[] { getStartYear(), getEndYear() } | |
194 ); | |
195 } | |
196 } | |
197 | |
198 @Override | |
199 public int compareTo(MiddleBedHeightData other) { | |
200 | |
201 int descCompared = description.compareTo(other.getDescription()); | |
202 | |
203 if (descCompared != 0) { | |
204 return descCompared; | |
205 } | |
206 | |
207 if (size() == 0 || other.size() == 0) { | |
208 if (size() == 0 && other.size() > 0) { | |
209 return 1; | |
210 } else if (size() > 0 && other.size() == 0) { | |
211 return -1; | |
212 } else if (size() == 0 && other.size() == 0) { | |
213 return 0; | |
214 } | |
215 } | |
216 | |
217 if (getKM(0) < other.getKM(0)) { | |
218 return -1; | |
219 } else if (getKM(0) > other.getKM(0)) { | |
220 return 1; | |
221 } | |
222 return 0; | |
223 } | |
224 } | |
225 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |