30
30
* @author Mark Matthews
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 $
34
public class Constants {
36
36
* Avoids allocation of empty byte[] when representing 0-length strings.
38
38
public final static byte[] EMPTY_BYTE_ARRAY = new byte[0];
41
* I18N'd representation of the abbreviation for "ms"
43
public final static String MILLIS_I18N = Messages.getString("Milliseconds");
45
public final static byte[] SLASH_STAR_SPACE_AS_BYTES = new byte[] {
46
(byte) '/', (byte) '*', (byte) ' ' };
48
public final static byte[] SPACE_STAR_SLASH_SPACE_AS_BYTES = new byte[] {
49
(byte) ' ', (byte) '*', (byte) '/', (byte) ' ' };
52
* We're still stuck on JDK-1.4.2, but want the Number.valueOf() methods
54
private static final Character[] CHARACTER_CACHE = new Character[128];
56
private static final int BYTE_CACHE_OFFSET = 128;
58
private static final Byte[] BYTE_CACHE = new Byte[256];
60
private static final int INTEGER_CACHE_OFFSET = 128;
62
private static final Integer[] INTEGER_CACHE = new Integer[256];
64
private static final int SHORT_CACHE_OFFSET = 128;
66
private static final Short[] SHORT_CACHE = new Short[256];
68
private static final Long[] LONG_CACHE = new Long[256];
70
private static final int LONG_CACHE_OFFSET = 128;
73
for (int i = 0; i < CHARACTER_CACHE.length; i++) {
74
CHARACTER_CACHE[i] = new Character((char) i);
77
for (int i = 0; i < INTEGER_CACHE.length; i++) {
78
INTEGER_CACHE[i] = new Integer(i - 128);
81
for (int i = 0; i < SHORT_CACHE.length; i++) {
82
SHORT_CACHE[i] = new Short((short) (i - 128));
85
for (int i = 0; i < LONG_CACHE.length; i++) {
86
LONG_CACHE[i] = new Long(i - 128);
89
for (int i = 0; i < BYTE_CACHE.length; i++)
90
BYTE_CACHE[i] = new Byte((byte) (i - BYTE_CACHE_OFFSET));
93
/** Same behavior as JDK-1.5's Constants.characterValueOf(int) */
95
public static Character characterValueOf(char c) {
97
return CHARACTER_CACHE[c];
100
return new Character(c);
103
/** Same behavior as JDK-1.5's Byte.valueOf(int) */
105
public static final Byte byteValueOf(byte b) {
106
return BYTE_CACHE[b + BYTE_CACHE_OFFSET];
109
/** Same behavior as JDK-1.5's Integer.valueOf(int) */
111
public static final Integer integerValueOf(int i) {
112
if (i >= -128 && i <= 127) {
113
return INTEGER_CACHE[i + INTEGER_CACHE_OFFSET];
116
return new Integer(i);
119
/** Same behavior as JDK-1.5's Constants.shortValueOf(int) */
121
public static Short shortValueOf(short s) {
123
if (s >= -128 && s <= 127) {
124
return SHORT_CACHE[s + SHORT_CACHE_OFFSET];
130
/** Same behavior as JDK-1.5's Long.valueOf(int) */
132
public static final Long longValueOf(long l) {
133
if (l >= -128 && l <= 127) {
134
return LONG_CACHE[(int) l + LONG_CACHE_OFFSET];
41
141
* Prevents instantiation
43
143
private Constants() {