Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Resources |
|
| 1.0;1 |
1 | package us.daveread.basicquery.util; | |
2 | ||
3 | import java.util.ResourceBundle; | |
4 | import java.text.MessageFormat; | |
5 | ||
6 | /** | |
7 | * <p> | |
8 | * Title: Access resources for the application | |
9 | * </p> | |
10 | * | |
11 | * <p> | |
12 | * Description: | |
13 | * </p> | |
14 | * | |
15 | * <p> | |
16 | * Copyright: Copyright (c) 2004-2014 | |
17 | * </p> | |
18 | * | |
19 | * <p> | |
20 | * Company: | |
21 | * </p> | |
22 | * | |
23 | * @author David Read | |
24 | */ | |
25 | public class Resources { | |
26 | /** | |
27 | * The package containing the resource bundles | |
28 | */ | |
29 | private static final String RESOURCE_BUNDLE_PACKAGE = "us.daveread.basicquery.resourcebundles.BasicQueryResources"; | |
30 | ||
31 | /** | |
32 | * No operation | |
33 | */ | |
34 | 0 | private Resources() { |
35 | 0 | } |
36 | ||
37 | /** | |
38 | * Get the string associated with the supplied key using the current resource | |
39 | * bundle | |
40 | * | |
41 | * @param key | |
42 | * The key representing the text to return | |
43 | * | |
44 | * @return The text for the supplied key using the current resource bundle | |
45 | */ | |
46 | public static String getString(String key) { | |
47 | 59 | return ResourceBundle.getBundle(RESOURCE_BUNDLE_PACKAGE).getString(key); |
48 | } | |
49 | ||
50 | /** | |
51 | * Get the first character of the supplied key | |
52 | * | |
53 | * @param key | |
54 | * The key | |
55 | * | |
56 | * @return The first character of the key | |
57 | */ | |
58 | public static char getChar(String key) { | |
59 | 1 | return getString(key).charAt(0); |
60 | } | |
61 | ||
62 | /** | |
63 | * Get the parameterized string associated with the supplied key using the | |
64 | * current resource bundle and fill in the parameter values using the supplied | |
65 | * array of parameters | |
66 | * | |
67 | * @param key | |
68 | * The key representing the parameterized string to return | |
69 | * @param args | |
70 | * The parameter values to use to populate the parameterized string | |
71 | * | |
72 | * @return The text for the supplied key, updated with the supplied parameter | |
73 | * values, using the current resource bundle | |
74 | */ | |
75 | public static String getString(String key, Object[] args) { | |
76 | 8 | return MessageFormat.format(getString(key), args); |
77 | } | |
78 | ||
79 | /** | |
80 | * Convenience method to deal with string having one parameter | |
81 | * | |
82 | * @param key | |
83 | * The key representing the parameterized string to return | |
84 | * @param arg | |
85 | * The single parameter value to use to populate the parameterized | |
86 | * string | |
87 | * | |
88 | * @return | |
89 | * The text for the supplied key, updated with the supplied parameter | |
90 | * value, using the current resource bundle | |
91 | */ | |
92 | public static String getString(String key, String arg) { | |
93 | String[] args; | |
94 | ||
95 | 1 | args = new String[1]; |
96 | 1 | args[0] = arg; |
97 | ||
98 | 1 | return getString(key, args); |
99 | } | |
100 | ||
101 | /** | |
102 | * Convenience method to deal with string having two parameters | |
103 | * | |
104 | * @param key | |
105 | * The key representing the parameterized string to return | |
106 | * @param arg1 | |
107 | * The first parameter value to use to populate the parameterized | |
108 | * string | |
109 | * @param arg2 | |
110 | * The second parameter value to use to populate the parameterized | |
111 | * string | |
112 | * | |
113 | * @return | |
114 | * The text for the supplied key, updated with the supplied parameter | |
115 | * values, using the current resource bundle | |
116 | */ | |
117 | public static String getString(String key, String arg1, String arg2) { | |
118 | String[] args; | |
119 | ||
120 | 1 | args = new String[2]; |
121 | 1 | args[0] = arg1; |
122 | 1 | args[1] = arg2; |
123 | ||
124 | 1 | return getString(key, args); |
125 | } | |
126 | ||
127 | /** | |
128 | * Convenience method to deal with string having three parameters | |
129 | * | |
130 | * @param key | |
131 | * The key representing the parameterized string to return | |
132 | * @param arg1 | |
133 | * The first parameter value to use to populate the parameterized | |
134 | * string | |
135 | * @param arg2 | |
136 | * The second parameter value to use to populate the parameterized | |
137 | * string | |
138 | * @param arg3 | |
139 | * The third parameter value to use to populate the parameterized | |
140 | * string | |
141 | * | |
142 | * @return | |
143 | * The text for the supplied key, updated with the supplied parameter | |
144 | * values, using the current resource bundle | |
145 | */ | |
146 | public static String getString(String key, String arg1, String arg2, | |
147 | String arg3) { | |
148 | String[] args; | |
149 | ||
150 | 1 | args = new String[3]; |
151 | 1 | args[0] = arg1; |
152 | 1 | args[1] = arg2; |
153 | 1 | args[2] = arg3; |
154 | ||
155 | 1 | return getString(key, args); |
156 | } | |
157 | ||
158 | /** | |
159 | * Convenience method to deal with string having four parameters | |
160 | * | |
161 | * @param key | |
162 | * The key representing the parameterized string to return | |
163 | * @param arg1 | |
164 | * The first parameter value to use to populate the parameterized | |
165 | * string | |
166 | * @param arg2 | |
167 | * The second parameter value to use to populate the parameterized | |
168 | * string | |
169 | * @param arg3 | |
170 | * The third parameter value to use to populate the parameterized | |
171 | * string | |
172 | * @param arg4 | |
173 | * The fourth parameter value to use to populate the parameterized | |
174 | * string | |
175 | * | |
176 | * @return | |
177 | * The text for the supplied key, updated with the supplied parameter | |
178 | * values, using the current resource bundle | |
179 | */ | |
180 | public static String getString(String key, String arg1, String arg2, | |
181 | String arg3, String arg4) { | |
182 | String[] args; | |
183 | ||
184 | 1 | args = new String[4]; |
185 | 1 | args[0] = arg1; |
186 | 1 | args[1] = arg2; |
187 | 1 | args[2] = arg3; |
188 | 1 | args[3] = arg4; |
189 | ||
190 | 1 | return getString(key, args); |
191 | } | |
192 | ||
193 | /** | |
194 | * Convenience method to deal with string having five parameters | |
195 | * | |
196 | * @param key | |
197 | * The key representing the parameterized string to return | |
198 | * @param arg1 | |
199 | * The first parameter value to use to populate the parameterized | |
200 | * string | |
201 | * @param arg2 | |
202 | * The second parameter value to use to populate the parameterized | |
203 | * string | |
204 | * @param arg3 | |
205 | * The third parameter value to use to populate the parameterized | |
206 | * string | |
207 | * @param arg4 | |
208 | * The fourth parameter value to use to populate the parameterized | |
209 | * string | |
210 | * @param arg5 | |
211 | * The fifth parameter value to use to populate the parameterized | |
212 | * string | |
213 | * | |
214 | * @return | |
215 | * The text for the supplied key, updated with the supplied parameter | |
216 | * values, using the current resource bundle | |
217 | */ | |
218 | public static String getString(String key, String arg1, String arg2, | |
219 | String arg3, String arg4, String arg5) { | |
220 | String[] args; | |
221 | ||
222 | 1 | args = new String[5]; |
223 | 1 | args[0] = arg1; |
224 | 1 | args[1] = arg2; |
225 | 1 | args[2] = arg3; |
226 | 1 | args[3] = arg4; |
227 | 1 | args[4] = arg5; |
228 | ||
229 | 1 | return getString(key, args); |
230 | } | |
231 | ||
232 | /** | |
233 | * Convenience method to deal with string having six parameters | |
234 | * | |
235 | * @param key | |
236 | * The key representing the parameterized string to return | |
237 | * @param arg1 | |
238 | * The first parameter value to use to populate the parameterized | |
239 | * string | |
240 | * @param arg2 | |
241 | * The second parameter value to use to populate the parameterized | |
242 | * string | |
243 | * @param arg3 | |
244 | * The third parameter value to use to populate the parameterized | |
245 | * string | |
246 | * @param arg4 | |
247 | * The fourth parameter value to use to populate the parameterized | |
248 | * string | |
249 | * @param arg5 | |
250 | * The fifth parameter value to use to populate the parameterized | |
251 | * string | |
252 | * @param arg6 | |
253 | * The sixth parameter value to use to populate the parameterized | |
254 | * string | |
255 | * | |
256 | * @return | |
257 | * The text for the supplied key, updated with the supplied parameter | |
258 | * values, using the current resource bundle | |
259 | */ | |
260 | public static String getString(String key, String arg1, String arg2, | |
261 | String arg3, String arg4, String arg5, String arg6) { | |
262 | String[] args; | |
263 | ||
264 | 1 | args = new String[6]; |
265 | 1 | args[0] = arg1; |
266 | 1 | args[1] = arg2; |
267 | 1 | args[2] = arg3; |
268 | 1 | args[3] = arg4; |
269 | 1 | args[4] = arg5; |
270 | 1 | args[5] = arg6; |
271 | ||
272 | 1 | return getString(key, args); |
273 | } | |
274 | ||
275 | /** | |
276 | * Convenience method to deal with string having seven parameters | |
277 | * | |
278 | * @param key | |
279 | * The key representing the parameterized string to return | |
280 | * @param arg1 | |
281 | * The first parameter value to use to populate the parameterized | |
282 | * string | |
283 | * @param arg2 | |
284 | * The second parameter value to use to populate the parameterized | |
285 | * string | |
286 | * @param arg3 | |
287 | * The third parameter value to use to populate the parameterized | |
288 | * string | |
289 | * @param arg4 | |
290 | * The fourth parameter value to use to populate the parameterized | |
291 | * string | |
292 | * @param arg5 | |
293 | * The fifth parameter value to use to populate the parameterized | |
294 | * string | |
295 | * @param arg6 | |
296 | * The sixth parameter value to use to populate the parameterized | |
297 | * string | |
298 | * @param arg7 | |
299 | * The seventh parameter value to use to populate the parameterized | |
300 | * string | |
301 | * | |
302 | * @return | |
303 | * The text for the supplied key, updated with the supplied parameter | |
304 | * values, using the current resource bundle | |
305 | */ | |
306 | public static String getString(String key, String arg1, String arg2, | |
307 | String arg3, String arg4, String arg5, String arg6, String arg7) { | |
308 | String[] args; | |
309 | ||
310 | 1 | args = new String[7]; |
311 | 1 | args[0] = arg1; |
312 | 1 | args[1] = arg2; |
313 | 1 | args[2] = arg3; |
314 | 1 | args[3] = arg4; |
315 | 1 | args[4] = arg5; |
316 | 1 | args[5] = arg6; |
317 | 1 | args[6] = arg7; |
318 | ||
319 | 1 | return getString(key, args); |
320 | } | |
321 | } |