[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
This commit is contained in:
Dezhi Cai 2019-09-10 14:22:22 +08:00 committed by Olivier Lamy
parent 3eb242c571
commit d09bc7437f
9 changed files with 20 additions and 13 deletions

View File

@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.Objects;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
@ -593,11 +594,9 @@ public class VersionRange
VersionRange other = (VersionRange) obj; VersionRange other = (VersionRange) obj;
boolean equals = boolean equals =
recommendedVersion == other.recommendedVersion Objects.equals(recommendedVersion, other.recommendedVersion);
|| ( ( recommendedVersion != null ) && recommendedVersion.equals( other.recommendedVersion ) );
equals &= equals &=
restrictions == other.restrictions Objects.equals(restrictions, other.restrictions);
|| ( ( restrictions != null ) && restrictions.equals( other.restrictions ) );
return equals; return equals;
} }

View File

@ -20,6 +20,7 @@ package org.apache.maven.artifact.resolver;
*/ */
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
@ -69,7 +70,7 @@ public class DebugResolutionListener
String omittedVersion = omitted.getVersion(); String omittedVersion = omitted.getVersion();
String keptVersion = kept.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 + ")" ); logger.debug( indent + omitted + " (removed - nearer found: " + keptVersion + ")" );
} }

View File

@ -22,6 +22,7 @@ package org.apache.maven.artifact.repository;
import java.io.File; import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
@ -353,7 +354,7 @@ public class MavenArtifactRepository
protected static <T> boolean eq( T s1, T s2 ) 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() public Authentication getAuthentication()

View File

@ -19,6 +19,8 @@ package org.apache.maven.artifact.resolver.filter;
* under the License. * under the License.
*/ */
import java.util.Objects;
/** /**
* Filter to only retain objects in the given artifactScope or better. * 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 ) private static <T> boolean equals( T str1, T str2 )
{ {
return str1 != null ? str1.equals( str2 ) : str2 == null; return Objects.equals(str1, str2);
} }
} }

View File

@ -39,7 +39,7 @@ class CacheUtils
@Deprecated @Deprecated
public static <T> boolean eq( T s1, T s2 ) public static <T> boolean eq( T s1, T s2 )
{ {
return s1 != null ? s1.equals( s2 ) : s2 == null; return Objects.equals(s1, s2);
} }
/** /**

View File

@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.apache.maven.RepositoryUtils; import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.ArtifactUtils;
@ -212,7 +213,7 @@ public class DefaultPluginDescriptorCache
private static <T> boolean eq( T s1, T s2 ) private static <T> boolean eq( T s1, T s2 )
{ {
return s1 != null ? s1.equals( s2 ) : s2 == null; return Objects.equals(s1, s2);
} }
} }

View File

@ -31,6 +31,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.Objects;
import org.apache.maven.RepositoryUtils; import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
@ -1061,7 +1062,7 @@ public class MavenProject
private static <T> boolean eq( T s1, T s2 ) private static <T> boolean eq( T s1, T s2 )
{ {
return ( s1 != null ) ? s1.equals( s2 ) : s2 == null; return Objects.equals(s1, s2);
} }
@Override @Override

View File

@ -27,6 +27,7 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
@ -201,7 +202,7 @@ public class DefaultMavenMetadataCache
private static <T> boolean eq( T s1, T s2 ) private static <T> boolean eq( T s1, T s2 )
{ {
return s1 != null ? s1.equals( s2 ) : s2 == null; return Objects.equals(s1, s2);
} }
/** /**

View File

@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Objects;
import org.apache.maven.toolchain.model.ToolchainModel; import org.apache.maven.toolchain.model.ToolchainModel;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
@ -137,7 +138,7 @@ public abstract class DefaultToolchain // should have been AbstractToolchain...
DefaultToolchain other = (DefaultToolchain) obj; DefaultToolchain other = (DefaultToolchain) obj;
if ( type == null ? other.type != null : !type.equals( other.type ) ) if (!Objects.equals(type, other.type))
{ {
return false; return false;
} }
@ -145,7 +146,7 @@ public abstract class DefaultToolchain // should have been AbstractToolchain...
Properties thisProvides = this.getModel().getProvides(); Properties thisProvides = this.getModel().getProvides();
Properties otherProvides = other.getModel().getProvides(); Properties otherProvides = other.getModel().getProvides();
if ( thisProvides == null ? otherProvides != null : !thisProvides.equals( otherProvides ) ) if (!Objects.equals(thisProvides, otherProvides))
{ {
return false; return false;
} }