Merge "Prefer valueOf() to boxed primitive constructors"

This commit is contained in:
Orion Hodson
2022-09-20 07:40:59 +00:00
committed by Gerrit Code Review

View File

@@ -264,29 +264,29 @@ public class TypedProperties extends HashMap<String, Object> {
// Ensure that the type can hold this value, and return. // Ensure that the type can hold this value, and return.
int width = (type >> 8) & 0xff; int width = (type >> 8) & 0xff;
switch (width) { switch (width) {
case 1: case 1:
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
throw new ParseException(st, "8-bit integer constant"); throw new ParseException(st, "8-bit integer constant");
} }
return new Byte((byte)value); return Byte.valueOf((byte) value);
case 2: case 2:
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw new ParseException(st, "16-bit integer constant"); throw new ParseException(st, "16-bit integer constant");
} }
return new Short((short)value); return Short.valueOf((short) value);
case 4: case 4:
if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
throw new ParseException(st, "32-bit integer constant"); throw new ParseException(st, "32-bit integer constant");
} }
return new Integer((int)value); return Integer.valueOf((int) value);
case 8: case 8:
if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) { if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) {
throw new ParseException(st, "64-bit integer constant"); throw new ParseException(st, "64-bit integer constant");
} }
return new Long(value); return Long.valueOf(value);
default: default:
throw new IllegalStateException( throw new IllegalStateException(
"Internal error; unexpected integer type width " + width); "Internal error; unexpected integer type width " + width);
} }
} else if ((type & 0xff) == 'F') { } else if ((type & 0xff) == 'F') {
if (token != StreamTokenizer.TT_WORD) { if (token != StreamTokenizer.TT_WORD) {
@@ -317,10 +317,10 @@ public class TypedProperties extends HashMap<String, Object> {
throw new ParseException(st, "32-bit float constant"); throw new ParseException(st, "32-bit float constant");
} }
} }
return new Float((float)value); return Float.valueOf((float) value);
} else { } else {
// This property is a double; no need to truncate. // This property is a double; no need to truncate.
return new Double(value); return Double.valueOf(value);
} }
} else if (type == TYPE_STRING) { } else if (type == TYPE_STRING) {
// Expect a quoted string or the word "null". // Expect a quoted string or the word "null".