You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2024/11/26 18:00:02 UTC

(sling-org-apache-sling-feature) branch SLING-12500-optimize-artifactid-equals-hashcode created (now b2ed421)

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

jsedding pushed a change to branch SLING-12500-optimize-artifactid-equals-hashcode
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature.git


      at b2ed421  SLING-12500 - ArtifactId #equals() and #hashCode() should not call #toMvnUrl()

This branch includes the following new commits:

     new b2ed421  SLING-12500 - ArtifactId #equals() and #hashCode() should not call #toMvnUrl()

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(sling-org-apache-sling-feature) 01/01: SLING-12500 - ArtifactId #equals() and #hashCode() should not call #toMvnUrl()

Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jsedding pushed a commit to branch SLING-12500-optimize-artifactid-equals-hashcode
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature.git

commit b2ed421d8d782acbbcc4326518369a57c5e28d8f
Author: Julian Sedding <js...@apache.org>
AuthorDate: Tue Nov 26 09:54:12 2024 +0100

    SLING-12500 - ArtifactId #equals() and #hashCode() should not call #toMvnUrl()
---
 .../java/org/apache/sling/feature/ArtifactId.java     | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/ArtifactId.java b/src/main/java/org/apache/sling/feature/ArtifactId.java
index 3c36c60..b311eb7 100644
--- a/src/main/java/org/apache/sling/feature/ArtifactId.java
+++ b/src/main/java/org/apache/sling/feature/ArtifactId.java
@@ -22,6 +22,7 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 
 import org.osgi.framework.Version;
 
@@ -314,15 +315,10 @@ public class ArtifactId implements Comparable<ArtifactId>, Serializable {
      * @return {@code true} if group id, artifact id, type and classifier equal
      */
     public boolean isSame(final ArtifactId id) {
-        if (this.groupId.equals(id.groupId) && this.artifactId.equals(id.artifactId) && this.type.equals(id.type)) {
-            if (this.classifier == null && id.classifier == null) {
-                return true;
-            }
-            if (this.classifier != null) {
-                return this.classifier.equals(id.classifier);
-            }
-        }
-        return false;
+        return Objects.equals(this.groupId, id.groupId)
+                && Objects.equals(this.artifactId, id.artifactId)
+                && Objects.equals(this.type, id.type)
+                && Objects.equals(this.classifier, id.classifier);
     }
 
     /**
@@ -486,14 +482,15 @@ public class ArtifactId implements Comparable<ArtifactId>, Serializable {
 
     @Override
     public int hashCode() {
-        return toMvnUrl().hashCode();
+        return Objects.hash(groupId, artifactId, version, classifier, type);
     }
 
     @Override
     public boolean equals(Object o) {
         if (o == null) return false;
         if (!(o instanceof ArtifactId)) return false;
-        return toMvnUrl().equals(((ArtifactId) o).toMvnUrl());
+        ArtifactId artifactId = (ArtifactId) o;
+        return Objects.equals(version, artifactId.version) && isSame(artifactId);
     }
 
     @Override