Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java @ 3818:dc18457b1cef
merged flys-artifacts/pre2.7-2012-03-16
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:59 +0200 |
parents | 7dd45896e941 |
children | 4c00cf83fff1 |
comparison
equal
deleted
inserted
replaced
2456:60ab1054069d | 3818:dc18457b1cef |
---|---|
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 public static NumberFormat getFormatter(CallMeta m, int min, int max){ | |
52 Locale locale = Resources.getLocale(m); | |
53 NumberFormat nf = NumberFormat.getInstance(locale); | |
54 | |
55 nf.setMaximumFractionDigits(max); | |
56 nf.setMinimumFractionDigits(min); | |
57 | |
58 return nf; | |
59 } | |
60 | |
61 public static NumberFormat getFormatter(CallContext c, int min, int max){ | |
62 return getFormatter(c.getMeta(), min, max); | |
63 } | |
64 | |
65 | |
66 /** | |
67 * Returns a number formatter with no max or min digits set. | |
68 * | |
69 * @param c The CallContext. | |
70 * | |
71 * @return a number formatter. | |
72 */ | |
73 public static NumberFormat getRawFormatter(CallContext c) { | |
74 Locale locale = Resources.getLocale(c.getMeta()); | |
75 return NumberFormat.getInstance(locale); | |
76 } | |
77 | |
78 | |
79 /** | |
80 * Returns a date formatter with SHORT style. | |
81 */ | |
82 public static DateFormat getShortDateFormat(CallContext cc) { | |
83 Locale locale = Resources.getLocale(cc.getMeta()); | |
84 return DateFormat.getDateInstance(DateFormat.SHORT, locale); | |
85 } | |
86 | |
87 | |
88 /** | |
89 * Returns a date formatter with MEDIUM style. | |
90 */ | |
91 public static DateFormat getMediumDateFormat(CallContext cc) { | |
92 Locale locale = Resources.getLocale(cc.getMeta()); | |
93 return DateFormat.getDateInstance(DateFormat.MEDIUM, locale); | |
94 } | |
95 | |
96 | |
97 /** | |
98 * Returns the number formatter for kilometer values in waterlevel exports. | |
99 * | |
100 * @return the number formatter for kilometer values. | |
101 */ | |
102 public static NumberFormat getWaterlevelKM(CallContext context) { | |
103 return getFormatter( | |
104 context, | |
105 WATERLEVEL_KM_MIN_DIGITS, | |
106 WATERLEVEL_KM_MAX_DIGITS); | |
107 } | |
108 | |
109 | |
110 /** | |
111 * Returns the number formatter for W values in waterlevel exports. | |
112 * | |
113 * @return the number formatter for W values. | |
114 */ | |
115 public static NumberFormat getWaterlevelW(CallContext context) { | |
116 return getFormatter( | |
117 context, | |
118 WATERLEVEL_W_MIN_DIGITS, | |
119 WATERLEVEL_W_MAX_DIGITS); | |
120 } | |
121 | |
122 | |
123 /** | |
124 * Returns the number formatter for Q values in waterlevel exports. | |
125 * | |
126 * @return the number formatter for Q values. | |
127 */ | |
128 public static NumberFormat getWaterlevelQ(CallContext context) { | |
129 return getFormatter( | |
130 context, | |
131 WATERLEVEL_Q_MIN_DIGITS, | |
132 WATERLEVEL_Q_MAX_DIGITS); | |
133 } | |
134 | |
135 | |
136 /** | |
137 * Returns the number formatter for W values in exports of computed | |
138 * discharge curves. | |
139 * | |
140 * @return the number formatter for W values. | |
141 */ | |
142 public static NumberFormat getComputedDischargeW(CallContext context) { | |
143 return getFormatter( | |
144 context, | |
145 COMPUTED_DISCHARGE_W_MIN_DIGITS, | |
146 COMPUTED_DISCHARGE_W_MAX_DIGITS); | |
147 } | |
148 | |
149 | |
150 /** | |
151 * Returns the number formatter for Q values in exports of computed | |
152 * discharge curves. | |
153 * | |
154 * @return the number formatter for Q values. | |
155 */ | |
156 public static NumberFormat getComputedDischargeQ(CallContext context) { | |
157 return getFormatter( | |
158 context, | |
159 COMPUTED_DISCHARGE_Q_MIN_DIGITS, | |
160 COMPUTED_DISCHARGE_Q_MAX_DIGITS); | |
161 } | |
162 | |
163 | |
164 /** | |
165 * Returns the number formatter for W values in exports of historical | |
166 * discharge curves. | |
167 * | |
168 * @return the number formatter for W values. | |
169 */ | |
170 public static NumberFormat getHistoricalDischargeW(CallContext context) { | |
171 return getFormatter( | |
172 context, | |
173 HISTORICAL_DISCHARGE_W_MIN_DIGITS, | |
174 HISTORICAL_DISCHARGE_W_MAX_DIGITS); | |
175 } | |
176 | |
177 | |
178 /** | |
179 * Returns the number formatter for Q values in exports of historical | |
180 * discharge curves. | |
181 * | |
182 * @return the number formatter for Q values. | |
183 */ | |
184 public static NumberFormat getHistoricalDischargeQ(CallContext context) { | |
185 return getFormatter( | |
186 context, | |
187 HISTORICAL_DISCHARGE_Q_MIN_DIGITS, | |
188 HISTORICAL_DISCHARGE_Q_MAX_DIGITS); | |
189 } | |
190 | |
191 | |
192 /** | |
193 * Returns the number formatter for W values in duration curve exports. | |
194 * | |
195 * @return the number formatter for W values. | |
196 */ | |
197 public static NumberFormat getDurationW(CallContext context) { | |
198 return getFormatter( | |
199 context, | |
200 DURATION_W_MIN_DIGITS, | |
201 DURATION_W_MAX_DIGITS); | |
202 } | |
203 | |
204 | |
205 /** | |
206 * Returns the number formatter for Q values in duration curve exports. | |
207 * | |
208 * @return the number formatter for W values. | |
209 */ | |
210 public static NumberFormat getDurationQ(CallContext context) { | |
211 return getFormatter( | |
212 context, | |
213 DURATION_Q_MIN_DIGITS, | |
214 DURATION_Q_MAX_DIGITS); | |
215 } | |
216 | |
217 | |
218 /** | |
219 * Returns the number formatter for D values in duration curve exports. | |
220 * | |
221 * @return the number formatter for W values. | |
222 */ | |
223 public static NumberFormat getDurationD(CallContext context) { | |
224 return getFormatter( | |
225 context, | |
226 DURATION_D_MIN_DIGITS, | |
227 DURATION_D_MAX_DIGITS); | |
228 } | |
229 | |
230 public static NumberFormat getCalculationKm(CallMeta meta) { | |
231 return getFormatter( | |
232 meta, | |
233 CALCULATION_REPORT_KM_MIN_DIGITS, | |
234 CALCULATION_REPORT_KM_MAX_DIGITS); | |
235 } | |
236 } | |
237 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |