Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java')
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java80
1 files changed, 47 insertions, 33 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java
index 35fa5fbf..2652f4ad 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java
@@ -17,12 +17,16 @@ import org.eclipse.osgi.util.NLS;
import org.apache.maven.artifact.Artifact;
+
public class ArtifactKey implements Serializable {
private static final long serialVersionUID = -8984509272834024387L;
-
+
private final String groupId;
+
private final String artifactId;
+
private final String version;
+
private final String classifier;
/**
@@ -44,12 +48,11 @@ public class ArtifactKey implements Serializable {
}
public boolean equals(Object o) {
- if (this == o) return true;
- if (o instanceof ArtifactKey) {
+ if(this == o)
+ return true;
+ if(o instanceof ArtifactKey) {
ArtifactKey other = (ArtifactKey) o;
- return equals(groupId, other.groupId)
- && equals(artifactId, other.artifactId)
- && equals(version, other.version)
+ return equals(groupId, other.groupId) && equals(artifactId, other.artifactId) && equals(version, other.version)
&& equals(classifier, other.classifier);
}
return false;
@@ -57,29 +60,27 @@ public class ArtifactKey implements Serializable {
public int hashCode() {
int hash = 17;
- hash = hash * 31 + (groupId != null? groupId.hashCode(): 0);
- hash = hash * 31 + (artifactId != null? artifactId.hashCode(): 0);
- hash = hash * 31 + (version != null? version.hashCode(): 0);
- hash = hash * 31 + (classifier != null? classifier.hashCode(): 0);
+ hash = hash * 31 + (groupId != null ? groupId.hashCode() : 0);
+ hash = hash * 31 + (artifactId != null ? artifactId.hashCode() : 0);
+ hash = hash * 31 + (version != null ? version.hashCode() : 0);
+ hash = hash * 31 + (classifier != null ? classifier.hashCode() : 0);
return hash;
}
private static boolean equals(Object o1, Object o2) {
- return o1 == null? o2 == null: o1.equals(o2);
+ return o1 == null ? o2 == null : o1.equals(o2);
}
// XXX this method does not belong here, it compares versions, while ArtifactKey uses baseVersions in many cases
public static boolean equals(Artifact a1, Artifact a2) {
- if (a1 == null) {
+ if(a1 == null) {
return a2 == null;
}
- if (a2 == null) {
+ if(a2 == null) {
return false;
}
- return equals(a1.getGroupId(), a2.getGroupId())
- && equals(a1.getArtifactId(), a2.getArtifactId())
- && equals(a1.getVersion(), a2.getVersion())
- && equals(a1.getClassifier(), a2.getClassifier());
+ return equals(a1.getGroupId(), a2.getGroupId()) && equals(a1.getArtifactId(), a2.getArtifactId())
+ && equals(a1.getVersion(), a2.getVersion()) && equals(a1.getClassifier(), a2.getClassifier());
}
public String toString() {
@@ -94,38 +95,51 @@ public class ArtifactKey implements Serializable {
public static ArtifactKey fromPortableString(String str) {
int p, c;
- p = 0; c = nextColonIndex(str, p);
- String groupId = substring(str, p, c);
+ p = 0;
+ c = nextColonIndex(str, p);
+ String groupId = substring(str, p, c);
- p = c + 1; c = nextColonIndex(str, p);
- String artifactId = substring(str, p, c);
-
- p = c + 1; c = nextColonIndex(str, p);
+ p = c + 1;
+ c = nextColonIndex(str, p);
+ String artifactId = substring(str, p, c);
+
+ p = c + 1;
+ c = nextColonIndex(str, p);
String version = substring(str, p, c);
-
- p = c + 1; c = nextColonIndex(str, p);
+
+ p = c + 1;
+ c = nextColonIndex(str, p);
String classifier = substring(str, p, c);
-
+
return new ArtifactKey(groupId, artifactId, version, classifier);
}
-
+
private static String substring(String str, int start, int end) {
String substring = str.substring(start, end);
- return "".equals(substring)? null: substring; //$NON-NLS-1$
+ return "".equals(substring) ? null : substring; //$NON-NLS-1$
}
private static int nextColonIndex(String str, int pos) {
int idx = str.indexOf(':', pos);
- if (idx < 0) throw new IllegalArgumentException(NLS.bind("Invalid portable string: {0}", str));
+ if(idx < 0)
+ throw new IllegalArgumentException(NLS.bind("Invalid portable string: {0}", str));
return idx;
}
public String toPortableString() {
StringBuilder sb = new StringBuilder();
- if (groupId != null) sb.append(groupId); sb.append(':');
- if (artifactId != null) sb.append(artifactId); sb.append(':');
- if (version != null) sb.append(version); sb.append(':');
- if (classifier != null) sb.append(classifier); sb.append(':');
+ if(groupId != null)
+ sb.append(groupId);
+ sb.append(':');
+ if(artifactId != null)
+ sb.append(artifactId);
+ sb.append(':');
+ if(version != null)
+ sb.append(version);
+ sb.append(':');
+ if(classifier != null)
+ sb.append(classifier);
+ sb.append(':');
return sb.toString();
}

Back to the top