[groovy] branch master updated: refactor code

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

[groovy] branch master updated: refactor code

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f1a0d19  refactor code
f1a0d19 is described below

commit f1a0d190dd3bc84d5760cd44d5bd051ddca3a31b
Author: mattisonchao <[hidden email]>
AuthorDate: Wed Nov 6 17:04:59 2019 +0800

    refactor code
   
    I refactor some code about new java version and some unnecessary
    objects that I leant from effective java item6.
   
    --Make progress every day!
---
 src/test/groovy/ClosureJavaIntegrationTest.java            | 12 ++++++------
 .../annotations/MyIntegerAnnoTraceASTTransformation.java   |  2 +-
 src/test/groovy/lang/GStringTest.java                      |  4 ++--
 src/test/groovy/lang/GroovyShellTest.java                  |  4 ++--
 src/test/groovy/lang/IntegerNumberRangeTest.java           |  4 ++--
 src/test/groovy/lang/IntegerObjectRangeTest.java           |  4 ++--
 src/test/groovy/util/EvalTest.java                         |  8 ++++----
 .../org/codehaus/groovy/ast/MethodCallExpressionTest.java  |  2 +-
 src/test/org/codehaus/groovy/classgen/ForTest.java         |  6 +++---
 .../classgen/asm/sc/bugs/support/Groovy7365Support.java    |  2 +-
 src/test/org/codehaus/groovy/runtime/DummyBean.java        |  2 +-
 .../org/codehaus/groovy/runtime/InvokeConstructorTest.java |  6 +++---
 .../codehaus/groovy/runtime/InvokeGroovyMethodTest.java    | 14 +++++++-------
 .../codehaus/groovy/runtime/memoize/CommonCacheTest.java   |  4 ++--
 .../groovy/runtime/memoize/ConcurrentCommonCacheTest.java  |  4 ++--
 .../groovy/runtime/memoize/StampedCommonCacheTest.java     |  4 ++--
 .../groovy/tools/rootloadersync/SubclassingInJavaTest.java |  4 ++--
 17 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/src/test/groovy/ClosureJavaIntegrationTest.java b/src/test/groovy/ClosureJavaIntegrationTest.java
index 59b0f4a..a855ff0 100644
--- a/src/test/groovy/ClosureJavaIntegrationTest.java
+++ b/src/test/groovy/ClosureJavaIntegrationTest.java
@@ -48,7 +48,7 @@ import static org.codehaus.groovy.runtime.DefaultGroovyMethods.sort;
  * mind, but these tests illustrate some of the possible ways to use them from Java.
  */
 public class ClosureJavaIntegrationTest extends TestCase {
-    Map<String, Integer> zoo = new LinkedHashMap<String, Integer>();
+    Map<String, Integer> zoo = new LinkedHashMap<>();
     List<String> animals = Arrays.asList("ant", "bear", "camel");
 
     @Override
@@ -64,7 +64,7 @@ public class ClosureJavaIntegrationTest extends TestCase {
     }
 
     public void testEachList() {
-        final List<Integer> result = new ArrayList<Integer>();
+        final List<Integer> result = new ArrayList<>();
         each(animals, new Closure(null) {
             public void doCall(String arg) {
                 result.add(arg.length());
@@ -74,7 +74,7 @@ public class ClosureJavaIntegrationTest extends TestCase {
     }
 
     public void testEachMap() {
-        final List<String> result = new ArrayList<String>();
+        final List<String> result = new ArrayList<>();
         each(zoo, new Closure(null) {
             public void doCall(String k, Integer v) {
                 result.add("k=" + k + ",v=" + v);
@@ -125,7 +125,7 @@ public class ClosureJavaIntegrationTest extends TestCase {
     }
 
     public void testFindAllAndCurry() {
-        Map<String, Integer> expected = new HashMap<String, Integer>(zoo);
+        Map<String, Integer> expected = new HashMap<>(zoo);
         expected.remove("Lions");
         Closure<Boolean> keyBiggerThan = new Closure<Boolean>(null) {
             public Boolean doCall(Map.Entry<String, Integer> e, Integer size) {
@@ -137,7 +137,7 @@ public class ClosureJavaIntegrationTest extends TestCase {
     }
 
     public void testListArithmetic() {
-        List<List> numLists = new ArrayList<List>();
+        List<List> numLists = new ArrayList<>();
         numLists.add(Arrays.asList(1, 2, 3));
         numLists.add(Arrays.asList(10, 20, 30));
         assertEquals(Arrays.asList(6, 60), collect(numLists, new Closure<Integer>(null) {
@@ -180,7 +180,7 @@ public class ClosureJavaIntegrationTest extends TestCase {
     }
 
     public void testTrampoline() {
-        final Reference<Closure<BigInteger>> ref = new Reference<Closure<BigInteger>>();
+        final Reference<Closure<BigInteger>> ref = new Reference<>();
         ref.set(new Closure<BigInteger>(null) {
             public Object doCall(Integer n, BigInteger total) {
                 return n > 1 ? ref.get().trampoline(n - 1, total.multiply(BigInteger.valueOf(n))) : total;
diff --git a/src/test/groovy/annotations/MyIntegerAnnoTraceASTTransformation.java b/src/test/groovy/annotations/MyIntegerAnnoTraceASTTransformation.java
index 3e4996e..aa22376 100644
--- a/src/test/groovy/annotations/MyIntegerAnnoTraceASTTransformation.java
+++ b/src/test/groovy/annotations/MyIntegerAnnoTraceASTTransformation.java
@@ -38,7 +38,7 @@ import java.util.List;
  */
 @GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
 public class MyIntegerAnnoTraceASTTransformation implements ASTTransformation {
-    public static List<String> trace = new ArrayList<String>();
+    public static List<String> trace = new ArrayList<>();
 
     public void visit(ASTNode[] nodes, final SourceUnit source) {
         if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
diff --git a/src/test/groovy/lang/GStringTest.java b/src/test/groovy/lang/GStringTest.java
index 1891bf0..7ef901f 100644
--- a/src/test/groovy/lang/GStringTest.java
+++ b/src/test/groovy/lang/GStringTest.java
@@ -64,8 +64,8 @@ public class GStringTest extends GroovyTestCase {
     }
 
     public void testEqualsAndHashCode() {
-        DummyGString a = new DummyGString(new Object[]{new Integer(1)});
-        DummyGString b = new DummyGString(new Object[]{new Long(1)});
+        DummyGString a = new DummyGString(new Object[]{Integer.valueOf(1)});
+        DummyGString b = new DummyGString(new Object[]{Long.valueOf(1)});
         Comparable c = new DummyGString(new Object[]{new Double(2.3)});
 
         assertTrue("a == b", a.equals(b));
diff --git a/src/test/groovy/lang/GroovyShellTest.java b/src/test/groovy/lang/GroovyShellTest.java
index 65c77ff..d11738e 100644
--- a/src/test/groovy/lang/GroovyShellTest.java
+++ b/src/test/groovy/lang/GroovyShellTest.java
@@ -48,7 +48,7 @@ public class GroovyShellTest extends GroovyTestCase {
         GroovyShell shell = new GroovyShell();
         try {
             Object result = shell.evaluate(script1, "Test.groovy");
-            assertEquals(new Integer(1), result);
+            assertEquals(Integer.valueOf(1), result);
         }
         catch (Exception e) {
             fail(e.toString());
@@ -75,7 +75,7 @@ public class GroovyShellTest extends GroovyTestCase {
         GroovyShell shell = new GroovyShell(context);
         try {
             Object result = shell.evaluate(script2, "Test.groovy");
-            assertEquals(new Integer(2), result);
+            assertEquals(Integer.valueOf(2), result);
         }
         catch (Exception e) {
             fail(e.toString());
diff --git a/src/test/groovy/lang/IntegerNumberRangeTest.java b/src/test/groovy/lang/IntegerNumberRangeTest.java
index a2231bb..0b90797 100644
--- a/src/test/groovy/lang/IntegerNumberRangeTest.java
+++ b/src/test/groovy/lang/IntegerNumberRangeTest.java
@@ -28,7 +28,7 @@ public class IntegerNumberRangeTest extends NumberRangeTestCase {
      */
     @Override
     protected Range createRange(int from, int to) {
-        return new NumberRange(new Integer(from), new Integer(to));
+        return new NumberRange(Integer.valueOf(from), Integer.valueOf(to));
     }
 
     /**
@@ -36,7 +36,7 @@ public class IntegerNumberRangeTest extends NumberRangeTestCase {
      */
     @Override
     protected Comparable createValue(int value) {
-        return new Integer(value);
+        return Integer.valueOf(value);
     }
 
 }
diff --git a/src/test/groovy/lang/IntegerObjectRangeTest.java b/src/test/groovy/lang/IntegerObjectRangeTest.java
index 8bab654..9caf617 100644
--- a/src/test/groovy/lang/IntegerObjectRangeTest.java
+++ b/src/test/groovy/lang/IntegerObjectRangeTest.java
@@ -28,7 +28,7 @@ public class IntegerObjectRangeTest extends NumberRangeTestCase {
      */
     @Override
     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));
     }
 
     /**
@@ -36,7 +36,7 @@ public class IntegerObjectRangeTest extends NumberRangeTestCase {
      */
     @Override
     protected Comparable createValue(int value) {
-        return new Integer(value);
+        return Integer.valueOf(value);
     }
 
 }
diff --git a/src/test/groovy/util/EvalTest.java b/src/test/groovy/util/EvalTest.java
index fb057b3..feb89a1 100644
--- a/src/test/groovy/util/EvalTest.java
+++ b/src/test/groovy/util/EvalTest.java
@@ -31,23 +31,23 @@ public class EvalTest extends TestCase {
     }
 
     public void testMeWithSymbolAndObject() throws CompilationFailedException {
-        Object result = Eval.me("x", new Integer(10), "x");
+        Object result = Eval.me("x", Integer.valueOf(10), "x");
         assertEquals("10", result.toString());
     }
 
     public void testX() throws CompilationFailedException {
-        Object result = Eval.x(new Integer(10), "x");
+        Object result = Eval.x(Integer.valueOf(10), "x");
         assertEquals("10", result.toString());
     }
 
     public void testXY() throws CompilationFailedException {
-        Integer ten = new Integer(10);
+        Integer ten = Integer.valueOf(10);
         Object result = Eval.xy(ten, ten, "x+y");
         assertEquals("20", result.toString());
     }
 
     public void testXYZ() throws CompilationFailedException {
-        Integer ten = new Integer(10);
+        Integer ten = Integer.valueOf(10);
         Object result = Eval.xyz(ten, ten, ten, "x+y+z");
         assertEquals("30", result.toString());
     }
diff --git a/src/test/org/codehaus/groovy/ast/MethodCallExpressionTest.java b/src/test/org/codehaus/groovy/ast/MethodCallExpressionTest.java
index cbd6bab..3d221a7 100644
--- a/src/test/org/codehaus/groovy/ast/MethodCallExpressionTest.java
+++ b/src/test/org/codehaus/groovy/ast/MethodCallExpressionTest.java
@@ -38,7 +38,7 @@ public class MethodCallExpressionTest extends ASTTest {
      */
     private boolean visited;
 
-    private List<String> defaultScriptMethods = new ArrayList<String>();
+    private List<String> defaultScriptMethods = new ArrayList<>();
 
     private ClassCodeVisitorSupport methodCallVisitor = new ClassCodeVisitorSupport() {
 
diff --git a/src/test/org/codehaus/groovy/classgen/ForTest.java b/src/test/org/codehaus/groovy/classgen/ForTest.java
index 165d1a3..c37dbdf 100644
--- a/src/test/org/codehaus/groovy/classgen/ForTest.java
+++ b/src/test/org/codehaus/groovy/classgen/ForTest.java
@@ -44,7 +44,7 @@ public class ForTest extends TestSupport {
         assertTrue("Managed to create bean", bean != null);
 
         System.out.println("################ Now about to invoke a method without looping");
-        Object value = new Integer(10000);
+        Object value = Integer.valueOf(10000);
 
         try {
             InvokerHelper.invokeMethod(bean, "oneParamDemo", new Object[]{value});
@@ -75,7 +75,7 @@ public class ForTest extends TestSupport {
         assertTrue("Managed to create bean", bean != null);
 
         System.out.println("################ Now about to invoke a method with looping");
-        Object[] array = {new Integer(1234), "abc", "def"};
+        Object[] array = {Integer.valueOf(1234), "abc", "def"};
 
         try {
             InvokerHelper.invokeMethod(bean, "iterateDemo", new Object[]{array});
@@ -107,7 +107,7 @@ public class ForTest extends TestSupport {
         assertTrue("Managed to create bean", bean != null);
 
         System.out.println("################ Now about to invoke a method with many parameters");
-        Object[] array = {new Integer(1000 * 1000), "foo-", "bar~"};
+        Object[] array = {Integer.valueOf(1000 * 1000), "foo-", "bar~"};
 
         try {
             InvokerHelper.invokeMethod(bean, "manyParamDemo", array);
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7365Support.java b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7365Support.java
index d7b2437..4d73b8c 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7365Support.java
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7365Support.java
@@ -23,6 +23,6 @@ import java.util.Set;
 
 public class Groovy7365Support<A, B> {
     public Set<String> getStrings() {
-        return new LinkedHashSet<String>();
+        return new LinkedHashSet<>();
     }
 }
diff --git a/src/test/org/codehaus/groovy/runtime/DummyBean.java b/src/test/org/codehaus/groovy/runtime/DummyBean.java
index 80a72f8..32c4219 100644
--- a/src/test/org/codehaus/groovy/runtime/DummyBean.java
+++ b/src/test/org/codehaus/groovy/runtime/DummyBean.java
@@ -29,7 +29,7 @@ import java.util.Map;
  */
 public class DummyBean {
     private String name = "James";
-    private Integer i = new Integer(123);
+    private Integer i = Integer.valueOf(123);
     private Map dynamicProperties = new HashMap();
     private Point point;
     private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
diff --git a/src/test/org/codehaus/groovy/runtime/InvokeConstructorTest.java b/src/test/org/codehaus/groovy/runtime/InvokeConstructorTest.java
index 716d7c3..fda5c3c 100644
--- a/src/test/org/codehaus/groovy/runtime/InvokeConstructorTest.java
+++ b/src/test/org/codehaus/groovy/runtime/InvokeConstructorTest.java
@@ -35,17 +35,17 @@ public class InvokeConstructorTest extends GroovyTestCase {
     }
 
     public void testInvokeConstructorOneParamWhichIsNull() throws Throwable {
-        assertConstructor(new DummyBean("Bob", new Integer(1707)), new Object[]{"Bob", new Integer(1707)});
+        assertConstructor(new DummyBean("Bob", Integer.valueOf(1707)), new Object[]{"Bob", Integer.valueOf(1707)});
     }
 
     public void testConstructorWithGStringCoercion() throws Throwable {
-        GString gstring = new GString(new Object[]{new Integer(123)}) {
+        GString gstring = new GString(new Object[]{Integer.valueOf(123)}) {
             public String[] getStrings() {
                 return new String[]{""};
             }
         };
 
-        Object expected = new Long(gstring.toString());
+        Object expected = Long.valueOf(gstring.toString());
 
         assertConstructor(expected, new Object[]{gstring});
     }
diff --git a/src/test/org/codehaus/groovy/runtime/InvokeGroovyMethodTest.java b/src/test/org/codehaus/groovy/runtime/InvokeGroovyMethodTest.java
index 2f865aa..e022078 100644
--- a/src/test/org/codehaus/groovy/runtime/InvokeGroovyMethodTest.java
+++ b/src/test/org/codehaus/groovy/runtime/InvokeGroovyMethodTest.java
@@ -53,19 +53,19 @@ public class InvokeGroovyMethodTest extends GroovyTestCase {
     }
 
     public void testMatchesWithObject() throws Throwable {
-        assertMatches(new Integer(1), new Integer(1), true);
-        assertMatches(new Integer(1), new Integer(2), false);
+        assertMatches(Integer.valueOf(1), Integer.valueOf(1), true);
+        assertMatches(Integer.valueOf(1), Integer.valueOf(2), false);
     }
 
     public void testMatchesWithClass() throws Throwable {
-        assertMatches(new Integer(1), Integer.class, true);
-        assertMatches(new Integer(1), Number.class, true);
-        assertMatches(new Integer(1), Double.class, false);
+        assertMatches(Integer.valueOf(1), Integer.class, true);
+        assertMatches(Integer.valueOf(1), Number.class, true);
+        assertMatches(Integer.valueOf(1), Double.class, false);
     }
 
     public void testMatchesWithList() throws Throwable {
-        assertMatches(new Integer(1), Arrays.asList(new Object[]{new Integer(2), new Integer(1)}), true);
-        assertMatches(new Integer(1), Arrays.asList(new Object[]{new Integer(2), new Integer(3)}), false);
+        assertMatches(Integer.valueOf(1), Arrays.asList(new Object[]{Integer.valueOf(2), Integer.valueOf(1)}), true);
+        assertMatches(Integer.valueOf(1), Arrays.asList(new Object[]{Integer.valueOf(2), Integer.valueOf(3)}), false);
     }
 
     // Implementation methods
diff --git a/src/test/org/codehaus/groovy/runtime/memoize/CommonCacheTest.java b/src/test/org/codehaus/groovy/runtime/memoize/CommonCacheTest.java
index b7ed91a..2223e54 100644
--- a/src/test/org/codehaus/groovy/runtime/memoize/CommonCacheTest.java
+++ b/src/test/org/codehaus/groovy/runtime/memoize/CommonCacheTest.java
@@ -171,7 +171,7 @@ public class CommonCacheTest {
 
     @Test
     public void testLruCache() {
-        CommonCache<String, String> sc = new CommonCache<String, String>(3);
+        CommonCache<String, String> sc = new CommonCache<>(3);
         sc.put("a", "1");
         sc.put("b", "2");
         sc.put("c", "3");
@@ -185,7 +185,7 @@ public class CommonCacheTest {
 
     @Test
     public void testFifoCache() {
-        CommonCache<String, String> sc = new CommonCache<String, String>(3, 3, EvictableCache.EvictionStrategy.FIFO);
+        CommonCache<String, String> sc = new CommonCache<>(3, 3, EvictableCache.EvictionStrategy.FIFO);
         sc.put("a", "1");
         sc.put("b", "2");
         sc.put("c", "3");
diff --git a/src/test/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCacheTest.java b/src/test/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCacheTest.java
index 97ecadc..efbb054 100644
--- a/src/test/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCacheTest.java
+++ b/src/test/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCacheTest.java
@@ -172,7 +172,7 @@ public class ConcurrentCommonCacheTest {
 
     @Test
     public void testLruCache() {
-        ConcurrentCommonCache<String, String> sc = new ConcurrentCommonCache<String, String>(3);
+        ConcurrentCommonCache<String, String> sc = new ConcurrentCommonCache<>(3);
         sc.put("a", "1");
         sc.put("b", "2");
         sc.put("c", "3");
@@ -186,7 +186,7 @@ public class ConcurrentCommonCacheTest {
 
     @Test
     public void testFifoCache() {
-        ConcurrentCommonCache<String, String> sc = new ConcurrentCommonCache<String, String>(3, 3, EvictableCache.EvictionStrategy.FIFO);
+        ConcurrentCommonCache<String, String> sc = new ConcurrentCommonCache<>(3, 3, EvictableCache.EvictionStrategy.FIFO);
         sc.put("a", "1");
         sc.put("b", "2");
         sc.put("c", "3");
diff --git a/src/test/org/codehaus/groovy/runtime/memoize/StampedCommonCacheTest.java b/src/test/org/codehaus/groovy/runtime/memoize/StampedCommonCacheTest.java
index 072492f..2fc6ff6 100644
--- a/src/test/org/codehaus/groovy/runtime/memoize/StampedCommonCacheTest.java
+++ b/src/test/org/codehaus/groovy/runtime/memoize/StampedCommonCacheTest.java
@@ -172,7 +172,7 @@ public class StampedCommonCacheTest {
 
     @Test
     public void testLruCache() {
-        StampedCommonCache<String, String> sc = new StampedCommonCache<String, String>(3);
+        StampedCommonCache<String, String> sc = new StampedCommonCache<>(3);
         sc.put("a", "1");
         sc.put("b", "2");
         sc.put("c", "3");
@@ -186,7 +186,7 @@ public class StampedCommonCacheTest {
 
     @Test
     public void testFifoCache() {
-        StampedCommonCache<String, String> sc = new StampedCommonCache<String, String>(3, 3, EvictableCache.EvictionStrategy.FIFO);
+        StampedCommonCache<String, String> sc = new StampedCommonCache<>(3, 3, EvictableCache.EvictionStrategy.FIFO);
         sc.put("a", "1");
         sc.put("b", "2");
         sc.put("c", "3");
diff --git a/src/test/org/codehaus/groovy/tools/rootloadersync/SubclassingInJavaTest.java b/src/test/org/codehaus/groovy/tools/rootloadersync/SubclassingInJavaTest.java
index 0001c7e..3276c60 100644
--- a/src/test/org/codehaus/groovy/tools/rootloadersync/SubclassingInJavaTest.java
+++ b/src/test/org/codehaus/groovy/tools/rootloadersync/SubclassingInJavaTest.java
@@ -34,8 +34,8 @@ public class SubclassingInJavaTest {
 
    @Test
    public void testGenericSubclassWithBafflingSymptom() {
-      OtherConcreteGenericJavaSubclass unrelatedInstance = new OtherConcreteGenericJavaSubclass(new HashSet<String>());
-      ConcreteGenericJavaSubclass instance = new ConcreteGenericJavaSubclass(new HashSet<String>());
+      OtherConcreteGenericJavaSubclass unrelatedInstance = new OtherConcreteGenericJavaSubclass(new HashSet<>());
+      ConcreteGenericJavaSubclass instance = new ConcreteGenericJavaSubclass(new HashSet<>());
       instance.addNote("abcd");
    }
 }

Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun