From 58e30649a3a36ecb324047cc21709415b49f939c Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Tue, 4 Jun 2013 23:06:02 -0400 Subject: [PATCH] added equals and hashCode Former-commit-id: e7091b8f28f1a24d761729fe213b6208fe2ee03b --- .../utils/DependencyVersion.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/org/owasp/dependencycheck/utils/DependencyVersion.java b/src/main/java/org/owasp/dependencycheck/utils/DependencyVersion.java index 4a8197818..ed4fb090c 100644 --- a/src/main/java/org/owasp/dependencycheck/utils/DependencyVersion.java +++ b/src/main/java/org/owasp/dependencycheck/utils/DependencyVersion.java @@ -111,4 +111,35 @@ public class DependencyVersion implements Iterable { public String toString() { return StringUtils.join(versionParts.toArray(), "."); } + + /** + * Compares the equality of this object to the one passed in as a parameter. + * @param obj the object to compare equality + * @return returns true only if the two objects are equal, otherwise false + */ + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final DependencyVersion other = (DependencyVersion) obj; + if (this.versionParts != other.versionParts && (this.versionParts == null || !this.versionParts.equals(other.versionParts))) { + return false; + } + return true; + } + + /** + * Calculates the hashCode for this object. + * @return the hashCode + */ + @Override + public int hashCode() { + int hash = 5; + hash = 71 * hash + (this.versionParts != null ? this.versionParts.hashCode() : 0); + return hash; + } }