Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] use utility method of Objects to simplify code #284

Merged
merged 2 commits into from Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.Objects;

import org.apache.maven.artifact.Artifact;

Expand Down Expand Up @@ -593,11 +594,9 @@ public boolean equals( Object obj )
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;
}

Expand Down
Expand Up @@ -20,6 +20,7 @@
*/

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void omitForNearer( Artifact omitted, Artifact kept )
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 + ")" );
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -353,7 +354,7 @@ public boolean equals( Object obj )

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()
Expand Down
Expand Up @@ -19,6 +19,8 @@
* under the License.
*/

import java.util.Objects;

/**
* Filter to only retain objects in the given artifactScope or better.
*
Expand Down Expand Up @@ -72,7 +74,7 @@ public boolean equals( Object obj )

private static <T> boolean equals( T str1, T str2 )
{
return str1 != null ? str1.equals( str2 ) : str2 == null;
return Objects.equals(str1, str2);
}

}
Expand Up @@ -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);
}

/**
Expand Down
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -212,7 +213,7 @@ private static int hash( Object obj )

private static <T> boolean eq( T s1, T s2 )
{
return s1 != null ? s1.equals( s2 ) : s2 == null;
return Objects.equals(s1, s2);
}

}
Expand Down
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -1061,7 +1062,7 @@ else if ( !( other instanceof MavenProject ) )

private static <T> boolean eq( T s1, T s2 )
{
return ( s1 != null ) ? s1.equals( s2 ) : s2 == null;
return Objects.equals(s1, s2);
}

@Override
Expand Down
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -201,7 +202,7 @@ private static boolean repositoriesEquals( List<ArtifactRepository> r1, List<Art

private static <T> boolean eq( T s1, T s2 )
{
return s1 != null ? s1.equals( s2 ) : s2 == null;
return Objects.equals(s1, s2);
}

/**
Expand Down
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -137,15 +138,15 @@ public boolean equals( Object obj )

DefaultToolchain other = (DefaultToolchain) obj;

if ( type == null ? other.type != null : !type.equals( other.type ) )
if (!Objects.equals(type, other.type))
{
return false;
}

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;
}
Expand Down