Skip to content

Commit b7b99fa

Browse files
authored
Merge pull request #464 from SaberStrat/feature/463-make-vulnerability-objects-comparable-by-fields
Make Vulnerability objects comparable by value Closes #463
2 parents f09c595 + 8b67e69 commit b7b99fa

File tree

1 file changed

+180
-5
lines changed

1 file changed

+180
-5
lines changed

src/main/java/org/cyclonedx/model/vulnerability/Vulnerability.java

+180-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import java.util.Date;
2323
import java.util.List;
24+
import java.util.Objects;
2425

2526
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2627
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -29,11 +30,7 @@
2930
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
3031
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
3132
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
32-
import org.cyclonedx.model.OrganizationalContact;
33-
import org.cyclonedx.model.OrganizationalEntity;
34-
import org.cyclonedx.model.Property;
35-
import org.cyclonedx.model.Tool;
36-
import org.cyclonedx.model.VersionFilter;
33+
import org.cyclonedx.model.*;
3734
import org.cyclonedx.util.serializer.CustomDateSerializer;
3835

3936
/**
@@ -276,6 +273,56 @@ public void setProperties(final List<Property> properties) {
276273
this.properties = properties;
277274
}
278275

276+
@Override
277+
public boolean equals(Object o) {
278+
if (this == o) return true;
279+
if (!(o instanceof Vulnerability)) return false;
280+
Vulnerability rhs = (Vulnerability) o;
281+
return Objects.equals(bomRef, rhs.bomRef) &&
282+
Objects.equals(id, rhs.id) &&
283+
Objects.equals(source, rhs.source) &&
284+
Objects.equals(references, rhs.references) &&
285+
Objects.equals(ratings, rhs.ratings) &&
286+
Objects.equals(cwes, rhs.cwes) &&
287+
Objects.equals(description, rhs.description) &&
288+
Objects.equals(detail, rhs.detail) &&
289+
Objects.equals(recommendation, rhs.recommendation) &&
290+
Objects.equals(advisories, rhs.advisories) &&
291+
Objects.equals(created, rhs.created) &&
292+
Objects.equals(published, rhs.published) &&
293+
Objects.equals(updated, rhs.updated) &&
294+
Objects.equals(rejected, rhs.rejected) &&
295+
Objects.equals(credits, rhs.credits) &&
296+
Objects.equals(tools, rhs.tools) &&
297+
Objects.equals(analysis, rhs.analysis) &&
298+
Objects.equals(affects, rhs.affects) &&
299+
Objects.equals(properties, rhs.properties);
300+
}
301+
302+
@Override
303+
public int hashCode() {
304+
return Objects.hash(
305+
bomRef,
306+
id,
307+
source,
308+
references,
309+
ratings,
310+
cwes,
311+
description,
312+
detail,
313+
recommendation,
314+
advisories,
315+
created,
316+
published,
317+
updated,
318+
rejected,
319+
credits,
320+
tools,
321+
analysis,
322+
affects,
323+
properties);
324+
}
325+
279326
@JsonInclude(JsonInclude.Include.NON_NULL)
280327
public static class Reference {
281328
private String id;
@@ -296,6 +343,22 @@ public Source getSource() {
296343
public void setSource(final Source source) {
297344
this.source = source;
298345
}
346+
347+
@Override
348+
public boolean equals(Object o) {
349+
if (this == o) return true;
350+
if (!(o instanceof Reference)) return false;
351+
Reference rhs = (Reference) o;
352+
return Objects.equals(id, rhs.id) &&
353+
Objects.equals(source, rhs.source);
354+
}
355+
356+
@Override
357+
public int hashCode() {
358+
return Objects.hash(
359+
id,
360+
source);
361+
}
299362
}
300363

301364
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -318,6 +381,22 @@ public String getUrl() {
318381
public void setUrl(final String url) {
319382
this.url = url;
320383
}
384+
385+
@Override
386+
public boolean equals(Object o) {
387+
if (this == o) return true;
388+
if (!(o instanceof Source)) return false;
389+
Source rhs = (Source) o;
390+
return Objects.equals(name, rhs.name) &&
391+
Objects.equals(url, rhs.url);
392+
}
393+
394+
@Override
395+
public int hashCode() {
396+
return Objects.hash(
397+
name,
398+
url);
399+
}
321400
}
322401

323402
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -340,6 +419,22 @@ public String getUrl() {
340419
public void setUrl(final String url) {
341420
this.url = url;
342421
}
422+
423+
@Override
424+
public boolean equals(Object o) {
425+
if (this == o) return true;
426+
if (!(o instanceof Advisory)) return false;
427+
Advisory rhs = (Advisory) o;
428+
return Objects.equals(title, rhs.title) &&
429+
Objects.equals(url, rhs.url);
430+
}
431+
432+
@Override
433+
public int hashCode() {
434+
return Objects.hash(
435+
title,
436+
url);
437+
}
343438
}
344439

345440
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -474,6 +569,30 @@ public String getJustification() {
474569
public void setJustification(final String justification) {
475570
this.justification = justification;
476571
}
572+
573+
@Override
574+
public boolean equals(Object o) {
575+
if (this == o) return true;
576+
if (!(o instanceof Rating)) return false;
577+
Rating rhs = (Rating) o;
578+
return Objects.equals(source, rhs.source) &&
579+
Objects.equals(score, rhs.score) &&
580+
Objects.equals(severity, rhs.severity) &&
581+
Objects.equals(method, rhs.method) &&
582+
Objects.equals(vector, rhs.vector) &&
583+
Objects.equals(justification, rhs.justification);
584+
}
585+
586+
@Override
587+
public int hashCode() {
588+
return Objects.hash(
589+
source,
590+
score,
591+
severity,
592+
method,
593+
vector,
594+
justification);
595+
}
477596
}
478597

479598
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -655,6 +774,30 @@ public Date getLastUpdated() {
655774
public void setLastUpdated(final Date lastUpdated) {
656775
this.lastUpdated = lastUpdated;
657776
}
777+
778+
@Override
779+
public boolean equals(Object o) {
780+
if (this == o) return true;
781+
if (!(o instanceof Analysis)) return false;
782+
Analysis rhs = (Analysis) o;
783+
return Objects.equals(state, rhs.state) &&
784+
Objects.equals(justification, rhs.justification) &&
785+
Objects.equals(responses, rhs.responses) &&
786+
Objects.equals(detail, rhs.detail) &&
787+
Objects.equals(firstIssued, rhs.firstIssued) &&
788+
Objects.equals(lastUpdated, rhs.lastUpdated);
789+
}
790+
791+
@Override
792+
public int hashCode() {
793+
return Objects.hash(
794+
state,
795+
justification,
796+
responses,
797+
detail,
798+
firstIssued,
799+
lastUpdated);
800+
}
658801
}
659802

660803
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@@ -679,6 +822,22 @@ public List<Version> getVersions() {
679822
public void setVersions(final List<Version> versions) {
680823
this.versions = versions;
681824
}
825+
826+
@Override
827+
public boolean equals(Object o) {
828+
if (this == o) return true;
829+
if (!(o instanceof Affect)) return false;
830+
Affect rhs = (Affect) o;
831+
return Objects.equals(ref, rhs.ref) &&
832+
Objects.equals(versions, rhs.versions);
833+
}
834+
835+
@Override
836+
public int hashCode() {
837+
return Objects.hash(
838+
ref,
839+
versions);
840+
}
682841
}
683842

684843
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -767,5 +926,21 @@ public List<OrganizationalEntity> getOrganizations() {
767926
public void setOrganizations(final List<OrganizationalEntity> organizations) {
768927
this.organizations = organizations;
769928
}
929+
930+
@Override
931+
public boolean equals(Object o) {
932+
if (this == o) return true;
933+
if (!(o instanceof Credits)) return false;
934+
Credits rhs = (Credits) o;
935+
return Objects.equals(organizations, rhs.organizations) &&
936+
Objects.equals(individuals, rhs.individuals);
937+
}
938+
939+
@Override
940+
public int hashCode() {
941+
return Objects.hash(
942+
organizations,
943+
individuals);
944+
}
770945
}
771946
}

0 commit comments

Comments
 (0)