Replaced equals and hashCode to leverage builders instead of deprecated ObjectUtils methods.

This commit is contained in:
Anthony Whitford
2015-09-13 10:48:03 -07:00
parent 0efc9d1cd2
commit f17d8f38fb

View File

@@ -28,7 +28,8 @@ import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.owasp.dependencycheck.data.nexus.MavenArtifact; import org.owasp.dependencycheck.data.nexus.MavenArtifact;
import org.owasp.dependencycheck.utils.Checksum; import org.owasp.dependencycheck.utils.Checksum;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -712,21 +713,24 @@ public class Dependency implements Serializable, Comparable<Dependency> {
return false; return false;
} }
final Dependency other = (Dependency) obj; final Dependency other = (Dependency) obj;
return ObjectUtils.equals(this.actualFilePath, other.actualFilePath) return new EqualsBuilder()
&& ObjectUtils.equals(this.filePath, other.filePath) .appendSuper(super.equals(obj))
&& ObjectUtils.equals(this.fileName, other.fileName) .append(this.actualFilePath, other.actualFilePath)
&& ObjectUtils.equals(this.md5sum, other.md5sum) .append(this.filePath, other.filePath)
&& ObjectUtils.equals(this.sha1sum, other.sha1sum) .append(this.fileName, other.fileName)
&& ObjectUtils.equals(this.identifiers, other.identifiers) .append(this.md5sum, other.md5sum)
&& ObjectUtils.equals(this.vendorEvidence, other.vendorEvidence) .append(this.sha1sum, other.sha1sum)
&& ObjectUtils.equals(this.productEvidence, other.productEvidence) .append(this.identifiers, other.identifiers)
&& ObjectUtils.equals(this.versionEvidence, other.versionEvidence) .append(this.vendorEvidence, other.vendorEvidence)
&& ObjectUtils.equals(this.description, other.description) .append(this.productEvidence, other.productEvidence)
&& ObjectUtils.equals(this.license, other.license) .append(this.versionEvidence, other.versionEvidence)
&& ObjectUtils.equals(this.vulnerabilities, other.vulnerabilities) .append(this.description, other.description)
//&& ObjectUtils.equals(this.relatedDependencies, other.relatedDependencies) .append(this.license, other.license)
&& ObjectUtils.equals(this.projectReferences, other.projectReferences) .append(this.vulnerabilities, other.vulnerabilities)
&& ObjectUtils.equals(this.availableVersions, other.availableVersions); //.append(this.relatedDependencies, other.relatedDependencies)
.append(this.projectReferences, other.projectReferences)
.append(this.availableVersions, other.availableVersions)
.isEquals();
} }
/** /**
@@ -736,15 +740,23 @@ public class Dependency implements Serializable, Comparable<Dependency> {
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
int hash = MAGIC_HASH_INIT_VALUE; return new HashCodeBuilder(MAGIC_HASH_INIT_VALUE, MAGIC_HASH_MULTIPLIER)
for (Object field : new Object[]{this.actualFilePath, this.filePath, this.fileName, this.md5sum, .append(actualFilePath)
this.sha1sum, this.identifiers, this.vendorEvidence, this.productEvidence, this.versionEvidence, .append(filePath)
this.description, this.license, this.vulnerabilities, .append(fileName)
//this.relatedDependencies, .append(md5sum)
this.projectReferences, this.availableVersions}) { .append(sha1sum)
hash = MAGIC_HASH_MULTIPLIER * hash + ObjectUtils.hashCode(field); .append(identifiers)
} .append(vendorEvidence)
return hash; .append(productEvidence)
.append(versionEvidence)
.append(description)
.append(license)
.append(vulnerabilities)
//.append(relatedDependencies)
.append(projectReferences)
.append(availableVersions)
.toHashCode();
} }
/** /**