Skip to content

Commit

Permalink
Resolves#1169: Used Objects.hash to implement hashCode
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Oct 28, 2024
1 parent 79e1f2a commit 8faf7d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8faf7d4

Please sign in to comment.