From 8faf7d47095d38eb5ff514519ca02015bcd3f8cf Mon Sep 17 00:00:00 2001 From: "Andrzej J." Date: Mon, 28 Oct 2024 17:33:10 +0100 Subject: [PATCH] Resolves#1169: Used Objects.hash to implement hashCode --- .../mojo/versions/api/ArtifactVersions.java | 9 +++------ .../mojo/versions/api/PluginUpdatesDetails.java | 15 +++++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java index afafaae2f..cbc6d200f 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java @@ -19,13 +19,14 @@ * under the License. */ +import java.util.Arrays; import java.util.Comparator; import java.util.List; +import java.util.Objects; import java.util.SortedSet; import java.util.TreeSet; import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -126,11 +127,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(getArtifact()) - .append(getVersions(true)) - .append(getVersionComparator()) - .toHashCode(); + return Objects.hash(getArtifact(), Arrays.hashCode(getVersions(true)), getVersionComparator()); } /** diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PluginUpdatesDetails.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PluginUpdatesDetails.java index 9eb4d5d3f..e4c3a5964 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PluginUpdatesDetails.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PluginUpdatesDetails.java @@ -19,11 +19,11 @@ * under the License. */ +import java.util.Arrays; import java.util.Comparator; import java.util.Map; import java.util.Objects; -import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; @@ -108,13 +108,12 @@ public boolean equals(Object o) { } public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(getArtifact()) - .append(getVersions(true)) - .append(getVersionComparator()) - .append(includeSnapshots) - .append(dependencyVersions) - .toHashCode(); + return Objects.hash( + getArtifact(), + Arrays.hashCode(getVersions(true)), + getVersionComparator(), + includeSnapshots, + dependencyVersions); } // added an arbitrary comparison just to be able to differentiate objects having different includeSnapshots