comparison flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java @ 3318:dbe2f85bf160

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

http://dive4elements.wald.intevation.org