From 0c8fb1fd7c0c94c1572b8c339440595b953cf761 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Wed, 10 Jun 2020 18:19:34 -0300 Subject: [PATCH] Refactor AppArtifactCoords This adds a AppArtifactCoords(AppArtifactKey key, String version) constructor and simplifies the equals/hashCode method implementation --- .../bootstrap/model/AppArtifactCoords.java | 70 +++++++------------ 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppArtifactCoords.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppArtifactCoords.java index d27aa8730845a..59dd0c443a059 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppArtifactCoords.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppArtifactCoords.java @@ -1,6 +1,7 @@ package io.quarkus.bootstrap.model; import java.io.Serializable; +import java.util.Objects; /** * GroupId, artifactId, classifier, type, version @@ -42,6 +43,15 @@ protected AppArtifactCoords(String[] parts) { version = parts[4]; } + public AppArtifactCoords(AppArtifactKey key, String version) { + this.key = key; + this.groupId = key.getGroupId(); + this.artifactId = key.getGroupId(); + this.classifier = key.getClassifier(); + this.type = key.getType(); + this.version = version; + } + public AppArtifactCoords(String groupId, String artifactId, String version) { this(groupId, artifactId, "", TYPE_JAR, version); } @@ -83,52 +93,24 @@ public AppArtifactKey getKey() { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((artifactId == null) ? 0 : artifactId.hashCode()); - result = prime * result + ((classifier == null) ? 0 : classifier.hashCode()); - result = prime * result + ((groupId == null) ? 0 : groupId.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - result = prime * result + ((version == null) ? 0 : version.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AppArtifactCoords that = (AppArtifactCoords) o; + return Objects.equals(groupId, that.groupId) && + Objects.equals(artifactId, that.artifactId) && + Objects.equals(classifier, that.classifier) && + Objects.equals(type, that.type) && + Objects.equals(version, that.version); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AppArtifactCoords other = (AppArtifactCoords) obj; - if (artifactId == null) { - if (other.artifactId != null) - return false; - } else if (!artifactId.equals(other.artifactId)) - return false; - if (classifier == null) { - if (other.classifier != null) - return false; - } else if (!classifier.equals(other.classifier)) - return false; - if (groupId == null) { - if (other.groupId != null) - return false; - } else if (!groupId.equals(other.groupId)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - if (version == null) { - if (other.version != null) - return false; - } else if (!version.equals(other.version)) - return false; - return true; + public int hashCode() { + return Objects.hash(groupId, artifactId, classifier, type, version); } @Override @@ -140,7 +122,7 @@ public String toString() { protected StringBuilder append(final StringBuilder buf) { buf.append(groupId).append(':').append(artifactId).append(':'); - if (!classifier.isEmpty()) { + if (classifier != null && !classifier.isEmpty()) { buf.append(classifier); } return buf.append(':').append(type).append(':').append(version);