groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 01/03: Refactor code
Date Sat, 02 Nov 2019 14:00:48 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 28f5dee0eaf7585c14cf21d0bff073961c848c91
Author: mattisonchao <mattisonchao@gmail.com>
AuthorDate: Sat Nov 2 10:28:18 2019 +0800

    Refactor code
    
    Refactored some code about new java version.
    --Make a contribution to groovy every day.
    
    (cherry picked from commit 43fb0d01ed72fdd17d07a460948e9be59db25d70)
---
 .../src/main/java/groovy/json/DefaultJsonGenerator.java           | 8 +-------
 .../java/org/apache/groovy/json/internal/CharSequenceValue.java   | 3 ++-
 .../main/java/org/apache/groovy/json/internal/NumberValue.java    | 3 ++-
 .../main/java/org/apache/groovy/nio/extensions/NioExtensions.java | 4 ++--
 .../groovy-test/src/main/java/groovy/test/AllTestSuite.java       | 7 +------
 .../groovy-test/src/main/java/groovy/test/GroovyAssert.java       | 2 +-
 .../groovy-test/src/main/java/groovy/test/GroovyTestCase.java     | 4 ++--
 .../groovy-test/src/main/java/groovy/test/GroovyTestSuite.java    | 7 +------
 8 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java b/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
index 1e530e2..5766843 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
@@ -224,13 +224,7 @@ public class DefaultJsonGenerator implements JsonGenerator {
         } else if (File.class.isAssignableFrom(objectClass)) {
             Map<?, ?> properties = getObjectProperties(object);
             //Clean up all recursive references to File objects
-            Iterator<? extends Map.Entry<?, ?>> iterator = properties.entrySet().iterator();
-            while(iterator.hasNext()) {
-                Map.Entry<?,?> entry = iterator.next();
-                if(entry.getValue() instanceof File) {
-                    iterator.remove();
-                }
-            }
+            properties.entrySet().removeIf(entry -> entry.getValue() instanceof File);
             writeMap(properties, buffer);
         } else {
             Map<?, ?> properties = getObjectProperties(object);
diff --git a/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/CharSequenceValue.java
b/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/CharSequenceValue.java
index 21beccf..cc313ec 100644
--- a/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/CharSequenceValue.java
+++ b/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/CharSequenceValue.java
@@ -24,6 +24,7 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.Objects;
 
 import static org.apache.groovy.json.internal.CharScanner.isInteger;
 import static org.apache.groovy.json.internal.CharScanner.parseIntFromTo;
@@ -157,7 +158,7 @@ public class CharSequenceValue implements Value, CharSequence {
         if (startIndex != value1.startIndex) return false;
         if (!Arrays.equals(buffer, value1.buffer)) return false;
         if (type != value1.type) return false;
-        return value != null ? value.equals(value1.value) : value1.value == null;
+        return Objects.equals(value, value1.value);
 
     }
 
diff --git a/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/NumberValue.java
b/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/NumberValue.java
index d541fbf..036cb0d 100644
--- a/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/NumberValue.java
+++ b/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/NumberValue.java
@@ -24,6 +24,7 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.Objects;
 
 import static java.lang.Boolean.parseBoolean;
 import static org.apache.groovy.json.internal.CharScanner.isInteger;
@@ -132,7 +133,7 @@ public class NumberValue extends java.lang.Number implements Value {
         if (startIndex != value1.startIndex) return false;
         if (!Arrays.equals(buffer, value1.buffer)) return false;
         if (type != value1.type) return false;
-        return value != null ? value.equals(value1.value) : value1.value == null;
+        return Objects.equals(value, value1.value);
 
     }
 
diff --git a/subprojects/groovy-nio/src/main/java/org/apache/groovy/nio/extensions/NioExtensions.java
b/subprojects/groovy-nio/src/main/java/org/apache/groovy/nio/extensions/NioExtensions.java
index 73efae6..733e540 100644
--- a/subprojects/groovy-nio/src/main/java/org/apache/groovy/nio/extensions/NioExtensions.java
+++ b/subprojects/groovy-nio/src/main/java/org/apache/groovy/nio/extensions/NioExtensions.java
@@ -1074,7 +1074,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
      */
     public static void traverse(final Path self, @ClosureParams(value = SimpleType.class,
options = "java.nio.file.Path") final Closure closure)
             throws IOException {
-        traverse(self, new HashMap<String, Object>(), closure);
+        traverse(self, new HashMap<>(), closure);
     }
 
     /**
@@ -1110,7 +1110,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
 
         try (DirectoryStream<Path> stream = Files.newDirectoryStream(self)) {
             final Iterator<Path> itr = stream.iterator();
-            List<Path> files = new LinkedList<Path>();
+            List<Path> files = new LinkedList<>();
             while (itr.hasNext()) {
                 files.add(itr.next());
             }
diff --git a/subprojects/groovy-test/src/main/java/groovy/test/AllTestSuite.java b/subprojects/groovy-test/src/main/java/groovy/test/AllTestSuite.java
index 26f718b..2ec63ac 100644
--- a/subprojects/groovy-test/src/main/java/groovy/test/AllTestSuite.java
+++ b/subprojects/groovy-test/src/main/java/groovy/test/AllTestSuite.java
@@ -79,12 +79,7 @@ public class AllTestSuite extends TestSuite {
     private static final ClassLoader JAVA_LOADER = AllTestSuite.class.getClassLoader();
     private static final GroovyClassLoader GROOVY_LOADER =
             AccessController.doPrivileged(
-                    new PrivilegedAction<GroovyClassLoader>() {
-                        @Override
-                        public GroovyClassLoader run() {
-                            return new GroovyClassLoader(JAVA_LOADER);
-                        }
-                    }
+                    (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(JAVA_LOADER)
             );
 
     private static final String[] EMPTY_ARGS = new String[]{};
diff --git a/subprojects/groovy-test/src/main/java/groovy/test/GroovyAssert.java b/subprojects/groovy-test/src/main/java/groovy/test/GroovyAssert.java
index e0ce566..cb489b9 100644
--- a/subprojects/groovy-test/src/main/java/groovy/test/GroovyAssert.java
+++ b/subprojects/groovy-test/src/main/java/groovy/test/GroovyAssert.java
@@ -230,7 +230,7 @@ public class GroovyAssert extends org.junit.Assert {
     /**
      * NotYetImplemented Implementation
      */
-    private static final ThreadLocal<Boolean> notYetImplementedFlag = new ThreadLocal<Boolean>();
+    private static final ThreadLocal<Boolean> notYetImplementedFlag = new ThreadLocal<>();
 
     /**
      * From JUnit. Finds from the call stack the active running JUnit test case
diff --git a/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestCase.java b/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestCase.java
index b8baf35..3a69f97 100644
--- a/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestCase.java
+++ b/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestCase.java
@@ -114,8 +114,8 @@ public class GroovyTestCase extends TestCase {
      * @param array    the array
      */
     protected void assertContains(char expected, char[] array) {
-        for (int i = 0; i < array.length; ++i) {
-            if (array[i] == expected) {
+        for (char c : array) {
+            if (c == expected) {
                 return;
             }
         }
diff --git a/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestSuite.java b/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestSuite.java
index 0dbe3c3..f7322a8 100644
--- a/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestSuite.java
+++ b/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestSuite.java
@@ -52,12 +52,7 @@ public class GroovyTestSuite extends TestSuite {
 
     protected final GroovyClassLoader loader =
             AccessController.doPrivileged(
-                    new PrivilegedAction<GroovyClassLoader>() {
-                        @Override
-                        public GroovyClassLoader run() {
-                            return new GroovyClassLoader(GroovyTestSuite.class.getClassLoader());
-                        }
-                    }
+                    (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(GroovyTestSuite.class.getClassLoader())
             );
 
     public static void main(String[] args) {


Mime
View raw message