01: /*
02: * Primitive Collections for Java.
03: * Copyright (C) 2002, 2003 S�ren Bak
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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 com.uwyn.rife.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 display(boolean v) {
32: return String.valueOf(v);
33: }
34:
35: public static String display(byte v) {
36: return String.valueOf(v);
37: }
38:
39: public static String display(short v) {
40: return String.valueOf(v);
41: }
42:
43: public static String display(int v) {
44: return String.valueOf(v);
45: }
46:
47: public static String display(long v) {
48: return String.valueOf(v);
49: }
50:
51: public static String display(float v) {
52: return String.valueOf(v);
53: }
54:
55: public static String display(double v) {
56: return String.valueOf(v);
57: }
58:
59: public static String display(char v) {
60: return "'"
61: + (displayChars.indexOf(v) != -1 ? String.valueOf(v)
62: : hexChar(v)) + "'";
63: }
64:
65: private static final String displayChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#�%&/()=?\'@�${[]}+|^~*-_.:,;<>\\";
66:
67: static String hexChar(char v) {
68: String s = Integer.toHexString(v);
69: switch (s.length()) {
70: case 1:
71: return "\\u000" + s;
72: case 2:
73: return "\\u00" + s;
74: case 3:
75: return "\\u0" + s;
76: case 4:
77: return "\\u" + s;
78: default:
79: throw new RuntimeException("Internal error");
80: }
81: }
82:
83: }
|