comparison flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java @ 1190:f514894ec2fd

merged flys-artifacts/2.5
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:17 +0200
parents a7947972fdeb
children acb4d20b130e
comparison
equal deleted inserted replaced
917:b48c36076e17 1190:f514894ec2fd
1 package de.intevation.flys.utils;
2
3 import java.text.NumberFormat;
4 import java.util.Locale;
5
6 import de.intevation.artifacts.CallContext;
7
8 import de.intevation.flys.artifacts.resources.Resources;
9
10
11 public final class Formatter {
12
13 // WATERLEVEL FORMATTER CONSTANTS
14 public static final int WATERLEVEL_KM_MIN_DIGITS = 3;
15 public static final int WATERLEVEL_KM_MAX_DIGITS = 3;
16 public static final int WATERLEVEL_W_MIN_DIGITS = 0;
17 public static final int WATERLEVEL_W_MAX_DIGITS = 2;
18 public static final int WATERLEVEL_Q_MIN_DIGITS = 0;
19 public static final int WATERLEVEL_Q_MAX_DIGITS = 2;
20
21
22 // COMPUTED DISCHARGE CURVE FORMATTER CONSTANTS
23 public static final int COMPUTED_DISCHARGE_W_MIN_DIGITS = 2;
24 public static final int COMPUTED_DISCHARGE_W_MAX_DIGITS = 2;
25 public static final int COMPUTED_DISCHARGE_Q_MIN_DIGITS = 0;
26 public static final int COMPUTED_DISCHARGE_Q_MAX_DIGITS = 0;
27
28
29 // DURATION CURVE FORMATTER CONSTANTS
30 public static final int DURATION_W_MIN_DIGITS = 0;
31 public static final int DURATION_W_MAX_DIGITS = 2;
32 public static final int DURATION_Q_MIN_DIGITS = 0;
33 public static final int DURATION_Q_MAX_DIGITS = 1;
34 public static final int DURATION_D_MIN_DIGITS = 0;
35 public static final int DURATION_D_MAX_DIGITS = 0;
36
37
38 public static NumberFormat getFormatter(CallContext c, int min, int max){
39 Locale locale = Resources.getLocale(c.getMeta());
40 NumberFormat nf = NumberFormat.getInstance(locale);
41
42 nf.setMaximumFractionDigits(max);
43 nf.setMinimumFractionDigits(min);
44
45 return nf;
46 }
47
48
49 /**
50 * Returns the number formatter for kilometer values in waterlevel exports.
51 *
52 * @return the number formatter for kilometer values.
53 */
54 public static NumberFormat getWaterlevelKM(CallContext context) {
55 return getFormatter(
56 context,
57 WATERLEVEL_KM_MIN_DIGITS,
58 WATERLEVEL_KM_MAX_DIGITS);
59 }
60
61
62 /**
63 * Returns the number formatter for W values in waterlevel exports.
64 *
65 * @return the number formatter for W values.
66 */
67 public static NumberFormat getWaterlevelW(CallContext context) {
68 return getFormatter(
69 context,
70 WATERLEVEL_W_MIN_DIGITS,
71 WATERLEVEL_W_MAX_DIGITS);
72 }
73
74
75 /**
76 * Returns the number formatter for Q values in waterlevel exports.
77 *
78 * @return the number formatter for Q values.
79 */
80 public static NumberFormat getWaterlevelQ(CallContext context) {
81 return getFormatter(
82 context,
83 WATERLEVEL_Q_MIN_DIGITS,
84 WATERLEVEL_Q_MAX_DIGITS);
85 }
86
87
88 /**
89 * Returns the number formatter for W values in exports of computed
90 * discharge curves.
91 *
92 * @return the number formatter for W values.
93 */
94 public static NumberFormat getComputedDischargeW(CallContext context) {
95 return getFormatter(
96 context,
97 COMPUTED_DISCHARGE_W_MIN_DIGITS,
98 COMPUTED_DISCHARGE_W_MAX_DIGITS);
99 }
100
101
102 /**
103 * Returns the number formatter for Q values in exports of computed
104 * discharge curves.
105 *
106 * @return the number formatter for Q values.
107 */
108 public static NumberFormat getComputedDischargeQ(CallContext context) {
109 return getFormatter(
110 context,
111 COMPUTED_DISCHARGE_Q_MIN_DIGITS,
112 COMPUTED_DISCHARGE_Q_MAX_DIGITS);
113 }
114
115
116 /**
117 * Returns the number formatter for W values in duration curve exports.
118 *
119 * @return the number formatter for W values.
120 */
121 public static NumberFormat getDurationW(CallContext context) {
122 return getFormatter(
123 context,
124 DURATION_W_MIN_DIGITS,
125 DURATION_W_MAX_DIGITS);
126 }
127
128
129 /**
130 * Returns the number formatter for Q values in duration curve exports.
131 *
132 * @return the number formatter for W values.
133 */
134 public static NumberFormat getDurationQ(CallContext context) {
135 return getFormatter(
136 context,
137 DURATION_Q_MIN_DIGITS,
138 DURATION_Q_MAX_DIGITS);
139 }
140
141
142 /**
143 * Returns the number formatter for D values in duration curve exports.
144 *
145 * @return the number formatter for W values.
146 */
147 public static NumberFormat getDurationD(CallContext context) {
148 return getFormatter(
149 context,
150 DURATION_D_MIN_DIGITS,
151 DURATION_D_MAX_DIGITS);
152 }
153 }
154 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org