groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 02/02: Trivial refactoring: Simplify code by `Objects.equals()`
Date Fri, 05 Apr 2019 19:24:35 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit f510eba804b1fefb56f97afcc0418b4d6429b8ff
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Sat Apr 6 02:26:38 2019 +0800

    Trivial refactoring: Simplify code by `Objects.equals()`
    
    (cherry picked from commit 9833db6c25de2284d9470fadb190ab362c5644a5)
---
 src/main/groovy/groovy/util/ProxyGenerator.java                    | 7 ++++---
 src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java | 3 ++-
 .../java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java     | 3 ++-
 .../groovy/runtime/typehandling/DefaultTypeTransformation.java     | 3 ++-
 .../org/codehaus/groovy/transform/stc/SecondPassExpression.java    | 4 +++-
 5 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/main/groovy/groovy/util/ProxyGenerator.java b/src/main/groovy/groovy/util/ProxyGenerator.java
index 22fa9b3..1aa79fc 100644
--- a/src/main/groovy/groovy/util/ProxyGenerator.java
+++ b/src/main/groovy/groovy/util/ProxyGenerator.java
@@ -39,6 +39,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 
 /**
@@ -287,10 +288,10 @@ public class ProxyGenerator {
 
             if (emptyMethods != cacheKey.emptyMethods) return false;
             if (useDelegate != cacheKey.useDelegate) return false;
-            if (baseClass != null ? !baseClass.equals(cacheKey.baseClass) : cacheKey.baseClass
!= null) return false;
-            if (delegateClass != null ? !delegateClass.equals(cacheKey.delegateClass) : cacheKey.delegateClass
!= null) return false;
+            if (!Objects.equals(baseClass, cacheKey.baseClass)) return false;
+            if (!Objects.equals(delegateClass, cacheKey.delegateClass)) return false;
             if (!Arrays.equals(interfaces, cacheKey.interfaces)) return false;
-            if (methods != null ? !methods.equals(cacheKey.methods) : cacheKey.methods !=
null) return false;
+            if (!Objects.equals(methods, cacheKey.methods)) return false;
 
             return true;
         }
diff --git a/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java b/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
index 5cfacb0..6d8667a 100644
--- a/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
+++ b/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
@@ -38,6 +38,7 @@ import org.codehaus.groovy.util.ReferenceBundle;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 public class MixinInMetaClass extends ManagedConcurrentMap {
     final ExpandoMetaClass emc;
@@ -199,7 +200,7 @@ public class MixinInMetaClass extends ManagedConcurrentMap {
 
         MixinInMetaClass that = (MixinInMetaClass) o;
 
-        if (mixinClass != null ? !mixinClass.equals(that.mixinClass) : that.mixinClass !=
null) return false;
+        if (!Objects.equals(mixinClass, that.mixinClass)) return false;
 
         return true;
     }
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index b2ac0f7..6e5d1e8 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -153,6 +153,7 @@ import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.NoSuchElementException;
+import java.util.Objects;
 import java.util.Queue;
 import java.util.Set;
 import java.util.SortedMap;
@@ -4940,7 +4941,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
      */
     public static boolean contains(Iterable self, Object item) {
         for (Object e : self) {
-            if (item == null ? e == null : item.equals(e)) {
+            if (Objects.equals(item, e)) {
                 return true;
             }
         }
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
index 320a2ed..3f974e9 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
@@ -48,6 +48,7 @@ import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * Class providing various type conversions, coercions and boxing/unboxing operations.
@@ -641,7 +642,7 @@ public class DefaultTypeTransformation {
         if (left instanceof Map.Entry && right instanceof Map.Entry) {
             Object k1 = ((Map.Entry) left).getKey();
             Object k2 = ((Map.Entry) right).getKey();
-            if (k1 == k2 || (k1 != null && k1.equals(k2))) {
+            if (Objects.equals(k1, k2)) {
                 Object v1 = ((Map.Entry) left).getValue();
                 Object v2 = ((Map.Entry) right).getValue();
                 if (v1 == v2 || (v1 != null && DefaultTypeTransformation.compareEqual(v1,
v2)))
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/SecondPassExpression.java b/src/main/java/org/codehaus/groovy/transform/stc/SecondPassExpression.java
index cde11a3..aafe263 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/SecondPassExpression.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/SecondPassExpression.java
@@ -20,6 +20,8 @@ package org.codehaus.groovy.transform.stc;
 
 import org.codehaus.groovy.ast.expr.Expression;
 
+import java.util.Objects;
+
 /**
  * An utility class used to wrap an expression with additional metadata used by the type
checker.
  * In particular, this is used to detect closure shared variables misuses. We need in some
circumstances
@@ -54,7 +56,7 @@ class SecondPassExpression<T> {
 
         final SecondPassExpression that = (SecondPassExpression) o;
 
-        if (data != null ? !data.equals(that.data) : that.data != null) return false;
+        if (!Objects.equals(data, that.data)) return false;
         if (!expression.equals(that.expression)) return false;
 
         return true;


Mime
View raw message