Skip to content

Commit

Permalink
Use efficient valueOf methods from Java 5, taken from #212.
Browse files Browse the repository at this point in the history
  • Loading branch information
gorky authored and joehni committed Jul 31, 2020
1 parent 4438248 commit 414ab98
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2003, 2004 Joe Walnes.
* Copyright (C) 2006, 2007, 2014, 2018 XStream Committers.
* Copyright (C) 2006, 2007, 2014, 2018, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -42,7 +42,7 @@ public void marshal(final Object source, final HierarchicalStreamWriter writer,
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
final String nullAttribute = reader.getAttribute("null");
if (nullAttribute != null && nullAttribute.equals("true")) {
return new Character('\0');
return Character.valueOf('\0');
} else {
return fromString(reader.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016, 2018 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016, 2018, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -301,19 +301,19 @@ private Object[] createNullArguments(final Class<?>[] parameterTypes) {
final Class<?> type = parameterTypes[i];
if (type.isPrimitive()) {
if (type == byte.class) {
arguments[i] = new Byte((byte)0);
arguments[i] = Byte.valueOf((byte)0);
} else if (type == short.class) {
arguments[i] = new Short((short)0);
arguments[i] = Short.valueOf((short)0);
} else if (type == int.class) {
arguments[i] = new Integer(0);
arguments[i] = Integer.valueOf(0);
} else if (type == long.class) {
arguments[i] = new Long(0);
arguments[i] = Long.valueOf(0);
} else if (type == float.class) {
arguments[i] = new Float(0);
arguments[i] = Float.valueOf(0);
} else if (type == double.class) {
arguments[i] = new Double(0);
arguments[i] = Double.valueOf(0);
} else if (type == char.class) {
arguments[i] = new Character('\0');
arguments[i] = Character.valueOf('\0');
} else {
arguments[i] = Boolean.FALSE;
}
Expand Down
14 changes: 7 additions & 7 deletions xstream/src/java/com/thoughtworks/xstream/core/JVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ static class Test {
final Test t = (Test)provider.newInstance(Test.class);
try {
provider.writeField(t, "o", "object", Test.class);
provider.writeField(t, "c", new Character('c'), Test.class);
provider.writeField(t, "b", new Byte((byte)1), Test.class);
provider.writeField(t, "s", new Short((short)1), Test.class);
provider.writeField(t, "i", new Integer(1), Test.class);
provider.writeField(t, "l", new Long(1), Test.class);
provider.writeField(t, "f", new Float(1), Test.class);
provider.writeField(t, "d", new Double(1), Test.class);
provider.writeField(t, "c", Character.valueOf('c'), Test.class);
provider.writeField(t, "b", Byte.valueOf((byte)1), Test.class);
provider.writeField(t, "s", Short.valueOf((short)1), Test.class);
provider.writeField(t, "i", Integer.valueOf(1), Test.class);
provider.writeField(t, "l", Long.valueOf(1), Test.class);
provider.writeField(t, "f", Float.valueOf(1), Test.class);
provider.writeField(t, "d", Double.valueOf(1), Test.class);
provider.writeField(t, "bool", Boolean.TRUE, Test.class);
test = true;
} catch (final IncompatibleClassChangeError e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2007, 2011, 2014, 2015 XStream Committers.
* Copyright (c) 2006, 2007, 2011, 2014, 2015, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -28,12 +28,12 @@ public final class Primitives {

static {
final Class<?>[][] boxing = new Class[][]{
{Byte.TYPE, Byte.class}, {Character.TYPE, Character.class}, {Short.TYPE, Short.class},
{Integer.TYPE, Integer.class}, {Long.TYPE, Long.class}, {Float.TYPE, Float.class},
{Double.TYPE, Double.class}, {Boolean.TYPE, Boolean.class}, {Void.TYPE, Void.class},};
{Byte.TYPE, Byte.class}, {Character.TYPE, Character.class}, {Short.TYPE, Short.class}, //
{Integer.TYPE, Integer.class}, {Long.TYPE, Long.class}, {Float.TYPE, Float.class}, //
{Double.TYPE, Double.class}, {Boolean.TYPE, Boolean.class}, {Void.TYPE, Void.class}};
final Character[] representingChars = {
new Character('B'), new Character('C'), new Character('S'), new Character('I'), new Character('J'),
new Character('F'), new Character('D'), new Character('Z'), null};
Character.valueOf('B'), Character.valueOf('C'), Character.valueOf('S'), Character.valueOf('I'), //
Character.valueOf('J'), Character.valueOf('F'), Character.valueOf('D'), Character.valueOf('Z'), null};
for (int i = 0; i < boxing.length; i++) {
final Class<?> primitiveType = boxing[i][0];
final Class<?> boxedType = boxing[i][1];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015 XStream Committers.
* Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -85,9 +85,9 @@ public void pushElement(final String name) {
indexMapStack[pointer] = indexMap;
}
if (indexMap.containsKey(name)) {
indexMap.put(name, new Integer(indexMap.get(name).intValue() + 1));
indexMap.put(name, Integer.valueOf(indexMap.get(name).intValue() + 1));
} else {
indexMap.put(name, new Integer(1));
indexMap.put(name, Integer.valueOf(1));
}
pointer++;
currentPath = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2006 Joe Walnes.
* Copyright (C) 2007, 2008, 2014, 2015 XStream Committers.
* Copyright (C) 2007, 2008, 2014, 2015, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -50,7 +50,7 @@ public void add(final int index, final V element) {
for (int i = size; i > to; i--) {
map.put(Integer.valueOf(i + 1), map.get(Integer.valueOf(i)));
}
map.put(new Integer(index), element);
map.put(Integer.valueOf(index), element);
}

private void rangeCheck(final int index) {
Expand Down

0 comments on commit 414ab98

Please sign in to comment.