KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > format > Printf


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.format;
4
5 /**
6  * Printf.
7  */

8 public class Printf {
9
10     // ---------------------------------------------------------------- primitives
11

12     public static String JavaDoc str(String JavaDoc format, byte value) {
13         return new PrintfFormat(format).form(value);
14     }
15     public static void out(String JavaDoc format, byte value) {
16         System.out.println(str(format, value));
17     }
18
19
20     public static String JavaDoc str(String JavaDoc format, char value) {
21         return new PrintfFormat(format).form(value);
22     }
23     public static void out(String JavaDoc format, char value) {
24         System.out.println(str(format, value));
25     }
26
27
28     public static String JavaDoc str(String JavaDoc format, short value) {
29         return new PrintfFormat(format).form(value);
30     }
31     public static void out(String JavaDoc format, short value) {
32         System.out.println(str(format, value));
33     }
34
35
36     public static String JavaDoc str(String JavaDoc format, int value) {
37         return new PrintfFormat(format).form(value);
38     }
39     public static void out(String JavaDoc format, int value) {
40         System.out.println(str(format, value));
41     }
42
43
44     public static String JavaDoc str(String JavaDoc format, long value) {
45         return new PrintfFormat(format).form(value);
46     }
47     public static void out(String JavaDoc format, long value) {
48         System.out.println(str(format, value));
49     }
50
51
52     public static String JavaDoc str(String JavaDoc format, float value) {
53         return new PrintfFormat(format).form(value);
54     }
55     public static void out(String JavaDoc format, float value) {
56         System.out.println(str(format, value));
57     }
58
59
60     public static String JavaDoc str(String JavaDoc format, double value) {
61         return new PrintfFormat(format).form(value);
62     }
63     public static void out(String JavaDoc format, double value) {
64         System.out.println(str(format, value));
65     }
66
67
68     public static String JavaDoc str(String JavaDoc format, boolean value) {
69         return new PrintfFormat(format).form(value);
70     }
71     public static void out(String JavaDoc format, boolean value) {
72         System.out.println(str(format, value));
73     }
74
75
76     public static String JavaDoc str(String JavaDoc format, String JavaDoc value) {
77         return new PrintfFormat(format).form(value);
78     }
79     public static void out(String JavaDoc format, String JavaDoc value) {
80         System.out.println(str(format, value));
81     }
82
83
84
85     // ---------------------------------------------------------------- wrappers
86

87     public static String JavaDoc str(String JavaDoc format, Byte JavaDoc value) {
88         return new PrintfFormat(format).form(value.byteValue());
89     }
90     public static void out(String JavaDoc format, Byte JavaDoc value) {
91         System.out.println(str(format, value));
92     }
93     
94
95     public static String JavaDoc str(String JavaDoc format, Character JavaDoc value) {
96         return new PrintfFormat(format).form(value.charValue());
97     }
98     public static void out(String JavaDoc format, Character JavaDoc value) {
99         System.out.println(str(format, value));
100     }
101     
102
103     public static String JavaDoc str(String JavaDoc format, Short JavaDoc value) {
104         return new PrintfFormat(format).form(value.shortValue());
105     }
106     public static void out(String JavaDoc format, Short JavaDoc value) {
107         System.out.println(str(format, value));
108     }
109     
110
111     public static String JavaDoc str(String JavaDoc format, Integer JavaDoc value) {
112         return new PrintfFormat(format).form(value.intValue());
113     }
114     public static void out(String JavaDoc format, Integer JavaDoc value) {
115         System.out.println(str(format, value));
116     }
117     
118
119     public static String JavaDoc str(String JavaDoc format, Long JavaDoc value) {
120         return new PrintfFormat(format).form(value.longValue());
121     }
122     public static void out(String JavaDoc format, Long JavaDoc value) {
123         System.out.println(str(format, value));
124     }
125     
126
127     public static String JavaDoc str(String JavaDoc format, Float JavaDoc value) {
128         return new PrintfFormat(format).form(value.floatValue());
129     }
130     public static void out(String JavaDoc format, Float JavaDoc value) {
131         System.out.println(str(format, value));
132     }
133     
134
135     public static String JavaDoc str(String JavaDoc format, Double JavaDoc value) {
136         return new PrintfFormat(format).form(value.doubleValue());
137     }
138     public static void out(String JavaDoc format, Double JavaDoc value) {
139         System.out.println(str(format, value));
140     }
141     
142
143     public static String JavaDoc str(String JavaDoc format, Boolean JavaDoc value) {
144         return new PrintfFormat(format).form(value.booleanValue());
145     }
146     public static void out(String JavaDoc format, Boolean JavaDoc value) {
147         System.out.println(str(format, value));
148     }
149     
150
151
152     // ---------------------------------------------------------------- arrays
153

154     public static String JavaDoc str(String JavaDoc format, byte[] params) {
155         PrintfFormat pf = new PrintfFormat();
156         for (int i = 0; i < params.length; i++) {
157             format = pf.reinit(format).form(params[i]);
158         }
159         return format;
160     }
161     public static void out(String JavaDoc format, byte[] params) {
162         System.out.println(str(format, params));
163     }
164
165
166     public static String JavaDoc str(String JavaDoc format, char[] params) {
167         PrintfFormat pf = new PrintfFormat();
168         for (int i = 0; i < params.length; i++) {
169             format = pf.reinit(format).form(params[i]);
170         }
171         return format;
172     }
173     public static void out(String JavaDoc format, char[] params) {
174         System.out.println(str(format, params));
175     }
176
177
178     public static String JavaDoc str(String JavaDoc format, short[] params) {
179         PrintfFormat pf = new PrintfFormat();
180         for (int i = 0; i < params.length; i++) {
181             format = pf.reinit(format).form(params[i]);
182         }
183         return format;
184     }
185     public static void out(String JavaDoc format, short[] params) {
186         System.out.println(str(format, params));
187     }
188
189
190     public static String JavaDoc str(String JavaDoc format, int[] params) {
191         PrintfFormat pf = new PrintfFormat();
192         for (int i = 0; i < params.length; i++) {
193             format = pf.reinit(format).form(params[i]);
194         }
195         return format;
196     }
197     public static void out(String JavaDoc format, int[] params) {
198         System.out.println(str(format, params));
199     }
200
201
202     public static String JavaDoc str(String JavaDoc format, long[] params) {
203         PrintfFormat pf = new PrintfFormat();
204         for (int i = 0; i < params.length; i++) {
205             format = pf.reinit(format).form(params[i]);
206         }
207         return format;
208     }
209     public static void out(String JavaDoc format, long[] params) {
210         System.out.println(str(format, params));
211     }
212
213
214     public static String JavaDoc str(String JavaDoc format, float[] params) {
215         PrintfFormat pf = new PrintfFormat();
216         for (int i = 0; i < params.length; i++) {
217             format = pf.reinit(format).form(params[i]);
218         }
219         return format;
220     }
221     public static void out(String JavaDoc format, float[] params) {
222         System.out.println(str(format, params));
223     }
224
225
226     public static String JavaDoc str(String JavaDoc format, double[] params) {
227         PrintfFormat pf = new PrintfFormat();
228         for (int i = 0; i < params.length; i++) {
229             format = pf.reinit(format).form(params[i]);
230         }
231         return format;
232     }
233     public static void out(String JavaDoc format, double[] params) {
234         System.out.println(str(format, params));
235     }
236
237
238     public static String JavaDoc str(String JavaDoc format, boolean[] params) {
239         PrintfFormat pf = new PrintfFormat();
240         for (int i = 0; i < params.length; i++) {
241             format = pf.reinit(format).form(params[i]);
242         }
243         return format;
244     }
245     public static void out(String JavaDoc format, boolean[] params) {
246         System.out.println(str(format, params));
247     }
248
249
250     public static String JavaDoc str(String JavaDoc format, String JavaDoc[] params) {
251         PrintfFormat pf = new PrintfFormat();
252         for (int i = 0; i < params.length; i++) {
253             format = pf.reinit(format).form(params[i]);
254         }
255         return format;
256     }
257     public static void out(String JavaDoc format, String JavaDoc[] params) {
258         System.out.println(str(format, params));
259     }
260
261
262
263     // ---------------------------------------------------------------- wrapper arrays
264

265     public static String JavaDoc str(String JavaDoc format, Byte JavaDoc[] params) {
266         PrintfFormat pf = new PrintfFormat();
267         for (int i = 0; i < params.length; i++) {
268             byte param = params[i].byteValue();
269             format = pf.reinit(format).form(param);
270         }
271         return format;
272     }
273     public static void out(String JavaDoc format, Byte JavaDoc[] params) {
274         System.out.println(str(format, params));
275     }
276
277     public static String JavaDoc str(String JavaDoc format, Character JavaDoc[] params) {
278         PrintfFormat pf = new PrintfFormat();
279         for (int i = 0; i < params.length; i++) {
280             char param = params[i].charValue();
281             format = pf.reinit(format).form(param);
282         }
283         return format;
284     }
285     public static void out(String JavaDoc format, Character JavaDoc[] params) {
286         System.out.println(str(format, params));
287     }
288
289     public static String JavaDoc str(String JavaDoc format, Short JavaDoc[] params) {
290         PrintfFormat pf = new PrintfFormat();
291         for (int i = 0; i < params.length; i++) {
292             short param = params[i].shortValue();
293             format = pf.reinit(format).form(param);
294         }
295         return format;
296     }
297     public static void out(String JavaDoc format, Short JavaDoc[] params) {
298         System.out.println(str(format, params));
299     }
300
301     public static String JavaDoc str(String JavaDoc format, Integer JavaDoc[] params) {
302         PrintfFormat pf = new PrintfFormat();
303         for (int i = 0; i < params.length; i++) {
304             int param = params[i].intValue();
305             format = pf.reinit(format).form(param);
306         }
307         return format;
308     }
309     public static void out(String JavaDoc format, Integer JavaDoc[] params) {
310         System.out.println(str(format, params));
311     }
312
313     public static String JavaDoc str(String JavaDoc format, Long JavaDoc[] params) {
314         PrintfFormat pf = new PrintfFormat();
315         for (int i = 0; i < params.length; i++) {
316             long param = params[i].longValue();
317             format = pf.reinit(format).form(param);
318         }
319         return format;
320     }
321     public static void out(String JavaDoc format, Long JavaDoc[] params) {
322         System.out.println(str(format, params));
323     }
324
325     public static String JavaDoc str(String JavaDoc format, Float JavaDoc[] params) {
326         PrintfFormat pf = new PrintfFormat();
327         for (int i = 0; i < params.length; i++) {
328             float param = params[i].floatValue();
329             format = pf.reinit(format).form(param);
330         }
331         return format;
332     }
333     public static void out(String JavaDoc format, Float JavaDoc[] params) {
334         System.out.println(str(format, params));
335     }
336
337     public static String JavaDoc str(String JavaDoc format, Double JavaDoc[] params) {
338         PrintfFormat pf = new PrintfFormat();
339         for (int i = 0; i < params.length; i++) {
340             double param = params[i].doubleValue();
341             format = pf.reinit(format).form(param);
342         }
343         return format;
344     }
345     public static void out(String JavaDoc format, Double JavaDoc[] params) {
346         System.out.println(str(format, params));
347     }
348
349     public static String JavaDoc str(String JavaDoc format, Boolean JavaDoc[] params) {
350         PrintfFormat pf = new PrintfFormat();
351         for (int i = 0; i < params.length; i++) {
352             boolean param = params[i].booleanValue();
353             format = pf.reinit(format).form(param);
354         }
355         return format;
356     }
357     public static void out(String JavaDoc format, Boolean JavaDoc[] params) {
358         System.out.println(str(format, params));
359     }
360
361
362     // ---------------------------------------------------------------- object array
363

364     public static String JavaDoc str(String JavaDoc format, Object JavaDoc[] params) {
365         PrintfFormat pf = new PrintfFormat();
366         for (int i = 0; i < params.length; i++) {
367             pf.reinit(format);
368
369             Object JavaDoc param = params[i];
370             if (param instanceof Integer JavaDoc) {
371                 format = pf.form(((Integer JavaDoc) param).intValue());
372             } else if (param instanceof Long JavaDoc) {
373                 format = pf.form(((Long JavaDoc) param).longValue());
374             } else if (param instanceof Character JavaDoc) {
375                 format = pf.form(((Character JavaDoc) param).charValue());
376             } else if (param instanceof Double JavaDoc) {
377                 format = pf.form(((Double JavaDoc) param).doubleValue());
378             } else if (param instanceof Float JavaDoc) {
379                 format = pf.form(((Float JavaDoc) param).floatValue());
380             } else {
381                 format = pf.form(param.toString());
382             }
383         }
384         return format;
385     }
386     public static void out(String JavaDoc format, Object JavaDoc[] params) {
387         System.out.println(str(format, params));
388     }
389
390 }
Popular Tags