1 | package net.sourceforge.retroweaver.runtime.java.lang; |
2 | |
3 | public class Integer_ { |
4 | |
5 | private Integer_() { |
6 | // private constructor |
7 | } |
8 | |
9 | private static Integer[] boxedVals = new Integer[256]; |
10 | |
11 | // Small lookup table for boxed objects |
12 | // |
13 | // The spec says that the range should be from -127 to 128, |
14 | // but a byte's range is from -128 to 127. Neal Gafter seems to imply |
15 | // that this is a bug in the spec. |
16 | static { |
17 | for (int i = 0; i < 256; ++i) { |
18 | byte val = (byte) (i - 128); |
19 | boxedVals[i] = new Integer(val); // NOPMD by xlv |
20 | } |
21 | } |
22 | |
23 | public static Integer valueOf(final int val) { |
24 | if (val > -129 && val < 128) { |
25 | return boxedVals[val + 128]; |
26 | } else { |
27 | return new Integer(val); // NOPMD by xlv |
28 | } |
29 | } |
30 | } |