[maven] branch master updated: [refactor] use utility method of Objects to simplify code (#284)

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

[maven] branch master updated: [refactor] use utility method of Objects to simplify code (#284)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d09bc74  [refactor] use utility method of Objects to simplify code (#284)
d09bc74 is described below

commit d09bc7437fe5f77e54e6944c1607871bb087b488
Author: Dezhi Cai <[hidden email]>
AuthorDate: Tue Sep 10 14:22:22 2019 +0800

    [refactor] use utility method of Objects to simplify code (#284)
   
    * [refactor] use utility method of Objects to simplify code
   
    * [refactor] use utility method of Objects to simplify code
---
 .../java/org/apache/maven/artifact/versioning/VersionRange.java    | 7 +++----
 .../apache/maven/artifact/resolver/DebugResolutionListener.java    | 3 ++-
 .../apache/maven/artifact/repository/MavenArtifactRepository.java  | 3 ++-
 .../apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java | 4 +++-
 maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java   | 2 +-
 .../java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java | 3 ++-
 .../src/main/java/org/apache/maven/project/MavenProject.java       | 3 ++-
 .../apache/maven/project/artifact/DefaultMavenMetadataCache.java   | 3 ++-
 .../src/main/java/org/apache/maven/toolchain/DefaultToolchain.java | 5 +++--
 9 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
index c37eabb..af37d18 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
@@ -25,6 +25,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.WeakHashMap;
+import java.util.Objects;
 
 import org.apache.maven.artifact.Artifact;
 
@@ -593,11 +594,9 @@ public class VersionRange
         VersionRange other = (VersionRange) obj;
 
         boolean equals =
-            recommendedVersion == other.recommendedVersion
-                || ( ( recommendedVersion != null ) && recommendedVersion.equals( other.recommendedVersion ) );
+                Objects.equals(recommendedVersion, other.recommendedVersion);
         equals &=
-            restrictions == other.restrictions
-                || ( ( restrictions != null ) && restrictions.equals( other.restrictions ) );
+                Objects.equals(restrictions, other.restrictions);
         return equals;
     }
 
diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java
index 01aa80f..e011760 100644
--- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java
+++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java
@@ -20,6 +20,7 @@ package org.apache.maven.artifact.resolver;
  */
 
 import java.util.HashSet;
+import java.util.Objects;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
@@ -69,7 +70,7 @@ public class DebugResolutionListener
         String omittedVersion = omitted.getVersion();
         String keptVersion = kept.getVersion();
 
-        if ( omittedVersion != null ? !omittedVersion.equals( keptVersion ) : keptVersion != null )
+        if (!Objects.equals(omittedVersion, keptVersion))
         {
             logger.debug( indent + omitted + " (removed - nearer found: " + keptVersion + ")" );
         }
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java
index 76bb604..4c081a1 100644
--- a/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java
+++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java
@@ -22,6 +22,7 @@ package org.apache.maven.artifact.repository;
 import java.io.File;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
@@ -353,7 +354,7 @@ public class MavenArtifactRepository
 
     protected static <T> boolean eq( T s1, T s2 )
     {
-        return s1 != null ? s1.equals( s2 ) : s2 == null;
+        return Objects.equals(s1, s2);
     }
 
     public Authentication getAuthentication()
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java b/maven-core/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java
index 1d131b7..651acb4 100644
--- a/maven-core/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java
+++ b/maven-core/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java
@@ -19,6 +19,8 @@ package org.apache.maven.artifact.resolver.filter;
  * under the License.
  */
 
+import java.util.Objects;
+
 /**
  * Filter to only retain objects in the given artifactScope or better.
  *
@@ -72,7 +74,7 @@ public class ScopeArtifactFilter
 
     private static <T> boolean equals( T str1, T str2 )
     {
-        return str1 != null ? str1.equals( str2 ) : str2 == null;
+        return Objects.equals(str1, str2);
     }
 
 }
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java b/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java
index ccb9a65..ec874c6 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java
@@ -39,7 +39,7 @@ class CacheUtils
     @Deprecated
     public static <T> boolean eq( T s1, T s2 )
     {
-        return s1 != null ? s1.equals( s2 ) : s2 == null;
+        return Objects.equals(s1, s2);
     }
 
     /**
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java
index 1e87998..ba62888 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.ArtifactUtils;
@@ -212,7 +213,7 @@ public class DefaultPluginDescriptorCache
 
         private static <T> boolean eq( T s1, T s2 )
         {
-            return s1 != null ? s1.equals( s2 ) : s2 == null;
+            return Objects.equals(s1, s2);
         }
 
     }
diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
index 75c3348..17bf836 100644
--- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
+++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
@@ -31,6 +31,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.Objects;
 
 import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
@@ -1061,7 +1062,7 @@ public class MavenProject
 
     private static <T> boolean eq( T s1, T s2 )
     {
-        return ( s1 != null ) ? s1.equals( s2 ) : s2 == null;
+        return Objects.equals(s1, s2);
     }
 
     @Override
diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java b/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java
index 056c052..0b9c577 100644
--- a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java
+++ b/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java
@@ -27,6 +27,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.maven.artifact.Artifact;
@@ -201,7 +202,7 @@ public class DefaultMavenMetadataCache
 
     private static <T> boolean eq( T s1, T s2 )
     {
-        return s1 != null ? s1.equals( s2 ) : s2 == null;
+        return Objects.equals(s1, s2);
     }
 
     /**
diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
index 59f5e13..a32f87e 100644
--- a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
+++ b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Objects;
 
 import org.apache.maven.toolchain.model.ToolchainModel;
 import org.codehaus.plexus.logging.Logger;
@@ -137,7 +138,7 @@ public abstract class DefaultToolchain // should have been AbstractToolchain...
 
         DefaultToolchain other = (DefaultToolchain) obj;
 
-        if ( type == null ? other.type != null : !type.equals( other.type ) )
+        if (!Objects.equals(type, other.type))
         {
             return false;
         }
@@ -145,7 +146,7 @@ public abstract class DefaultToolchain // should have been AbstractToolchain...
         Properties thisProvides = this.getModel().getProvides();
         Properties otherProvides = other.getModel().getProvides();
 
-        if ( thisProvides == null ? otherProvides != null : !thisProvides.equals( otherProvides ) )
+        if (!Objects.equals(thisProvides, otherProvides))
         {
             return false;
         }