~ubuntu-branches/ubuntu/oneiric/mysql-connector-java/oneiric

« back to all changes in this revision

Viewing changes to src/com/mysql/jdbc/Constants.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2007-11-30 10:34:13 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20071130103413-mxm4lpfrr4fnjbuj
Tags: 5.1.5+dfsg-1
* New upstream release. Closes: #450718.
* Add Homepage field to debian/control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 * 
30
30
 * @author Mark Matthews
31
31
 * 
32
 
 * @version $Id: Constants.java 3726 2005-05-19 15:52:24Z mmatthews $
 
32
 * @version $Id: Constants.java 6433 2007-05-18 18:38:56Z mmatthews $
33
33
 */
34
 
class Constants {
 
34
public class Constants {
35
35
        /**
36
36
         * Avoids allocation of empty byte[] when representing 0-length strings.
37
37
         */
38
38
        public final static byte[] EMPTY_BYTE_ARRAY = new byte[0];
39
39
 
40
40
        /**
 
41
         * I18N'd representation of the abbreviation for "ms"
 
42
         */
 
43
        public final static String MILLIS_I18N = Messages.getString("Milliseconds");
 
44
        
 
45
        public final static byte[] SLASH_STAR_SPACE_AS_BYTES = new byte[] {
 
46
                        (byte) '/', (byte) '*', (byte) ' ' };
 
47
 
 
48
        public final static byte[] SPACE_STAR_SLASH_SPACE_AS_BYTES = new byte[] {
 
49
                        (byte) ' ', (byte) '*', (byte) '/', (byte) ' ' };
 
50
 
 
51
        /*
 
52
         * We're still stuck on JDK-1.4.2, but want the Number.valueOf() methods
 
53
         */
 
54
        private static final Character[] CHARACTER_CACHE = new Character[128];
 
55
 
 
56
        private static final int BYTE_CACHE_OFFSET = 128;
 
57
 
 
58
        private static final Byte[] BYTE_CACHE = new Byte[256];
 
59
 
 
60
        private static final int INTEGER_CACHE_OFFSET = 128;
 
61
 
 
62
        private static final Integer[] INTEGER_CACHE = new Integer[256];
 
63
 
 
64
        private static final int SHORT_CACHE_OFFSET = 128;
 
65
 
 
66
        private static final Short[] SHORT_CACHE = new Short[256];
 
67
 
 
68
        private static final Long[] LONG_CACHE = new Long[256];
 
69
 
 
70
        private static final int LONG_CACHE_OFFSET = 128;
 
71
 
 
72
        static {
 
73
                for (int i = 0; i < CHARACTER_CACHE.length; i++) {
 
74
                        CHARACTER_CACHE[i] = new Character((char) i);
 
75
                }
 
76
 
 
77
                for (int i = 0; i < INTEGER_CACHE.length; i++) {
 
78
                        INTEGER_CACHE[i] = new Integer(i - 128);
 
79
                }
 
80
 
 
81
                for (int i = 0; i < SHORT_CACHE.length; i++) {
 
82
                        SHORT_CACHE[i] = new Short((short) (i - 128));
 
83
                }
 
84
 
 
85
                for (int i = 0; i < LONG_CACHE.length; i++) {
 
86
                        LONG_CACHE[i] = new Long(i - 128);
 
87
                }
 
88
 
 
89
                for (int i = 0; i < BYTE_CACHE.length; i++)
 
90
                        BYTE_CACHE[i] = new Byte((byte) (i - BYTE_CACHE_OFFSET));
 
91
        }
 
92
 
 
93
        /** Same behavior as JDK-1.5's Constants.characterValueOf(int) */
 
94
        
 
95
        public static Character characterValueOf(char c) {
 
96
                if (c <= 127) {
 
97
                        return CHARACTER_CACHE[c];
 
98
                }
 
99
 
 
100
                return new Character(c);
 
101
        }
 
102
 
 
103
        /** Same behavior as JDK-1.5's Byte.valueOf(int) */
 
104
 
 
105
        public static final Byte byteValueOf(byte b) {
 
106
                return BYTE_CACHE[b + BYTE_CACHE_OFFSET];
 
107
        }
 
108
 
 
109
        /** Same behavior as JDK-1.5's Integer.valueOf(int) */
 
110
 
 
111
        public static final Integer integerValueOf(int i) {
 
112
                if (i >= -128 && i <= 127) {
 
113
                        return INTEGER_CACHE[i + INTEGER_CACHE_OFFSET];
 
114
                }
 
115
 
 
116
                return new Integer(i);
 
117
        }
 
118
 
 
119
        /** Same behavior as JDK-1.5's Constants.shortValueOf(int) */
 
120
        
 
121
        public static Short shortValueOf(short s) {
 
122
 
 
123
                if (s >= -128 && s <= 127) {
 
124
                        return SHORT_CACHE[s + SHORT_CACHE_OFFSET];
 
125
                }
 
126
                
 
127
                return new Short(s);
 
128
        }
 
129
 
 
130
        /** Same behavior as JDK-1.5's Long.valueOf(int) */
 
131
        
 
132
        public static final Long longValueOf(long l) {
 
133
                if (l >= -128 && l <= 127) {
 
134
                        return LONG_CACHE[(int) l + LONG_CACHE_OFFSET];
 
135
                }
 
136
 
 
137
                return new Long(l);
 
138
        }
 
139
 
 
140
        /**
41
141
         * Prevents instantiation
42
142
         */
43
143
        private Constants() {