Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java @ 3771:04309ca24614
Locales fix
flys-artifacts/trunk@5476 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Sat, 15 Sep 2012 13:42:44 +0000 |
parents | 0336132ec9db |
children | db4e7ff0b987 |
comparison
equal
deleted
inserted
replaced
3770:6a08f4dc790b | 3771:04309ca24614 |
---|---|
1 package de.intevation.flys.utils; | 1 package de.intevation.flys.utils; |
2 | |
3 import de.intevation.artifacts.CallContext; | |
4 import de.intevation.artifacts.CallMeta; | |
5 | |
6 import de.intevation.flys.artifacts.resources.Resources; | |
7 | 2 |
8 import java.text.DateFormat; | 3 import java.text.DateFormat; |
9 import java.text.NumberFormat; | 4 import java.text.NumberFormat; |
10 import java.text.SimpleDateFormat; | 5 import java.text.SimpleDateFormat; |
11 | |
12 import java.util.Locale; | 6 import java.util.Locale; |
7 | |
8 import de.intevation.artifacts.CallContext; | |
9 import de.intevation.artifacts.CallMeta; | |
10 import de.intevation.flys.artifacts.resources.Resources; | |
13 | 11 |
14 | 12 |
15 public final class Formatter { | 13 public final class Formatter { |
16 | 14 |
17 // KMS IN ERROR REPORTS. | 15 // KMS IN ERROR REPORTS. |
79 public static final int FIX_DELTA_W_DELTA_W_MAX_DIGITS = 3; | 77 public static final int FIX_DELTA_W_DELTA_W_MAX_DIGITS = 3; |
80 public static final int FIX_DELTA_W_DELTA_Q_MIN_DIGITS = 0; | 78 public static final int FIX_DELTA_W_DELTA_Q_MIN_DIGITS = 0; |
81 public static final int FIX_DELTA_W_DELTA_Q_MAX_DIGITS = 2; | 79 public static final int FIX_DELTA_W_DELTA_Q_MAX_DIGITS = 2; |
82 | 80 |
83 /** | 81 /** |
84 * Creates a localised NumberFormatter with given range of decimal digits. | 82 * Creates a localized NumberFormatter with given range of decimal digits. |
85 * @param m CallMeta to find the locale. | 83 * @param m CallMeta to find the locale. |
86 * @param min minimum number of decimal ("fraction") digits. | 84 * @param min minimum number of decimal ("fraction") digits. |
87 * @param max maximum number of decimal ("fraction") digits. | 85 * @param max maximum number of decimal ("fraction") digits. |
88 * @return A NumberFormat. Use #format(NUMBER) to get String representation | 86 * @return A NumberFormat. Use #format(NUMBER) to get String representation |
89 * of NUMBER. | 87 * of NUMBER. |
139 * | 137 * |
140 * @return the number formatter for kilometer values. | 138 * @return the number formatter for kilometer values. |
141 */ | 139 */ |
142 public static NumberFormat getWaterlevelKM(CallContext context) { | 140 public static NumberFormat getWaterlevelKM(CallContext context) { |
143 return getFormatter( | 141 return getFormatter( |
144 context, | 142 context, |
145 WATERLEVEL_KM_MIN_DIGITS, | 143 WATERLEVEL_KM_MIN_DIGITS, |
146 WATERLEVEL_KM_MAX_DIGITS); | 144 WATERLEVEL_KM_MAX_DIGITS); |
147 } | 145 } |
148 | 146 |
149 public static NumberFormat getWaterlevelW(CallMeta meta) { | 147 public static NumberFormat getWaterlevelW(CallMeta meta) { |
150 return getFormatter( | 148 return getFormatter( |
151 meta, | 149 meta, |
152 WATERLEVEL_W_MIN_DIGITS, | 150 WATERLEVEL_W_MIN_DIGITS, |
153 WATERLEVEL_W_MAX_DIGITS); | 151 WATERLEVEL_W_MAX_DIGITS); |
154 } | 152 } |
155 | 153 |
156 /** | 154 /** |
157 * Returns the number formatter for W values in waterlevel exports. | 155 * Returns the number formatter for W values in waterlevel exports. |
158 * | 156 * |
159 * @return the number formatter for W values. | 157 * @return the number formatter for W values. |
160 */ | 158 */ |
161 public static NumberFormat getWaterlevelW(CallContext context) { | 159 public static NumberFormat getWaterlevelW(CallContext context) { |
162 return getFormatter( | 160 return getFormatter( |
163 context, | 161 context, |
164 WATERLEVEL_W_MIN_DIGITS, | 162 WATERLEVEL_W_MIN_DIGITS, |
165 WATERLEVEL_W_MAX_DIGITS); | 163 WATERLEVEL_W_MAX_DIGITS); |
166 } | 164 } |
167 | 165 |
168 | 166 |
169 /** | 167 /** |
170 * Returns the number formatter for Q values in waterlevel exports. | 168 * Returns the number formatter for Q values in waterlevel exports. |
171 * | 169 * |
172 * @return the number formatter for Q values. | 170 * @return the number formatter for Q values. |
173 */ | 171 */ |
174 public static NumberFormat getWaterlevelQ(CallContext context) { | 172 public static NumberFormat getWaterlevelQ(CallContext context) { |
175 return getFormatter( | 173 return getFormatter( |
176 context, | 174 context, |
177 WATERLEVEL_Q_MIN_DIGITS, | 175 WATERLEVEL_Q_MIN_DIGITS, |
178 WATERLEVEL_Q_MAX_DIGITS); | 176 WATERLEVEL_Q_MAX_DIGITS); |
179 } | 177 } |
180 | 178 |
181 public static NumberFormat getWaterlevelQ(CallMeta meta) { | 179 public static NumberFormat getWaterlevelQ(CallMeta meta) { |
182 return getFormatter( | 180 return getFormatter( |
183 meta, | 181 meta, |
184 WATERLEVEL_Q_MIN_DIGITS, | 182 WATERLEVEL_Q_MIN_DIGITS, |
185 WATERLEVEL_Q_MAX_DIGITS); | 183 WATERLEVEL_Q_MAX_DIGITS); |
186 } | 184 } |
187 | 185 |
188 /** | 186 /** |
189 * Returns the number formatter for W values in exports of computed | 187 * Returns the number formatter for W values in exports of computed |
190 * discharge curves. | 188 * discharge curves. |
191 * | 189 * |
192 * @return the number formatter for W values. | 190 * @return the number formatter for W values. |
193 */ | 191 */ |
194 public static NumberFormat getComputedDischargeW(CallContext context) { | 192 public static NumberFormat getComputedDischargeW(CallContext context) { |
195 return getFormatter( | 193 return getFormatter( |
196 context, | 194 context, |
197 COMPUTED_DISCHARGE_W_MIN_DIGITS, | 195 COMPUTED_DISCHARGE_W_MIN_DIGITS, |
198 COMPUTED_DISCHARGE_W_MAX_DIGITS); | 196 COMPUTED_DISCHARGE_W_MAX_DIGITS); |
199 } | 197 } |
200 | 198 |
201 | 199 |
202 /** | 200 /** |
203 * Returns the number formatter for Q values in exports of computed | 201 * Returns the number formatter for Q values in exports of computed |
205 * | 203 * |
206 * @return the number formatter for Q values. | 204 * @return the number formatter for Q values. |
207 */ | 205 */ |
208 public static NumberFormat getComputedDischargeQ(CallContext context) { | 206 public static NumberFormat getComputedDischargeQ(CallContext context) { |
209 return getFormatter( | 207 return getFormatter( |
210 context, | 208 context, |
211 COMPUTED_DISCHARGE_Q_MIN_DIGITS, | 209 COMPUTED_DISCHARGE_Q_MIN_DIGITS, |
212 COMPUTED_DISCHARGE_Q_MAX_DIGITS); | 210 COMPUTED_DISCHARGE_Q_MAX_DIGITS); |
213 } | 211 } |
214 | 212 |
215 | 213 |
216 /** | 214 /** |
217 * Returns the number formatter for W values in exports of historical | 215 * Returns the number formatter for W values in exports of historical |
219 * | 217 * |
220 * @return the number formatter for W values. | 218 * @return the number formatter for W values. |
221 */ | 219 */ |
222 public static NumberFormat getHistoricalDischargeW(CallContext context) { | 220 public static NumberFormat getHistoricalDischargeW(CallContext context) { |
223 return getFormatter( | 221 return getFormatter( |
224 context, | 222 context, |
225 HISTORICAL_DISCHARGE_W_MIN_DIGITS, | 223 HISTORICAL_DISCHARGE_W_MIN_DIGITS, |
226 HISTORICAL_DISCHARGE_W_MAX_DIGITS); | 224 HISTORICAL_DISCHARGE_W_MAX_DIGITS); |
227 } | 225 } |
228 | 226 |
229 | 227 |
230 /** | 228 /** |
231 * Returns the number formatter for Q values in exports of historical | 229 * Returns the number formatter for Q values in exports of historical |
233 * | 231 * |
234 * @return the number formatter for Q values. | 232 * @return the number formatter for Q values. |
235 */ | 233 */ |
236 public static NumberFormat getHistoricalDischargeQ(CallContext context) { | 234 public static NumberFormat getHistoricalDischargeQ(CallContext context) { |
237 return getFormatter( | 235 return getFormatter( |
238 context, | 236 context, |
239 HISTORICAL_DISCHARGE_Q_MIN_DIGITS, | 237 HISTORICAL_DISCHARGE_Q_MIN_DIGITS, |
240 HISTORICAL_DISCHARGE_Q_MAX_DIGITS); | 238 HISTORICAL_DISCHARGE_Q_MAX_DIGITS); |
241 } | 239 } |
242 | 240 |
243 | 241 |
244 /** | 242 /** |
245 * Returns the number formatter for W values in duration curve exports. | 243 * Returns the number formatter for W values in duration curve exports. |
246 * | 244 * |
247 * @return the number formatter for W values. | 245 * @return the number formatter for W values. |
248 */ | 246 */ |
249 public static NumberFormat getDurationW(CallContext context) { | 247 public static NumberFormat getDurationW(CallContext context) { |
250 return getFormatter( | 248 return getFormatter( |
251 context, | 249 context, |
252 DURATION_W_MIN_DIGITS, | 250 DURATION_W_MIN_DIGITS, |
253 DURATION_W_MAX_DIGITS); | 251 DURATION_W_MAX_DIGITS); |
254 } | 252 } |
255 | 253 |
256 | 254 |
257 /** | 255 /** |
258 * Returns the number formatter for Q values in duration curve exports. | 256 * Returns the number formatter for Q values in duration curve exports. |
259 * | 257 * |
260 * @return the number formatter for W values. | 258 * @return the number formatter for W values. |
261 */ | 259 */ |
262 public static NumberFormat getDurationQ(CallContext context) { | 260 public static NumberFormat getDurationQ(CallContext context) { |
263 return getFormatter( | 261 return getFormatter( |
264 context, | 262 context, |
265 DURATION_Q_MIN_DIGITS, | 263 DURATION_Q_MIN_DIGITS, |
266 DURATION_Q_MAX_DIGITS); | 264 DURATION_Q_MAX_DIGITS); |
267 } | 265 } |
268 | 266 |
269 | 267 |
270 /** | 268 /** |
271 * Returns the number formatter for D values in duration curve exports. | 269 * Returns the number formatter for D values in duration curve exports. |
272 * | 270 * |
273 * @return the number formatter for W values. | 271 * @return the number formatter for W values. |
274 */ | 272 */ |
275 public static NumberFormat getDurationD(CallContext context) { | 273 public static NumberFormat getDurationD(CallContext context) { |
276 return getFormatter( | 274 return getFormatter( |
277 context, | 275 context, |
278 DURATION_D_MIN_DIGITS, | 276 DURATION_D_MIN_DIGITS, |
279 DURATION_D_MAX_DIGITS); | 277 DURATION_D_MAX_DIGITS); |
280 } | 278 } |
281 | 279 |
282 public static NumberFormat getCalculationKm(CallMeta meta) { | 280 public static NumberFormat getCalculationKm(CallMeta meta) { |
283 return getFormatter( | 281 return getFormatter( |
284 meta, | 282 meta, |
285 CALCULATION_REPORT_KM_MIN_DIGITS, | 283 CALCULATION_REPORT_KM_MIN_DIGITS, |
286 CALCULATION_REPORT_KM_MAX_DIGITS); | 284 CALCULATION_REPORT_KM_MAX_DIGITS); |
287 } | 285 } |
288 | 286 |
289 | 287 |
290 public static NumberFormat getFlowVelocityKM(CallContext context) { | 288 public static NumberFormat getFlowVelocityKM(CallContext context) { |
291 return getFormatter( | 289 return getFormatter( |
292 context, | 290 context, |
293 FLOW_VELOCITY_KM_MIN_DIGITS, | 291 FLOW_VELOCITY_KM_MIN_DIGITS, |
294 FLOW_VELOCITY_KM_MAX_DIGITS); | 292 FLOW_VELOCITY_KM_MAX_DIGITS); |
295 } | 293 } |
296 | 294 |
297 | 295 |
298 public static NumberFormat getFlowVelocityValues(CallContext context) { | 296 public static NumberFormat getFlowVelocityValues(CallContext context) { |
299 return getFormatter( | 297 return getFormatter( |
300 context, | 298 context, |
301 FLOW_VELOCITY_VALUES_MIN_DIGITS, | 299 FLOW_VELOCITY_VALUES_MIN_DIGITS, |
302 FLOW_VELOCITY_VALUES_MAX_DIGITS); | 300 FLOW_VELOCITY_VALUES_MAX_DIGITS); |
303 } | 301 } |
304 | 302 |
305 | 303 |
306 public static NumberFormat getFlowVelocityQ(CallContext context) { | 304 public static NumberFormat getFlowVelocityQ(CallContext context) { |
307 return getFormatter( | 305 return getFormatter( |
308 context, | 306 context, |
309 FLOW_VELOCITY_Q_MIN_DIGITS, | 307 FLOW_VELOCITY_Q_MIN_DIGITS, |
310 FLOW_VELOCITY_Q_MAX_DIGITS); | 308 FLOW_VELOCITY_Q_MAX_DIGITS); |
311 } | 309 } |
312 | 310 |
313 | 311 |
314 public static NumberFormat getMiddleBedHeightKM(CallContext context) { | 312 public static NumberFormat getMiddleBedHeightKM(CallContext context) { |
315 return getFormatter( | 313 return getFormatter( |
316 context, | 314 context, |
317 MIDDLE_BED_HEIGHT_KM_MIN_DIGITS, | 315 MIDDLE_BED_HEIGHT_KM_MIN_DIGITS, |
318 MIDDLE_BED_HEIGHT_KM_MAX_DIGITS); | 316 MIDDLE_BED_HEIGHT_KM_MAX_DIGITS); |
319 } | 317 } |
320 | 318 |
321 | 319 |
322 public static NumberFormat getMiddleBedHeightHeight(CallContext context) { | 320 public static NumberFormat getMiddleBedHeightHeight(CallContext context) { |
323 return getFormatter( | 321 return getFormatter( |
324 context, | 322 context, |
325 MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS, | 323 MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS, |
326 MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS); | 324 MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS); |
327 } | 325 } |
328 | 326 |
329 | 327 |
330 public static NumberFormat getMiddleBedHeightUncert(CallContext context) { | 328 public static NumberFormat getMiddleBedHeightUncert(CallContext context) { |
331 return getFormatter( | 329 return getFormatter( |
332 context, | 330 context, |
333 MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS, | 331 MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS, |
334 MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS); | 332 MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS); |
335 } | 333 } |
336 | 334 |
337 | 335 |
338 public static NumberFormat getMiddleBedHeightDataGap(CallContext context) { | 336 public static NumberFormat getMiddleBedHeightDataGap(CallContext context) { |
339 return getFormatter( | 337 return getFormatter( |
340 context, | 338 context, |
341 MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS, | 339 MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS, |
342 MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS); | 340 MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS); |
343 } | 341 } |
344 | 342 |
345 | 343 |
346 public static NumberFormat getMiddleBedHeightSounding(CallContext context) { | 344 public static NumberFormat getMiddleBedHeightSounding(CallContext context) { |
347 return getFormatter( | 345 return getFormatter( |
348 context, | 346 context, |
349 MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS, | 347 MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS, |
350 MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS); | 348 MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS); |
351 } | 349 } |
352 | 350 |
353 | 351 |
354 public static NumberFormat getMiddleBedHeightWidth(CallContext context) { | 352 public static NumberFormat getMiddleBedHeightWidth(CallContext context) { |
355 return getFormatter( | 353 return getFormatter( |
356 context, | 354 context, |
357 MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS, | 355 MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS, |
358 MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS); | 356 MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS); |
359 } | 357 } |
360 | 358 |
361 public static NumberFormat getFixDeltaWKM(CallContext context) { | 359 public static NumberFormat getFixDeltaWKM(CallContext context) { |
362 return getFormatter( | 360 return getFormatter( |
363 context, | 361 context, |
364 FIX_DELTA_W_KM_MIN_DIGITS, | 362 FIX_DELTA_W_KM_MIN_DIGITS, |
365 FIX_DELTA_W_KM_MAX_DIGITS); | 363 FIX_DELTA_W_KM_MAX_DIGITS); |
366 } | 364 } |
367 | 365 |
368 public static NumberFormat getFixDeltaWDeltaW(CallContext context) { | 366 public static NumberFormat getFixDeltaWDeltaW(CallContext context) { |
369 return getFormatter( | 367 return getFormatter( |
370 context, | 368 context, |
371 FIX_DELTA_W_DELTA_W_MIN_DIGITS, | 369 FIX_DELTA_W_DELTA_W_MIN_DIGITS, |
372 FIX_DELTA_W_DELTA_W_MAX_DIGITS); | 370 FIX_DELTA_W_DELTA_W_MAX_DIGITS); |
373 } | 371 } |
374 | 372 |
375 public static NumberFormat getFixDeltaWQ(CallContext context) { | 373 public static NumberFormat getFixDeltaWQ(CallContext context) { |
376 return getFormatter( | 374 return getFormatter( |
377 context, | 375 context, |
378 FIX_DELTA_W_DELTA_Q_MIN_DIGITS, | 376 FIX_DELTA_W_DELTA_Q_MIN_DIGITS, |
379 FIX_DELTA_W_DELTA_Q_MAX_DIGITS); | 377 FIX_DELTA_W_DELTA_Q_MAX_DIGITS); |
380 } | 378 } |
381 | 379 |
382 public static NumberFormat getFixDeltaWW(CallContext context) { | 380 public static NumberFormat getFixDeltaWW(CallContext context) { |
383 return getFormatter( | 381 return getFormatter( |
384 context, | 382 context, |
385 FIX_DELTA_W_DELTA_W_MIN_DIGITS, | 383 FIX_DELTA_W_DELTA_W_MIN_DIGITS, |
386 FIX_DELTA_W_DELTA_W_MAX_DIGITS); | 384 FIX_DELTA_W_DELTA_W_MAX_DIGITS); |
387 } | 385 } |
388 | 386 |
389 public static NumberFormat getMeterFormat(CallContext context) { | 387 public static NumberFormat getMeterFormat(CallContext context) { |
390 return getFormatter( | 388 return getFormatter( |
391 context, | 389 context, |
392 0, | 390 0, |
393 2); | 391 2); |
394 | 392 |
395 } | 393 } |
396 | 394 |
397 public static DateFormat getDateFormatter(CallMeta m, String pattern) { | 395 public static DateFormat getDateFormatter(CallMeta m, String pattern) { |
398 Locale locale = Resources.getLocale(m); | 396 Locale locale = Resources.getLocale(m); |