comparison flys-artifacts/src/main/java/org/dive4elements/river/utils/Formatter.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/utils/Formatter.java@db4e7ff0b987
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.utils;
2
3 import java.text.DateFormat;
4 import java.text.NumberFormat;
5 import java.text.SimpleDateFormat;
6 import java.util.Locale;
7
8 import org.dive4elements.artifacts.CallContext;
9 import org.dive4elements.artifacts.CallMeta;
10 import org.dive4elements.river.artifacts.resources.Resources;
11
12
13 /** Helper to access static i18n Formatters. */
14 public final class Formatter {
15
16 // KMS IN ERROR REPORTS.
17 public static final int CALCULATION_REPORT_KM_MIN_DIGITS = 1;
18 public static final int CALCULATION_REPORT_KM_MAX_DIGITS = 3;
19
20 // WATERLEVEL FORMATTER CONSTANTS
21 public static final int WATERLEVEL_KM_MIN_DIGITS = 3;
22 public static final int WATERLEVEL_KM_MAX_DIGITS = 3;
23 public static final int WATERLEVEL_W_MIN_DIGITS = 0;
24 public static final int WATERLEVEL_W_MAX_DIGITS = 2;
25 public static final int WATERLEVEL_Q_MIN_DIGITS = 0;
26 public static final int WATERLEVEL_Q_MAX_DIGITS = 2;
27
28
29 // COMPUTED DISCHARGE CURVE FORMATTER CONSTANTS
30 public static final int COMPUTED_DISCHARGE_W_MIN_DIGITS = 2;
31 public static final int COMPUTED_DISCHARGE_W_MAX_DIGITS = 2;
32 public static final int COMPUTED_DISCHARGE_Q_MIN_DIGITS = 0;
33 public static final int COMPUTED_DISCHARGE_Q_MAX_DIGITS = 2;
34
35
36 // HISTORICAL DISCHARGE CURVE FORMATTER CONSTANTS
37 public static final int HISTORICAL_DISCHARGE_W_MIN_DIGITS = 0;
38 public static final int HISTORICAL_DISCHARGE_W_MAX_DIGITS = 2;
39 public static final int HISTORICAL_DISCHARGE_Q_MIN_DIGITS = 0;
40 public static final int HISTORICAL_DISCHARGE_Q_MAX_DIGITS = 2;
41
42
43 // DURATION CURVE FORMATTER CONSTANTS
44 public static final int DURATION_W_MIN_DIGITS = 0;
45 public static final int DURATION_W_MAX_DIGITS = 2;
46 public static final int DURATION_Q_MIN_DIGITS = 0;
47 public static final int DURATION_Q_MAX_DIGITS = 1;
48 public static final int DURATION_D_MIN_DIGITS = 0;
49 public static final int DURATION_D_MAX_DIGITS = 0;
50
51
52 // FLOW VELOCITY FORMATTER CONSTANTS
53 public static final int FLOW_VELOCITY_KM_MIN_DIGITS = 3;
54 public static final int FLOW_VELOCITY_KM_MAX_DIGITS = 3;
55 public static final int FLOW_VELOCITY_VALUES_MIN_DIGITS = 2;
56 public static final int FLOW_VELOCITY_VALUES_MAX_DIGITS = 2;
57 public static final int FLOW_VELOCITY_Q_MIN_DIGITS = 0;
58 public static final int FLOW_VELOCITY_Q_MAX_DIGITS = 2;
59
60
61 // MIDDLE BED HEIGHT FORMATTER CONSTANTS
62 public static final int MIDDLE_BED_HEIGHT_KM_MIN_DIGITS = 3;
63 public static final int MIDDLE_BED_HEIGHT_KM_MAX_DIGITS = 3;
64 public static final int MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS = 3;
65 public static final int MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS = 3;
66 public static final int MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS = 3;
67 public static final int MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS = 3;
68 public static final int MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS = 2;
69 public static final int MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS = 2;
70 public static final int MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS = 0;
71 public static final int MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS = 0;
72 public static final int MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS = 3;
73 public static final int MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS = 3;
74
75 public static final int FIX_DELTA_W_KM_MIN_DIGITS = 3;
76 public static final int FIX_DELTA_W_KM_MAX_DIGITS = 3;
77 public static final int FIX_DELTA_W_DELTA_W_MIN_DIGITS = 3;
78 public static final int FIX_DELTA_W_DELTA_W_MAX_DIGITS = 3;
79 public static final int FIX_DELTA_W_DELTA_Q_MIN_DIGITS = 0;
80 public static final int FIX_DELTA_W_DELTA_Q_MAX_DIGITS = 2;
81
82
83 /**
84 * Creates a localized NumberFormatter with given range of decimal digits.
85 * @param m CallMeta to find the locale.
86 * @param min minimum number of decimal ("fraction") digits.
87 * @param max maximum number of decimal ("fraction") digits.
88 * @return A NumberFormat. Use #format(NUMBER) to get String representation
89 * of NUMBER.
90 */
91 public static NumberFormat getFormatter(CallMeta m, int min, int max){
92 Locale locale = Resources.getLocale(m);
93 NumberFormat nf = NumberFormat.getInstance(locale);
94
95 nf.setMaximumFractionDigits(max);
96 nf.setMinimumFractionDigits(min);
97
98 return nf;
99 }
100
101
102 public static NumberFormat getFormatter(CallContext c, int min, int max){
103 return getFormatter(c.getMeta(), min, max);
104 }
105
106
107 /**
108 * Returns a number formatter with no max or min digits set.
109 *
110 * @param c The CallContext.
111 *
112 * @return a number formatter.
113 */
114 public static NumberFormat getRawFormatter(CallContext c) {
115 Locale locale = Resources.getLocale(c.getMeta());
116 return NumberFormat.getInstance(locale);
117 }
118
119
120 /**
121 * Returns a date formatter with SHORT style.
122 */
123 public static DateFormat getShortDateFormat(CallContext cc) {
124 Locale locale = Resources.getLocale(cc.getMeta());
125 return DateFormat.getDateInstance(DateFormat.SHORT, locale);
126 }
127
128
129 /**
130 * Returns a date formatter with MEDIUM style.
131 */
132 public static DateFormat getMediumDateFormat(CallContext cc) {
133 Locale locale = Resources.getLocale(cc.getMeta());
134 return DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
135 }
136
137
138 /**
139 * Returns the number formatter for kilometer values in waterlevel exports.
140 *
141 * @return the number formatter for kilometer values.
142 */
143 public static NumberFormat getWaterlevelKM(CallContext context) {
144 return getFormatter(
145 context,
146 WATERLEVEL_KM_MIN_DIGITS,
147 WATERLEVEL_KM_MAX_DIGITS);
148 }
149
150
151 public static NumberFormat getWaterlevelW(CallMeta meta) {
152 return getFormatter(
153 meta,
154 WATERLEVEL_W_MIN_DIGITS,
155 WATERLEVEL_W_MAX_DIGITS);
156 }
157
158
159 /**
160 * Returns the number formatter for W values in waterlevel exports.
161 *
162 * @return the number formatter for W values.
163 */
164 public static NumberFormat getWaterlevelW(CallContext context) {
165 return getFormatter(
166 context,
167 WATERLEVEL_W_MIN_DIGITS,
168 WATERLEVEL_W_MAX_DIGITS);
169 }
170
171
172 /**
173 * Returns the number formatter for Q values in waterlevel exports.
174 *
175 * @return the number formatter for Q values.
176 */
177 public static NumberFormat getWaterlevelQ(CallContext context) {
178 return getFormatter(
179 context,
180 WATERLEVEL_Q_MIN_DIGITS,
181 WATERLEVEL_Q_MAX_DIGITS);
182 }
183
184
185 public static NumberFormat getWaterlevelQ(CallMeta meta) {
186 return getFormatter(
187 meta,
188 WATERLEVEL_Q_MIN_DIGITS,
189 WATERLEVEL_Q_MAX_DIGITS);
190 }
191
192 /**
193 * Returns the number formatter for W values in exports of computed
194 * discharge curves.
195 *
196 * @return the number formatter for W values.
197 */
198 public static NumberFormat getComputedDischargeW(CallContext context) {
199 return getFormatter(
200 context,
201 COMPUTED_DISCHARGE_W_MIN_DIGITS,
202 COMPUTED_DISCHARGE_W_MAX_DIGITS);
203 }
204
205
206 /**
207 * Returns the number formatter for Q values in exports of computed
208 * discharge curves.
209 *
210 * @return the number formatter for Q values.
211 */
212 public static NumberFormat getComputedDischargeQ(CallContext context) {
213 return getFormatter(
214 context,
215 COMPUTED_DISCHARGE_Q_MIN_DIGITS,
216 COMPUTED_DISCHARGE_Q_MAX_DIGITS);
217 }
218
219
220 /**
221 * Returns the number formatter for W values in exports of historical
222 * discharge curves.
223 *
224 * @return the number formatter for W values.
225 */
226 public static NumberFormat getHistoricalDischargeW(CallContext context) {
227 return getFormatter(
228 context,
229 HISTORICAL_DISCHARGE_W_MIN_DIGITS,
230 HISTORICAL_DISCHARGE_W_MAX_DIGITS);
231 }
232
233
234 /**
235 * Returns the number formatter for Q values in exports of historical
236 * discharge curves.
237 *
238 * @return the number formatter for Q values.
239 */
240 public static NumberFormat getHistoricalDischargeQ(CallContext context) {
241 return getFormatter(
242 context,
243 HISTORICAL_DISCHARGE_Q_MIN_DIGITS,
244 HISTORICAL_DISCHARGE_Q_MAX_DIGITS);
245 }
246
247
248 /**
249 * Returns the number formatter for W values in duration curve exports.
250 *
251 * @return the number formatter for W values.
252 */
253 public static NumberFormat getDurationW(CallContext context) {
254 return getFormatter(
255 context,
256 DURATION_W_MIN_DIGITS,
257 DURATION_W_MAX_DIGITS);
258 }
259
260
261 /**
262 * Returns the number formatter for Q values in duration curve exports.
263 *
264 * @return the number formatter for W values.
265 */
266 public static NumberFormat getDurationQ(CallContext context) {
267 return getFormatter(
268 context,
269 DURATION_Q_MIN_DIGITS,
270 DURATION_Q_MAX_DIGITS);
271 }
272
273
274 /**
275 * Returns the number formatter for D values in duration curve exports.
276 *
277 * @return the number formatter for W values.
278 */
279 public static NumberFormat getDurationD(CallContext context) {
280 return getFormatter(
281 context,
282 DURATION_D_MIN_DIGITS,
283 DURATION_D_MAX_DIGITS);
284 }
285
286 public static NumberFormat getCalculationKm(CallMeta meta) {
287 return getFormatter(
288 meta,
289 CALCULATION_REPORT_KM_MIN_DIGITS,
290 CALCULATION_REPORT_KM_MAX_DIGITS);
291 }
292
293
294 public static NumberFormat getFlowVelocityKM(CallContext context) {
295 return getFormatter(
296 context,
297 FLOW_VELOCITY_KM_MIN_DIGITS,
298 FLOW_VELOCITY_KM_MAX_DIGITS);
299 }
300
301
302 public static NumberFormat getFlowVelocityValues(CallContext context) {
303 return getFormatter(
304 context,
305 FLOW_VELOCITY_VALUES_MIN_DIGITS,
306 FLOW_VELOCITY_VALUES_MAX_DIGITS);
307 }
308
309
310 public static NumberFormat getFlowVelocityQ(CallContext context) {
311 return getFormatter(
312 context,
313 FLOW_VELOCITY_Q_MIN_DIGITS,
314 FLOW_VELOCITY_Q_MAX_DIGITS);
315 }
316
317
318 public static NumberFormat getMiddleBedHeightKM(CallContext context) {
319 return getFormatter(
320 context,
321 MIDDLE_BED_HEIGHT_KM_MIN_DIGITS,
322 MIDDLE_BED_HEIGHT_KM_MAX_DIGITS);
323 }
324
325
326 public static NumberFormat getMiddleBedHeightHeight(CallContext context) {
327 return getFormatter(
328 context,
329 MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS,
330 MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS);
331 }
332
333
334 public static NumberFormat getMiddleBedHeightUncert(CallContext context) {
335 return getFormatter(
336 context,
337 MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS,
338 MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS);
339 }
340
341
342 public static NumberFormat getMiddleBedHeightDataGap(CallContext context) {
343 return getFormatter(
344 context,
345 MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS,
346 MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS);
347 }
348
349
350 public static NumberFormat getMiddleBedHeightSounding(CallContext context) {
351 return getFormatter(
352 context,
353 MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS,
354 MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS);
355 }
356
357
358 public static NumberFormat getMiddleBedHeightWidth(CallContext context) {
359 return getFormatter(
360 context,
361 MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS,
362 MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS);
363 }
364
365 public static NumberFormat getFixDeltaWKM(CallContext context) {
366 return getFormatter(
367 context,
368 FIX_DELTA_W_KM_MIN_DIGITS,
369 FIX_DELTA_W_KM_MAX_DIGITS);
370 }
371
372 public static NumberFormat getFixDeltaWDeltaW(CallContext context) {
373 return getFormatter(
374 context,
375 FIX_DELTA_W_DELTA_W_MIN_DIGITS,
376 FIX_DELTA_W_DELTA_W_MAX_DIGITS);
377 }
378
379 public static NumberFormat getFixDeltaWQ(CallContext context) {
380 return getFormatter(
381 context,
382 FIX_DELTA_W_DELTA_Q_MIN_DIGITS,
383 FIX_DELTA_W_DELTA_Q_MAX_DIGITS);
384 }
385
386 public static NumberFormat getFixDeltaWW(CallContext context) {
387 return getFormatter(
388 context,
389 FIX_DELTA_W_DELTA_W_MIN_DIGITS,
390 FIX_DELTA_W_DELTA_W_MAX_DIGITS);
391 }
392
393 public static NumberFormat getMeterFormat(CallContext context) {
394 return getFormatter(
395 context,
396 0,
397 2);
398
399 }
400
401 public static DateFormat getDateFormatter(CallMeta m, String pattern) {
402 Locale locale = Resources.getLocale(m);
403 return new SimpleDateFormat(pattern, locale);
404 }
405 }
406 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org