Skip to content

Commit

Permalink
Merge pull request #464 from SaberStrat/feature/463-make-vulnerabilit…
Browse files Browse the repository at this point in the history
…y-objects-comparable-by-fields

Make Vulnerability objects comparable by value

Closes #463
  • Loading branch information
nscuro authored Aug 6, 2024
2 parents f09c595 + 8b67e69 commit b7b99fa
Showing 1 changed file with 180 additions and 5 deletions.
185 changes: 180 additions & 5 deletions src/main/java/org/cyclonedx/model/vulnerability/Vulnerability.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -29,11 +30,7 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.cyclonedx.model.OrganizationalContact;
import org.cyclonedx.model.OrganizationalEntity;
import org.cyclonedx.model.Property;
import org.cyclonedx.model.Tool;
import org.cyclonedx.model.VersionFilter;
import org.cyclonedx.model.*;
import org.cyclonedx.util.serializer.CustomDateSerializer;

/**
Expand Down Expand Up @@ -276,6 +273,56 @@ public void setProperties(final List<Property> properties) {
this.properties = properties;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Vulnerability)) return false;
Vulnerability rhs = (Vulnerability) o;
return Objects.equals(bomRef, rhs.bomRef) &&
Objects.equals(id, rhs.id) &&
Objects.equals(source, rhs.source) &&
Objects.equals(references, rhs.references) &&
Objects.equals(ratings, rhs.ratings) &&
Objects.equals(cwes, rhs.cwes) &&
Objects.equals(description, rhs.description) &&
Objects.equals(detail, rhs.detail) &&
Objects.equals(recommendation, rhs.recommendation) &&
Objects.equals(advisories, rhs.advisories) &&
Objects.equals(created, rhs.created) &&
Objects.equals(published, rhs.published) &&
Objects.equals(updated, rhs.updated) &&
Objects.equals(rejected, rhs.rejected) &&
Objects.equals(credits, rhs.credits) &&
Objects.equals(tools, rhs.tools) &&
Objects.equals(analysis, rhs.analysis) &&
Objects.equals(affects, rhs.affects) &&
Objects.equals(properties, rhs.properties);
}

@Override
public int hashCode() {
return Objects.hash(
bomRef,
id,
source,
references,
ratings,
cwes,
description,
detail,
recommendation,
advisories,
created,
published,
updated,
rejected,
credits,
tools,
analysis,
affects,
properties);
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Reference {
private String id;
Expand All @@ -296,6 +343,22 @@ public Source getSource() {
public void setSource(final Source source) {
this.source = source;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Reference)) return false;
Reference rhs = (Reference) o;
return Objects.equals(id, rhs.id) &&
Objects.equals(source, rhs.source);
}

@Override
public int hashCode() {
return Objects.hash(
id,
source);
}
}

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand All @@ -318,6 +381,22 @@ public String getUrl() {
public void setUrl(final String url) {
this.url = url;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Source)) return false;
Source rhs = (Source) o;
return Objects.equals(name, rhs.name) &&
Objects.equals(url, rhs.url);
}

@Override
public int hashCode() {
return Objects.hash(
name,
url);
}
}

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand All @@ -340,6 +419,22 @@ public String getUrl() {
public void setUrl(final String url) {
this.url = url;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Advisory)) return false;
Advisory rhs = (Advisory) o;
return Objects.equals(title, rhs.title) &&
Objects.equals(url, rhs.url);
}

@Override
public int hashCode() {
return Objects.hash(
title,
url);
}
}

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -474,6 +569,30 @@ public String getJustification() {
public void setJustification(final String justification) {
this.justification = justification;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Rating)) return false;
Rating rhs = (Rating) o;
return Objects.equals(source, rhs.source) &&
Objects.equals(score, rhs.score) &&
Objects.equals(severity, rhs.severity) &&
Objects.equals(method, rhs.method) &&
Objects.equals(vector, rhs.vector) &&
Objects.equals(justification, rhs.justification);
}

@Override
public int hashCode() {
return Objects.hash(
source,
score,
severity,
method,
vector,
justification);
}
}

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -655,6 +774,30 @@ public Date getLastUpdated() {
public void setLastUpdated(final Date lastUpdated) {
this.lastUpdated = lastUpdated;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Analysis)) return false;
Analysis rhs = (Analysis) o;
return Objects.equals(state, rhs.state) &&
Objects.equals(justification, rhs.justification) &&
Objects.equals(responses, rhs.responses) &&
Objects.equals(detail, rhs.detail) &&
Objects.equals(firstIssued, rhs.firstIssued) &&
Objects.equals(lastUpdated, rhs.lastUpdated);
}

@Override
public int hashCode() {
return Objects.hash(
state,
justification,
responses,
detail,
firstIssued,
lastUpdated);
}
}

@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand All @@ -679,6 +822,22 @@ public List<Version> getVersions() {
public void setVersions(final List<Version> versions) {
this.versions = versions;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Affect)) return false;
Affect rhs = (Affect) o;
return Objects.equals(ref, rhs.ref) &&
Objects.equals(versions, rhs.versions);
}

@Override
public int hashCode() {
return Objects.hash(
ref,
versions);
}
}

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -767,5 +926,21 @@ public List<OrganizationalEntity> getOrganizations() {
public void setOrganizations(final List<OrganizationalEntity> organizations) {
this.organizations = organizations;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Credits)) return false;
Credits rhs = (Credits) o;
return Objects.equals(organizations, rhs.organizations) &&
Objects.equals(individuals, rhs.individuals);
}

@Override
public int hashCode() {
return Objects.hash(
organizations,
individuals);
}
}
}

0 comments on commit b7b99fa

Please sign in to comment.