[groovy] branch GROOVY_3_0_X updated: refactor code (closes #1072)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[groovy] branch GROOVY_3_0_X updated: refactor code (closes #1072)

paulk
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 2f2a8c6  refactor code (closes #1072)
2f2a8c6 is described below

commit 2f2a8c651f176c6e4ab055c91fde361ac849b6a9
Author: mattisonchao <[hidden email]>
AuthorDate: Thu Nov 7 09:49:11 2019 +0800

    refactor code (closes #1072)
   
    refactor some code about unnecessary objects
---
 src/test/groovy/lang/LongNumberRangeTest.java      |  6 ++---
 src/test/groovy/lang/LongObjectRangeTest.java      |  6 ++---
 src/test/groovy/lang/MetaClassTest.java            | 12 ++++-----
 src/test/groovy/lang/NumberRangeTestCase.java      |  2 +-
 src/test/groovy/lang/ObjectRangeTest.java          | 30 +++++++++++-----------
 .../codehaus/groovy/runtime/InvokeMethodTest.java  | 26 +++++++++----------
 .../org/codehaus/groovy/runtime/InvokerTest.java   | 16 ++++++------
 .../org/codehaus/groovy/runtime/MethodKeyTest.java |  4 +--
 .../groovy/runtime/MethodRankHelperTest.java       |  2 +-
 .../org/codehaus/groovy/runtime/PropertyTest.java  | 14 +++++-----
 10 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/src/test/groovy/lang/LongNumberRangeTest.java b/src/test/groovy/lang/LongNumberRangeTest.java
index e7dd69b..e2872e7 100644
--- a/src/test/groovy/lang/LongNumberRangeTest.java
+++ b/src/test/groovy/lang/LongNumberRangeTest.java
@@ -28,7 +28,7 @@ public class LongNumberRangeTest extends NumberRangeTestCase {
      */
     @Override
     protected Range createRange(int from, int to) {
-        return new NumberRange(new Long(from), new Long(to));
+        return new NumberRange(Long.valueOf(from), Long.valueOf(to));
     }
 
     /**
@@ -36,11 +36,11 @@ public class LongNumberRangeTest extends NumberRangeTestCase {
      */
     @Override
     protected Comparable createValue(int value) {
-        return new Long(value);
+        return Long.valueOf(value);
     }
 
     public void testSizeWithLongTo() {
-        assertEquals(3, new NumberRange(new Integer(Integer.MAX_VALUE), new Long(Integer.MAX_VALUE + 2L)).size());
+        assertEquals(3, new NumberRange(Integer.valueOf(Integer.MAX_VALUE), Long.valueOf(Integer.MAX_VALUE + 2L)).size());
     }
 
     // GROOVY-4973: Range made-up of from: Integer and to: Long should have 'from' promoted to type Long.
diff --git a/src/test/groovy/lang/LongObjectRangeTest.java b/src/test/groovy/lang/LongObjectRangeTest.java
index 51a7e5e..2cb132c 100644
--- a/src/test/groovy/lang/LongObjectRangeTest.java
+++ b/src/test/groovy/lang/LongObjectRangeTest.java
@@ -28,7 +28,7 @@ public class LongObjectRangeTest extends NumberRangeTestCase {
      */
     @Override
     protected Range createRange(int from, int to) {
-        return new ObjectRange(new Long(from), new Long(to));
+        return new ObjectRange(Long.valueOf(from), Long.valueOf(to));
     }
 
     /**
@@ -36,11 +36,11 @@ public class LongObjectRangeTest extends NumberRangeTestCase {
      */
     @Override
     protected Comparable createValue(int value) {
-        return new Long(value);
+        return Long.valueOf(value);
     }
 
     public void testSizeWithLongTo() {
-        assertEquals(3, new ObjectRange(new Integer(Integer.MAX_VALUE), new Long(Integer.MAX_VALUE + 2L)).size());
+        assertEquals(3, new ObjectRange(Integer.valueOf(Integer.MAX_VALUE), Long.valueOf(Integer.MAX_VALUE + 2L)).size());
     }
 
     // GROOVY-4973: Range made-up of from: Integer and to: Long should have 'from' promoted to type Long.
diff --git a/src/test/groovy/lang/MetaClassTest.java b/src/test/groovy/lang/MetaClassTest.java
index f493fc7..4717fdf 100644
--- a/src/test/groovy/lang/MetaClassTest.java
+++ b/src/test/groovy/lang/MetaClassTest.java
@@ -75,10 +75,10 @@ public class MetaClassTest extends GroovyTestCase {
 
         MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass);
 
-        assertEquals(metaClass.getProperty(dymmyClass, "x"), new Integer(0));
+        assertEquals(metaClass.getProperty(dymmyClass, "x"), Integer.valueOf(0));
         assertEquals(metaClass.getProperty(dymmyClass, "y"), "none");
 
-        metaClass.setProperty(dymmyClass, "x", new Integer(25));
+        metaClass.setProperty(dymmyClass, "x", Integer.valueOf(25));
         assertEquals(dymmyClass.x, 25);
 
         metaClass.setProperty(dymmyClass, "y", "newvalue");
@@ -88,7 +88,7 @@ public class MetaClassTest extends GroovyTestCase {
     public void testSetPropertyWithInt() {
         DymmyClass dymmyClass = new DymmyClass();
         MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass);
-        metaClass.setProperty(dymmyClass, "anInt", new Integer(10));
+        metaClass.setProperty(dymmyClass, "anInt", Integer.valueOf(10));
     }
 
     public void testSetPropertyWithDoubleArray() {
@@ -120,7 +120,7 @@ public class MetaClassTest extends GroovyTestCase {
 
         // test Integer[]
         Integer[] integers = new Integer[]{
-                new Integer(0), new Integer(1), new Integer(2), new Integer(3)
+                Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)
         };
         metaClass.setProperty(dymmyClass, "integers", integers);
         assertEquals(integers, metaClass.getProperty(dymmyClass, "integers"));
@@ -132,8 +132,8 @@ public class MetaClassTest extends GroovyTestCase {
 
         // test list
         ArrayList list = new ArrayList();
-        list.add(new Integer(120));
-        list.add(new Integer(150));
+        list.add(Integer.valueOf(120));
+        list.add(Integer.valueOf(150));
 
         // test int[]
         metaClass.setProperty(dymmyClass, "ints", list);
diff --git a/src/test/groovy/lang/NumberRangeTestCase.java b/src/test/groovy/lang/NumberRangeTestCase.java
index 7e00612..6e07cd3 100644
--- a/src/test/groovy/lang/NumberRangeTestCase.java
+++ b/src/test/groovy/lang/NumberRangeTestCase.java
@@ -98,7 +98,7 @@ public abstract class NumberRangeTestCase extends TestCase {
      * Tests using different classes for 'from' and 'to'.
      */
     public void testDifferentClassesForFromAndTo() {
-        final Integer from = new Integer(1);
+        final Integer from = Integer.valueOf(1);
         final Comparable to = createValue(5);
         final Range range = new ObjectRange(from, to);
 
diff --git a/src/test/groovy/lang/ObjectRangeTest.java b/src/test/groovy/lang/ObjectRangeTest.java
index 39f1361..ba2b2b4 100644
--- a/src/test/groovy/lang/ObjectRangeTest.java
+++ b/src/test/groovy/lang/ObjectRangeTest.java
@@ -114,7 +114,7 @@ public class ObjectRangeTest extends TestCase {
     }
 
     public void testNullForFromOrToIsIllegal() {
-        Comparable dontcare = new Integer(0);
+        Comparable dontcare = Integer.valueOf(0);
         try {
             new ObjectRange((Comparable)null, dontcare);
             fail("Should have thrown IllegalArgumentException");
@@ -214,13 +214,13 @@ public class ObjectRangeTest extends TestCase {
     public void testContains() {
         Range r = createRange(10, 20);
 
-        assertTrue("contains 11", r.contains(new Integer(11)));
-        assertTrue("contains 10", r.contains(new Integer(10)));
-        assertTrue("contains 19", r.contains(new Integer(19)));
-        assertFalse("contains 9", r.contains(new Integer(9)));
-        assertFalse("contains 21", r.contains(new Integer(21)));
-        assertFalse("contains 100", r.contains(new Integer(100)));
-        assertFalse("contains -1", r.contains(new Integer(-1)));
+        assertTrue("contains 11", r.contains(Integer.valueOf(11)));
+        assertTrue("contains 10", r.contains(Integer.valueOf(10)));
+        assertTrue("contains 19", r.contains(Integer.valueOf(19)));
+        assertFalse("contains 9", r.contains(Integer.valueOf(9)));
+        assertFalse("contains 21", r.contains(Integer.valueOf(21)));
+        assertFalse("contains 100", r.contains(Integer.valueOf(100)));
+        assertFalse("contains -1", r.contains(Integer.valueOf(-1)));
 
         r = createRange(new BigDecimal("2.1"), new BigDecimal("10.0"));
 
@@ -234,8 +234,8 @@ public class ObjectRangeTest extends TestCase {
     }
 
     public void testContainsWithLikeNumbers() {
-        Range r = new ObjectRange(new Integer(1), new Short((short)3));
-        assertTrue("contains 2", r.contains(new Integer(2)));
+        Range r = new ObjectRange(Integer.valueOf(1), Short.valueOf((short) 3));
+        assertTrue("contains 2", r.contains(Integer.valueOf(2)));
         r = new ObjectRange(new Float(1.0), new Double(3.0));
         assertTrue("contains 2.0d", r.contains(new Double(2.0)));
         assertTrue("contains 2.0g", r.contains(new BigDecimal(2.0)));
@@ -245,7 +245,7 @@ public class ObjectRangeTest extends TestCase {
     }
 
     public void testContainsWithIncompatibleType() {
-        Range r = new ObjectRange(new Integer(1), new Short((short)3));
+        Range r = new ObjectRange(Integer.valueOf(1), Short.valueOf((short) 3));
         assertFalse("shouldn't contain string", r.contains("String"));
     }
 
@@ -327,14 +327,14 @@ public class ObjectRangeTest extends TestCase {
         int i = 4;
         for (Iterator it = r.iterator(); it.hasNext();) {
             i++;
-            assertEquals("equals to " + i, new Integer(i), (Integer) (it.next()));
+            assertEquals("equals to " + i, Integer.valueOf(i), (Integer) (it.next()));
         }
         assertEquals(11, i);
 
         i = 4;
         for (Iterator it = r.step(1).iterator(); it.hasNext();) {
             i++;
-            assertEquals("equals to " + i, new Integer(i), (Integer) (it.next()));
+            assertEquals("equals to " + i, Integer.valueOf(i), (Integer) (it.next()));
         }
         assertEquals(11, i);
 
@@ -376,7 +376,7 @@ public class ObjectRangeTest extends TestCase {
     }
 
     protected Range createRange(int from, int to) {
-        return new ObjectRange(new Integer(from), new Integer(to));
+        return new ObjectRange(Integer.valueOf(from), Integer.valueOf(to));
     }
 
     protected Range createRange(Comparable from, Comparable to) {
@@ -384,7 +384,7 @@ public class ObjectRangeTest extends TestCase {
     }
 
     protected void assertEquals(String msg, int expected, Object value) {
-        assertEquals(msg, new Integer(expected), value);
+        assertEquals(msg, Integer.valueOf(expected), value);
     }
 
 }
diff --git a/src/test/org/codehaus/groovy/runtime/InvokeMethodTest.java b/src/test/org/codehaus/groovy/runtime/InvokeMethodTest.java
index 60cd460..3b91f3a 100644
--- a/src/test/org/codehaus/groovy/runtime/InvokeMethodTest.java
+++ b/src/test/org/codehaus/groovy/runtime/InvokeMethodTest.java
@@ -68,13 +68,13 @@ public class InvokeMethodTest extends GroovyTestCase {
         Object[] foo = {"a", "b", "c"};
 
         Object value = invoke(this, "mockCallWithOneCollectionParam", new Object[]{foo});
-        assertEquals("return value", new Integer(3), value);
+        assertEquals("return value", Integer.valueOf(3), value);
 
         List list = new ArrayList();
         list.add("a");
         list.add("b");
         value = invoke(this, "mockCallWithOneCollectionParam", list);
-        assertEquals("return value", new Integer(2), value);
+        assertEquals("return value", Integer.valueOf(2), value);
     }
 
     public void testInvokePrintlnMethod() throws Throwable {
@@ -103,7 +103,7 @@ public class InvokeMethodTest extends GroovyTestCase {
     }
 
     public void testMethodChooserNumber() throws Throwable {
-        assertMethodChooser("Number", new Integer(2));
+        assertMethodChooser("Number", Integer.valueOf(2));
         assertMethodChooser("Number", new Double(2));
     }
 
@@ -133,7 +133,7 @@ public class InvokeMethodTest extends GroovyTestCase {
         Object list = InvokerHelper.createList(new Object[]{"a", "b"});
 
         Object value = invoke(list, "size", null);
-        assertEquals("size of collection", new Integer(2), value);
+        assertEquals("size of collection", Integer.valueOf(2), value);
 
         value = invoke(list, "contains", "a");
         assertEquals("contains method", Boolean.TRUE, value);
@@ -141,7 +141,7 @@ public class InvokeMethodTest extends GroovyTestCase {
 
     public void testNewMethods() throws Throwable {
         Object value = invoke("hello", "size", null);
-        assertEquals("size of string", new Integer(5), value);
+        assertEquals("size of string", Integer.valueOf(5), value);
     }
 
     public void testStaticMethod() throws Throwable {
@@ -159,9 +159,9 @@ public class InvokeMethodTest extends GroovyTestCase {
     //Integer/Integer division.
     public void testDivideNumbers() throws Throwable {
         assertMethodCall(new Double(10), "div", new Double(2), new Double(5));
-        assertMethodCall(new Double(10), "div", new Integer(2), new Double(5));
-        assertMethodCall(new Integer(10), "div", new Double(2), new Double(5));
-        assertMethodCall(new Integer(10), "div", new Integer(2), new java.math.BigDecimal("5"));
+        assertMethodCall(new Double(10), "div", Integer.valueOf(2), new Double(5));
+        assertMethodCall(Integer.valueOf(10), "div", new Double(2), new Double(5));
+        assertMethodCall(Integer.valueOf(10), "div", Integer.valueOf(2), new java.math.BigDecimal("5"));
     }
 
     public void testBaseFailMethod() throws Throwable {
@@ -202,7 +202,7 @@ public class InvokeMethodTest extends GroovyTestCase {
     }
 
     public void testCallIntMethodWithInteger() throws Throwable {
-        Object value = invoke(this, "overloadedRemove", new Object[]{new Integer(5)});
+        Object value = invoke(this, "overloadedRemove", new Object[]{Integer.valueOf(5)});
         assertEquals("called with integer", "int5", value);
     }
 
@@ -211,7 +211,7 @@ public class InvokeMethodTest extends GroovyTestCase {
         list.add("foo");
         list.add("bar");
 
-        invoke(list, "remove", new Object[]{new Integer(0)});
+        invoke(list, "remove", new Object[]{Integer.valueOf(0)});
 
         assertEquals("Should have just 1 item left: " + list, 1, list.size());
     }
@@ -270,10 +270,10 @@ public class InvokeMethodTest extends GroovyTestCase {
 
     public void testStringSubstringMethod() throws Throwable {
         String object = "hello";
-        Object value = invoke(object, "substring", new Integer(2));
+        Object value = invoke(object, "substring", Integer.valueOf(2));
         assertEquals("substring(2)", object.substring(2), value);
 
-        value = invoke(object, "substring", new Object[]{new Integer(1), new Integer(3)});
+        value = invoke(object, "substring", new Object[]{Integer.valueOf(1), Integer.valueOf(3)});
         assertEquals("substring(1,3)", object.substring(1, 3), value);
     }
 
@@ -343,7 +343,7 @@ public class InvokeMethodTest extends GroovyTestCase {
 
     public Integer mockCallWithOneCollectionParam(Object collection) {
         Collection coll = DefaultTypeTransformation.asCollection(collection);
-        return new Integer(coll.size());
+        return Integer.valueOf(coll.size());
     }
 
     public Object mockOverloadedMethod() {
diff --git a/src/test/org/codehaus/groovy/runtime/InvokerTest.java b/src/test/org/codehaus/groovy/runtime/InvokerTest.java
index 354fba4..828d42b 100644
--- a/src/test/org/codehaus/groovy/runtime/InvokerTest.java
+++ b/src/test/org/codehaus/groovy/runtime/InvokerTest.java
@@ -83,29 +83,29 @@ public class InvokerTest extends GroovyTestCase {
             }
         };
         assertAsBoolean(true, nonEmptyGString);
-        assertAsBoolean(true, new Integer(1234));
-        assertAsBoolean(false, new Integer(0));
+        assertAsBoolean(true, Integer.valueOf(1234));
+        assertAsBoolean(false, Integer.valueOf(0));
         assertAsBoolean(true, new Float(0.3f));
         assertAsBoolean(true, new Double(3.0f));
         assertAsBoolean(false, new Float(0.0f));
         assertAsBoolean(true, new Character((char) 1));
         assertAsBoolean(false, new Character((char) 0));
         assertAsBoolean(false, Collections.EMPTY_LIST);
-        assertAsBoolean(true, Arrays.asList(new Integer[]{new Integer(1)}));
+        assertAsBoolean(true, Arrays.asList(new Integer[]{Integer.valueOf(1)}));
     }
 
     public void testLessThan() {
-        assertTrue(ScriptBytecodeAdapter.compareLessThan(new Integer(1), new Integer(2)));
-        assertTrue(ScriptBytecodeAdapter.compareLessThanEqual(new Integer(2), new Integer(2)));
+        assertTrue(ScriptBytecodeAdapter.compareLessThan(Integer.valueOf(1), Integer.valueOf(2)));
+        assertTrue(ScriptBytecodeAdapter.compareLessThanEqual(Integer.valueOf(2), Integer.valueOf(2)));
     }
 
     public void testGreaterThan() {
-        assertTrue(ScriptBytecodeAdapter.compareGreaterThan(new Integer(3), new Integer(2)));
-        assertTrue(ScriptBytecodeAdapter.compareGreaterThanEqual(new Integer(2), new Integer(2)));
+        assertTrue(ScriptBytecodeAdapter.compareGreaterThan(Integer.valueOf(3), Integer.valueOf(2)));
+        assertTrue(ScriptBytecodeAdapter.compareGreaterThanEqual(Integer.valueOf(2), Integer.valueOf(2)));
     }
 
     public void testCompareTo() {
-        assertTrue(DefaultTypeTransformation.compareEqual("x", new Integer('x')));
+        assertTrue(DefaultTypeTransformation.compareEqual("x", Integer.valueOf('x')));
     }
 
     // Implementation methods
diff --git a/src/test/org/codehaus/groovy/runtime/MethodKeyTest.java b/src/test/org/codehaus/groovy/runtime/MethodKeyTest.java
index f38d6b1..4a5813f 100644
--- a/src/test/org/codehaus/groovy/runtime/MethodKeyTest.java
+++ b/src/test/org/codehaus/groovy/runtime/MethodKeyTest.java
@@ -40,9 +40,9 @@ public class MethodKeyTest extends TestCase {
 
     public void testTemporaryImplementation() throws Exception {
         MethodKey a = new DefaultMethodKey(Object.class, "foo", new Class[]{Object.class, Integer.class}, false);
-        MethodKey a2 = new TemporaryMethodKey(Object.class, "foo", new Object[]{new Object(), new Integer(1)}, false);
+        MethodKey a2 = new TemporaryMethodKey(Object.class, "foo", new Object[]{new Object(), Integer.valueOf(1)}, false);
         MethodKey b = new TemporaryMethodKey(Object.class, "foo", new Object[]{new Object()}, false);
-        MethodKey c = new TemporaryMethodKey(Object.class, "bar", new Object[]{new Object(), new Integer(1)}, false);
+        MethodKey c = new TemporaryMethodKey(Object.class, "bar", new Object[]{new Object(), Integer.valueOf(1)}, false);
 
         assertCompare(a, a, true);
         assertCompare(a, a2, true);
diff --git a/src/test/org/codehaus/groovy/runtime/MethodRankHelperTest.java b/src/test/org/codehaus/groovy/runtime/MethodRankHelperTest.java
index ee24f97..e1722f8 100644
--- a/src/test/org/codehaus/groovy/runtime/MethodRankHelperTest.java
+++ b/src/test/org/codehaus/groovy/runtime/MethodRankHelperTest.java
@@ -81,7 +81,7 @@ public class MethodRankHelperTest extends TestCase {
     private Integer[] box(int[] ia) {
         Integer[] ret = new Integer[ia.length];
         for (int i = 0; i < ia.length; i++) {
-            ret[i] = new Integer(ia[i]);
+            ret[i] = Integer.valueOf(ia[i]);
         }
         return ret;
     }
diff --git a/src/test/org/codehaus/groovy/runtime/PropertyTest.java b/src/test/org/codehaus/groovy/runtime/PropertyTest.java
index f812f42..50df512 100644
--- a/src/test/org/codehaus/groovy/runtime/PropertyTest.java
+++ b/src/test/org/codehaus/groovy/runtime/PropertyTest.java
@@ -38,17 +38,17 @@ public class PropertyTest extends GroovyTestCase {
     public void testMapProperties() throws Exception {
         Map map = new HashMap();
         map.put("foo", "abc");
-        map.put("bar", new Integer(123));
+        map.put("bar", Integer.valueOf(123));
 
         assertGetSetProperty(map, "foo", "abc", "def");
-        assertGetSetProperty(map, "bar", new Integer(123), new Double(12.34));
+        assertGetSetProperty(map, "bar", Integer.valueOf(123), new Double(12.34));
     }
 
     public void testBeanProperties() throws Exception {
         DummyBean bean = new DummyBean();
 
         assertGetSetProperty(bean, "name", "James", "Bob");
-        assertGetSetProperty(bean, "i", new Integer(123), new Integer(455));
+        assertGetSetProperty(bean, "i", Integer.valueOf(123), Integer.valueOf(455));
 
         // dynamic properties
         assertGetSetProperty(bean, "dynamicFoo", null, "aValue");
@@ -82,8 +82,8 @@ public class PropertyTest extends GroovyTestCase {
     public void testListCoercionProperty() throws Exception {
         DummyBean bean = new DummyBean();
         List list = new ArrayList();
-        list.add(new Integer(10));
-        list.add(new Integer(20));
+        list.add(Integer.valueOf(10));
+        list.add(Integer.valueOf(20));
 
         InvokerHelper.setProperty(bean, "point", list);
         assertEquals("Should have set a point", new Point(10, 20), bean.getPoint());
@@ -95,8 +95,8 @@ public class PropertyTest extends GroovyTestCase {
         try {
             JFrame bean = new JFrame();
             List list = new ArrayList();
-            list.add(new Integer(10));
-            list.add(new Integer(20));
+            list.add(Integer.valueOf(10));
+            list.add(Integer.valueOf(20));
 
             InvokerHelper.setProperty(bean, "location", list);
             assertEquals("Should have set a point", new Point(10, 20), bean.getLocation());