Skip to content

Commit 414ab98

Browse files
gorkyjoehni
authored andcommitted
Use efficient valueOf methods from Java 5, taken from #212.
1 parent 4438248 commit 414ab98

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

xstream/src/java/com/thoughtworks/xstream/converters/basic/CharConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2003, 2004 Joe Walnes.
3-
* Copyright (C) 2006, 2007, 2014, 2018 XStream Committers.
3+
* Copyright (C) 2006, 2007, 2014, 2018, 2020 XStream Committers.
44
* All rights reserved.
55
*
66
* The software in this package is published under the terms of the BSD
@@ -42,7 +42,7 @@ public void marshal(final Object source, final HierarchicalStreamWriter writer,
4242
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
4343
final String nullAttribute = reader.getAttribute("null");
4444
if (nullAttribute != null && nullAttribute.equals("true")) {
45-
return new Character('\0');
45+
return Character.valueOf('\0');
4646
} else {
4747
return fromString(reader.getValue());
4848
}

xstream/src/java/com/thoughtworks/xstream/converters/reflection/CGLIBEnhancedConverter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016, 2018 XStream Committers.
2+
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016, 2018, 2020 XStream Committers.
33
* All rights reserved.
44
*
55
* The software in this package is published under the terms of the BSD
@@ -301,19 +301,19 @@ private Object[] createNullArguments(final Class<?>[] parameterTypes) {
301301
final Class<?> type = parameterTypes[i];
302302
if (type.isPrimitive()) {
303303
if (type == byte.class) {
304-
arguments[i] = new Byte((byte)0);
304+
arguments[i] = Byte.valueOf((byte)0);
305305
} else if (type == short.class) {
306-
arguments[i] = new Short((short)0);
306+
arguments[i] = Short.valueOf((short)0);
307307
} else if (type == int.class) {
308-
arguments[i] = new Integer(0);
308+
arguments[i] = Integer.valueOf(0);
309309
} else if (type == long.class) {
310-
arguments[i] = new Long(0);
310+
arguments[i] = Long.valueOf(0);
311311
} else if (type == float.class) {
312-
arguments[i] = new Float(0);
312+
arguments[i] = Float.valueOf(0);
313313
} else if (type == double.class) {
314-
arguments[i] = new Double(0);
314+
arguments[i] = Double.valueOf(0);
315315
} else if (type == char.class) {
316-
arguments[i] = new Character('\0');
316+
arguments[i] = Character.valueOf('\0');
317317
} else {
318318
arguments[i] = Boolean.FALSE;
319319
}

xstream/src/java/com/thoughtworks/xstream/core/JVM.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ static class Test {
119119
final Test t = (Test)provider.newInstance(Test.class);
120120
try {
121121
provider.writeField(t, "o", "object", Test.class);
122-
provider.writeField(t, "c", new Character('c'), Test.class);
123-
provider.writeField(t, "b", new Byte((byte)1), Test.class);
124-
provider.writeField(t, "s", new Short((short)1), Test.class);
125-
provider.writeField(t, "i", new Integer(1), Test.class);
126-
provider.writeField(t, "l", new Long(1), Test.class);
127-
provider.writeField(t, "f", new Float(1), Test.class);
128-
provider.writeField(t, "d", new Double(1), Test.class);
122+
provider.writeField(t, "c", Character.valueOf('c'), Test.class);
123+
provider.writeField(t, "b", Byte.valueOf((byte)1), Test.class);
124+
provider.writeField(t, "s", Short.valueOf((short)1), Test.class);
125+
provider.writeField(t, "i", Integer.valueOf(1), Test.class);
126+
provider.writeField(t, "l", Long.valueOf(1), Test.class);
127+
provider.writeField(t, "f", Float.valueOf(1), Test.class);
128+
provider.writeField(t, "d", Double.valueOf(1), Test.class);
129129
provider.writeField(t, "bool", Boolean.TRUE, Test.class);
130130
test = true;
131131
} catch (final IncompatibleClassChangeError e) {

xstream/src/java/com/thoughtworks/xstream/core/util/Primitives.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2007, 2011, 2014, 2015 XStream Committers.
2+
* Copyright (c) 2006, 2007, 2011, 2014, 2015, 2020 XStream Committers.
33
* All rights reserved.
44
*
55
* The software in this package is published under the terms of the BSD
@@ -28,12 +28,12 @@ public final class Primitives {
2828

2929
static {
3030
final Class<?>[][] boxing = new Class[][]{
31-
{Byte.TYPE, Byte.class}, {Character.TYPE, Character.class}, {Short.TYPE, Short.class},
32-
{Integer.TYPE, Integer.class}, {Long.TYPE, Long.class}, {Float.TYPE, Float.class},
33-
{Double.TYPE, Double.class}, {Boolean.TYPE, Boolean.class}, {Void.TYPE, Void.class},};
31+
{Byte.TYPE, Byte.class}, {Character.TYPE, Character.class}, {Short.TYPE, Short.class}, //
32+
{Integer.TYPE, Integer.class}, {Long.TYPE, Long.class}, {Float.TYPE, Float.class}, //
33+
{Double.TYPE, Double.class}, {Boolean.TYPE, Boolean.class}, {Void.TYPE, Void.class}};
3434
final Character[] representingChars = {
35-
new Character('B'), new Character('C'), new Character('S'), new Character('I'), new Character('J'),
36-
new Character('F'), new Character('D'), new Character('Z'), null};
35+
Character.valueOf('B'), Character.valueOf('C'), Character.valueOf('S'), Character.valueOf('I'), //
36+
Character.valueOf('J'), Character.valueOf('F'), Character.valueOf('D'), Character.valueOf('Z'), null};
3737
for (int i = 0; i < boxing.length; i++) {
3838
final Class<?> primitiveType = boxing[i][0];
3939
final Class<?> boxedType = boxing[i][1];

xstream/src/java/com/thoughtworks/xstream/io/path/PathTracker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
3-
* Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015 XStream Committers.
3+
* Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015, 2020 XStream Committers.
44
* All rights reserved.
55
*
66
* The software in this package is published under the terms of the BSD
@@ -85,9 +85,9 @@ public void pushElement(final String name) {
8585
indexMapStack[pointer] = indexMap;
8686
}
8787
if (indexMap.containsKey(name)) {
88-
indexMap.put(name, new Integer(indexMap.get(name).intValue() + 1));
88+
indexMap.put(name, Integer.valueOf(indexMap.get(name).intValue() + 1));
8989
} else {
90-
indexMap.put(name, new Integer(1));
90+
indexMap.put(name, Integer.valueOf(1));
9191
}
9292
pointer++;
9393
currentPath = null;

xstream/src/java/com/thoughtworks/xstream/persistence/XmlArrayList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2006 Joe Walnes.
3-
* Copyright (C) 2007, 2008, 2014, 2015 XStream Committers.
3+
* Copyright (C) 2007, 2008, 2014, 2015, 2020 XStream Committers.
44
* All rights reserved.
55
*
66
* The software in this package is published under the terms of the BSD
@@ -50,7 +50,7 @@ public void add(final int index, final V element) {
5050
for (int i = size; i > to; i--) {
5151
map.put(Integer.valueOf(i + 1), map.get(Integer.valueOf(i)));
5252
}
53-
map.put(new Integer(index), element);
53+
map.put(Integer.valueOf(index), element);
5454
}
5555

5656
private void rangeCheck(final int index) {

0 commit comments

Comments
 (0)