+ public static final Number N(String s) { return s.indexOf('.') == -1 ? N(Integer.parseInt(s)) : new Double(s); }
+ public static final Number N(double d) { return (int)d == d ? N((int)d) : new Double(d); }
+ public static final Number N(long l) { return N((int)l); }
+
+ private static final Integer[] smallIntCache = new Integer[65535 / 4];
+ private static final Integer[] largeIntCache = new Integer[65535 / 4];
+ public static final Number N(int i) {
+ Integer ret = null;
+ int idx = i + smallIntCache.length / 2;
+ if (idx < smallIntCache.length && idx > 0) {
+ ret = smallIntCache[idx];
+ if (ret != null) return ret;
+ }
+ else ret = largeIntCache[Math.abs(idx % largeIntCache.length)];
+ if (ret == null || ret.intValue() != i) {
+ ret = new Integer(i);
+ if (idx < smallIntCache.length && idx > 0) smallIntCache[idx] = ret;
+ else largeIntCache[Math.abs(idx % largeIntCache.length)] = ret;
+ }
+ return ret;
+ }