KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > util > Display


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2002, 2003 Søren Bak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package bak.pcj.util;
20
21 /**
22  * This class provides static methods for display of collection
23  * elements. It is only provided as a utility class for the collection
24  * implementations and is not a part of the API.
25  *
26  * @author Søren Bak
27  * @version 1.2 21-08-2003 20:25
28  */

29 public class Display {
30
31     public static String JavaDoc display(boolean v) {
32         return String.valueOf(v);
33     }
34
35     public static String JavaDoc display(byte v) {
36         return String.valueOf(v);
37     }
38
39     public static String JavaDoc display(short v) {
40         return String.valueOf(v);
41     }
42
43     public static String JavaDoc display(int v) {
44         return String.valueOf(v);
45     }
46
47     public static String JavaDoc display(long v) {
48         return String.valueOf(v);
49     }
50
51     public static String JavaDoc display(float v) {
52         return String.valueOf(v);
53     }
54
55     public static String JavaDoc display(double v) {
56         return String.valueOf(v);
57     }
58
59     public static String JavaDoc display(char v) {
60         return "'" + (displayChars.indexOf(v) != -1 ? String.valueOf(v) : hexChar(v)) + "'";
61     }
62
63     private static final String JavaDoc displayChars =
64         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#€%&/()=?\'@£${[]}+|^~*-_.:,;<>\\";
65
66     static String JavaDoc hexChar(char v) {
67         String JavaDoc s = Integer.toHexString(v);
68         switch (s.length()) {
69         case 1: return "\\u000"+s;
70         case 2: return "\\u00"+s;
71         case 3: return "\\u0"+s;
72         case 4: return "\\u"+s;
73         default:
74             throw new RuntimeException JavaDoc("Internal error");
75         }
76     }
77
78 }
Popular Tags