Skip to content

Commit b18624f

Browse files
committed
refactor: Use valueOf() instead of constructor for wrapper classes
1 parent cebb035 commit b18624f

23 files changed

+249
-249
lines changed

subprojects/json-lib-core/src/main/java/org/kordamp/json/JSONArray.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ public static JSONArray fromArray(byte[] array, JsonConfig jsonConfig) {
748748
fireArrayStartEvent(jsonConfig);
749749
JSONArray jsonArray = new JSONArray();
750750
for (int i = 0; i < array.length; i++) {
751-
Number n = JSONUtils.transformNumber(new Byte(array[i]));
751+
Number n = JSONUtils.transformNumber(Byte.valueOf(array[i]));
752752
jsonArray.addValue(n, jsonConfig);
753753
fireElementAddedEvent(i, n, jsonConfig);
754754
}
@@ -782,7 +782,7 @@ public static JSONArray fromArray(char[] array, JsonConfig jsonConfig) {
782782
fireArrayStartEvent(jsonConfig);
783783
JSONArray jsonArray = new JSONArray();
784784
for (int i = 0; i < array.length; i++) {
785-
Character c = new Character(array[i]);
785+
Character c = Character.valueOf(array[i]);
786786
jsonArray.addValue(c, jsonConfig);
787787
fireElementAddedEvent(i, c, jsonConfig);
788788
}
@@ -940,7 +940,7 @@ public static JSONArray fromArray(int[] array, JsonConfig jsonConfig) {
940940
fireArrayStartEvent(jsonConfig);
941941
JSONArray jsonArray = new JSONArray();
942942
for (int i = 0; i < array.length; i++) {
943-
Number n = new Integer(array[i]);
943+
Number n = Integer.valueOf(array[i]);
944944
jsonArray.addValue(n, jsonConfig);
945945
fireElementAddedEvent(i, n, jsonConfig);
946946
}
@@ -974,7 +974,7 @@ public static JSONArray fromArray(long[] array, JsonConfig jsonConfig) {
974974
fireArrayStartEvent(jsonConfig);
975975
JSONArray jsonArray = new JSONArray();
976976
for (int i = 0; i < array.length; i++) {
977-
Number n = JSONUtils.transformNumber(new Long(array[i]));
977+
Number n = JSONUtils.transformNumber(Long.valueOf(array[i]));
978978
jsonArray.addValue(n, jsonConfig);
979979
fireElementAddedEvent(i, n, jsonConfig);
980980
}
@@ -1048,7 +1048,7 @@ public static JSONArray fromArray(short[] array, JsonConfig jsonConfig) {
10481048
fireArrayStartEvent(jsonConfig);
10491049
JSONArray jsonArray = new JSONArray();
10501050
for (int i = 0; i < array.length; i++) {
1051-
Number n = JSONUtils.transformNumber(new Short(array[i]));
1051+
Number n = JSONUtils.transformNumber(Short.valueOf(array[i]));
10521052
jsonArray.addValue(n, jsonConfig);
10531053
fireElementAddedEvent(i, n, jsonConfig);
10541054
}
@@ -1482,7 +1482,7 @@ public JSONArray element(double value) {
14821482
* @return this.
14831483
*/
14841484
public JSONArray element(int value) {
1485-
return element(new Integer(value));
1485+
return element(Integer.valueOf(value));
14861486
}
14871487

14881488
/**
@@ -1562,7 +1562,7 @@ public JSONArray element(int index, Collection value, JsonConfig jsonConfig) {
15621562
* finite.
15631563
*/
15641564
public JSONArray element(int index, double value) {
1565-
return element(index, new Double(value));
1565+
return element(index, Double.valueOf(value));
15661566
}
15671567

15681568
/**
@@ -1578,7 +1578,7 @@ public JSONArray element(int index, double value) {
15781578
* @throws JSONException If the index is negative.
15791579
*/
15801580
public JSONArray element(int index, int value) {
1581-
return element(index, new Integer(value));
1581+
return element(index, Integer.valueOf(value));
15821582
}
15831583

15841584
/**
@@ -1594,7 +1594,7 @@ public JSONArray element(int index, int value) {
15941594
* @throws JSONException If the index is negative.
15951595
*/
15961596
public JSONArray element(int index, long value) {
1597-
return element(index, new Long(value));
1597+
return element(index, Long.valueOf(value));
15981598
}
15991599

16001600
/**

subprojects/json-lib-core/src/main/java/org/kordamp/json/JSONObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ public JSONObject element(String key, Collection value, JsonConfig jsonConfig) {
16011601
*/
16021602
public JSONObject element(String key, double value) {
16031603
verifyIsNull();
1604-
Double d = new Double(value);
1604+
Double d = Double.valueOf(value);
16051605
JSONUtils.testValidity(d);
16061606
return element(key, d);
16071607
}
@@ -1618,7 +1618,7 @@ public JSONObject element(String key, double value) {
16181618
*/
16191619
public JSONObject element(String key, int value) {
16201620
verifyIsNull();
1621-
return element(key, new Integer(value));
1621+
return element(key, Integer.valueOf(value));
16221622
}
16231623

16241624
/**
@@ -1633,7 +1633,7 @@ public JSONObject element(String key, int value) {
16331633
*/
16341634
public JSONObject element(String key, long value) {
16351635
verifyIsNull();
1636-
return element(key, new Long(value));
1636+
return element(key, Long.valueOf(value));
16371637
}
16381638

16391639
/**

subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/DefaultDefaultValueProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public Object getDefaultValue(Class type) {
3232
return new JSONArray();
3333
} else if (JSONUtils.isNumber(type)) {
3434
if (JSONUtils.isDouble(type)) {
35-
return new Double(0);
35+
return Double.valueOf(0);
3636
} else {
37-
return new Integer(0);
37+
return Integer.valueOf(0);
3838
}
3939
} else if (JSONUtils.isBoolean(type)) {
4040
return Boolean.FALSE;

subprojects/json-lib-core/src/main/java/org/kordamp/json/util/JSONBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public JSONBuilder value(boolean b) {
307307
* @throws JSONException If the number is not finite.
308308
*/
309309
public JSONBuilder value(double d) {
310-
return this.value(new Double(d));
310+
return this.value(Double.valueOf(d));
311311
}
312312

313313
/**

subprojects/json-lib-core/src/main/java/org/kordamp/json/util/JSONTokener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,13 @@ public Object nextValue(JsonConfig jsonConfig) {
419419
if (b == '0') {
420420
if (s.length() > 2 && (s.charAt(1) == 'x' || s.charAt(1) == 'X')) {
421421
try {
422-
return new Integer(Integer.parseInt(s.substring(2), 16));
422+
return Integer.valueOf(Integer.parseInt(s.substring(2), 16));
423423
} catch (Exception e) {
424424
/* Ignore the error */
425425
}
426426
} else {
427427
try {
428-
return new Integer(Integer.parseInt(s, 8));
428+
return Integer.valueOf(Integer.parseInt(s, 8));
429429
} catch (Exception e) {
430430
/* Ignore the error */
431431
}

subprojects/json-lib-core/src/main/java/org/kordamp/json/util/JSONUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,15 @@ public static void testValidity(Object o) {
680680
*/
681681
public static Number transformNumber(Number input) {
682682
if (input instanceof Float) {
683-
return new Double(input.toString());
683+
return Double.valueOf(input.toString());
684684
} else if (input instanceof Short) {
685-
return new Integer(input.intValue());
685+
return Integer.valueOf(input.intValue());
686686
} else if (input instanceof Byte) {
687-
return new Integer(input.intValue());
687+
return Integer.valueOf(input.intValue());
688688
} else if (input instanceof Long) {
689-
Long max = new Long(Integer.MAX_VALUE);
689+
Long max = Long.valueOf(Integer.MAX_VALUE);
690690
if (input.longValue() <= max.longValue() && input.longValue() >= Integer.MIN_VALUE) {
691-
return new Integer(input.intValue());
691+
return Integer.valueOf(input.intValue());
692692
}
693693
}
694694

subprojects/json-lib-core/src/site/xdoc/snippets.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@
284284
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( str );
285285
DynaBean bean = (DynaBean) JSONSerializer.toJava( jsonObject );
286286
assertEquals( "JSON", bean.get("string") );
287-
assertEquals( new Integer(1), bean.get("integer") );
288-
assertEquals( new Double(2.0), bean.get("double") );
287+
assertEquals( Integer.valueOf(1), bean.get("integer") );
288+
assertEquals( Double.valueOf(2.0), bean.get("double") );
289289
assertEquals( Boolean.TRUE, bean.get("boolean") );
290290
</textarea>[<a href="#Snippets">Index</a>|<a href="#JSONJava">From JSON to Java</a>]
291291
</subsection>

subprojects/json-lib-core/src/site/xdoc/usage.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
Map map = new HashMap();
7777
map.put( "name", "json" );
7878
map.put( "bool", Boolean.TRUE );
79-
map.put( "int", new Integer(1) );
79+
map.put( "int", Integer.valueOf(1) );
8080
map.put( "arr", new String[]{"a","b"} );
8181
map.put( "func", "function(i){ return this.arr[i]; }" );
8282

@@ -154,7 +154,7 @@
154154
JSONObject jsonObject = JSONObject.fromObject( json );
155155
BeanA bean = (BeanA) JSONObject.toBean( jsonObject, BeanA.class );
156156
assertEquals( jsonObject.get( "bool" ), Boolean.valueOf( bean.isBool() ) );
157-
assertEquals( jsonObject.get( "integer" ), new Integer( bean.getInteger() ) );
157+
assertEquals( jsonObject.get( "integer" ), Integer.valueOf( bean.getInteger() ) );
158158
assertEquals( jsonObject.get( "string" ), bean.getString() );
159159
</textarea>
160160

subprojects/json-lib-core/src/test/java/org/kordamp/json/PropertyConstants.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public final class PropertyConstants {
4646
private static Map values = new HashMap();
4747

4848
static {
49-
values.put(BYTE, new Byte(Byte.MAX_VALUE));
50-
values.put(SHORT, new Short(Short.MAX_VALUE));
51-
values.put(INT, new Integer(Integer.MAX_VALUE));
52-
values.put(LONG, new Long(Long.MAX_VALUE));
53-
values.put(FLOAT, new Float(Float.MAX_VALUE));
54-
values.put(DOUBLE, new Double(Double.MAX_VALUE));
49+
values.put(BYTE, Byte.valueOf(Byte.MAX_VALUE));
50+
values.put(SHORT, Short.valueOf(Short.MAX_VALUE));
51+
values.put(INT, Integer.valueOf(Integer.MAX_VALUE));
52+
values.put(LONG, Long.valueOf(Long.MAX_VALUE));
53+
values.put(FLOAT, Float.valueOf(Float.MAX_VALUE));
54+
values.put(DOUBLE, Double.valueOf(Double.MAX_VALUE));
5555
values.put(BOOLEAN, Boolean.TRUE);
56-
values.put(CHAR, new Character('J'));
56+
values.put(CHAR, Character.valueOf('J'));
5757
values.put(STRING, "json");
5858
values.put(FUNCTION, new JSONFunction("this;"));
5959
values.put(ARRAY, new int[]{1, 2});

0 commit comments

Comments
 (0)