Skip to content

Commit

Permalink
Use records
Browse files Browse the repository at this point in the history
  • Loading branch information
fwilhe committed May 8, 2024
1 parent 30dc1fe commit 784c786
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 495 deletions.
35 changes: 1 addition & 34 deletions src/main/java/io/gardenlinux/glvd/dto/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
package io.gardenlinux.glvd.dto;

import java.util.List;
import java.util.Objects;

public class Configuration {
private List<Node> nodes;
public record Configuration(List<Node> nodes) {

public Configuration() {
}

public Configuration(List<Node> nodes) {
this.nodes = nodes;
}

public List<Node> getNodes() {
return nodes;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Configuration that = (Configuration) o;
return Objects.equals(nodes, that.nodes);
}

@Override
public int hashCode() {
return Objects.hashCode(nodes);
}

@Override
public String toString() {
return "Configuration{" +
"nodes=" + nodes +
'}';
}
}
79 changes: 2 additions & 77 deletions src/main/java/io/gardenlinux/glvd/dto/CpeMatch.java
Original file line number Diff line number Diff line change
@@ -1,81 +1,6 @@
package io.gardenlinux.glvd.dto;

import java.util.Objects;
public record CpeMatch(String criteria, Deb deb, boolean vulnerable, String versionStartIncluding,
String versionEndExcluding, String matchCriteriaId) {

public class CpeMatch {
private String criteria;
private Deb deb;
private boolean vulnerable;
private String versionStartIncluding;
private String versionEndExcluding;
private String matchCriteriaId;

public CpeMatch() {
}


public CpeMatch(String criteria, Deb deb, boolean vulnerable, String versionStartIncluding, String versionEndExcluding, String matchCriteriaId) {
this.criteria = criteria;
this.deb = deb;
this.vulnerable = vulnerable;
this.versionStartIncluding = versionStartIncluding;
this.versionEndExcluding = versionEndExcluding;
this.matchCriteriaId = matchCriteriaId;
}

public String getVersionStartIncluding() {
return versionStartIncluding;
}

public String getCriteria() {
return criteria;
}

public Deb getDeb() {
return deb;
}

public boolean isVulnerable() {
return vulnerable;
}

public String getVersionEndExcluding() {
return versionEndExcluding;
}

public String getMatchCriteriaId() {
return matchCriteriaId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

CpeMatch cpeMatch = (CpeMatch) o;
return vulnerable == cpeMatch.vulnerable && Objects.equals(criteria, cpeMatch.criteria) && Objects.equals(deb, cpeMatch.deb) && Objects.equals(versionStartIncluding, cpeMatch.versionStartIncluding) && Objects.equals(versionEndExcluding, cpeMatch.versionEndExcluding) && Objects.equals(matchCriteriaId, cpeMatch.matchCriteriaId);
}

@Override
public int hashCode() {
int result = Objects.hashCode(criteria);
result = 31 * result + Objects.hashCode(deb);
result = 31 * result + Boolean.hashCode(vulnerable);
result = 31 * result + Objects.hashCode(versionStartIncluding);
result = 31 * result + Objects.hashCode(versionEndExcluding);
result = 31 * result + Objects.hashCode(matchCriteriaId);
return result;
}

@Override
public String toString() {
return "CpeMatch{" +
"criteria='" + criteria + '\'' +
", deb=" + deb +
", vulnerable=" + vulnerable +
", versionStartIncluding='" + versionStartIncluding + '\'' +
", versionEndExcluding='" + versionEndExcluding + '\'' +
", matchCriteriaId='" + matchCriteriaId + '\'' +
'}';
}
}
128 changes: 4 additions & 124 deletions src/main/java/io/gardenlinux/glvd/dto/Cve.java
Original file line number Diff line number Diff line change
@@ -1,130 +1,10 @@
package io.gardenlinux.glvd.dto;

import jakarta.annotation.Nonnull;

import java.util.List;
import java.util.Objects;

public class Cve {

private String id;

@Nonnull
private String lastModified;

@Nonnull
private String sourceIdentifier;

private String published;

private String vulnStatus;

private List<Description> descriptions;

private Object metrics;

private List<Reference> references;

private List<Weakness> weaknesses;

private List<Configuration> configurations;


public Cve() {
}

public Cve(String id, @Nonnull String lastModified, @Nonnull String sourceIdentifier, String published, String vulnStatus, List<Description> descriptions, Object metrics, List<Reference> references, List<Weakness> weaknesses, List<Configuration> configurations) {
this.id = id;
this.lastModified = lastModified;
this.sourceIdentifier = sourceIdentifier;
this.published = published;
this.vulnStatus = vulnStatus;
this.descriptions = descriptions;
this.metrics = metrics;
this.references = references;
this.weaknesses = weaknesses;
this.configurations = configurations;
}
public record Cve(String id, String lastModified, String sourceIdentifier, String published, String vulnStatus,
List<Description> descriptions, Object metrics, List<Reference> references, List<Weakness> weaknesses,
List<Configuration> configurations) {

public String getId() {
return id;
}

@Nonnull
public String getLastModified() {
return lastModified;
}

@Nonnull
public String getSourceIdentifier() {
return sourceIdentifier;
}

public String getPublished() {
return published;
}

public String getVulnStatus() {
return vulnStatus;
}

public List<Description> getDescriptions() {
return descriptions;
}

public Object getMetrics() {
return metrics;
}

public List<Reference> getReferences() {
return references;
}

public List<Weakness> getWeaknesses() {
return weaknesses;
}

public List<Configuration> getConfigurations() {
return configurations;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Cve cve = (Cve) o;
return Objects.equals(id, cve.id) && lastModified.equals(cve.lastModified) && sourceIdentifier.equals(cve.sourceIdentifier) && Objects.equals(published, cve.published) && Objects.equals(vulnStatus, cve.vulnStatus) && Objects.equals(descriptions, cve.descriptions) && Objects.equals(metrics, cve.metrics) && Objects.equals(references, cve.references) && Objects.equals(weaknesses, cve.weaknesses) && Objects.equals(configurations, cve.configurations);
}

@Override
public int hashCode() {
int result = Objects.hashCode(id);
result = 31 * result + lastModified.hashCode();
result = 31 * result + sourceIdentifier.hashCode();
result = 31 * result + Objects.hashCode(published);
result = 31 * result + Objects.hashCode(vulnStatus);
result = 31 * result + Objects.hashCode(descriptions);
result = 31 * result + Objects.hashCode(metrics);
result = 31 * result + Objects.hashCode(references);
result = 31 * result + Objects.hashCode(weaknesses);
result = 31 * result + Objects.hashCode(configurations);
return result;
}

@Override
public String toString() {
return "Cve{" +
"id='" + id + '\'' +
", lastModified='" + lastModified + '\'' +
", sourceIdentifier='" + sourceIdentifier + '\'' +
", published='" + published + '\'' +
", vulnStatus='" + vulnStatus + '\'' +
", descriptions=" + descriptions +
", metrics=" + metrics +
", references=" + references +
", weaknesses=" + weaknesses +
", configurations=" + configurations +
'}';
}
}

53 changes: 1 addition & 52 deletions src/main/java/io/gardenlinux/glvd/dto/Deb.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,5 @@
package io.gardenlinux.glvd.dto;

import java.util.Objects;
public record Deb(String versionLatest, String versionEndExcluding, String cvssSeverity) {

public class Deb {
private String versionLatest;
private String versionEndExcluding;
private String cvssSeverity;

public Deb() {
}

public Deb(String versionLatest, String versionEndExcluding, String cvssSeverity) {
this.versionLatest = versionLatest;
this.versionEndExcluding = versionEndExcluding;
this.cvssSeverity = cvssSeverity;
}

public String getVersionLatest() {
return versionLatest;
}

public String getVersionEndExcluding() {
return versionEndExcluding;
}

public String getCvssSeverity() {
return cvssSeverity;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Deb deb = (Deb) o;
return Objects.equals(versionLatest, deb.versionLatest) && Objects.equals(versionEndExcluding, deb.versionEndExcluding) && Objects.equals(cvssSeverity, deb.cvssSeverity);
}

@Override
public int hashCode() {
int result = Objects.hashCode(versionLatest);
result = 31 * result + Objects.hashCode(versionEndExcluding);
result = 31 * result + Objects.hashCode(cvssSeverity);
return result;
}

@Override
public String toString() {
return "Deb{" +
"versionLatest='" + versionLatest + '\'' +
", versionEndExcluding='" + versionEndExcluding + '\'' +
", cvssSeverity='" + cvssSeverity + '\'' +
'}';
}
}
40 changes: 1 addition & 39 deletions src/main/java/io/gardenlinux/glvd/dto/Description.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
package io.gardenlinux.glvd.dto;

import java.util.Objects;

public class Description {

private String lang;

private String value;

public Description() {
}

public Description(String lang, String value) {
this.lang = lang;
this.value = value;
}

public String getLang() {
return lang;
}

public String getValue() {
return value;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Description that = (Description) o;
return Objects.equals(lang, that.lang) && Objects.equals(value, that.value);
}

@Override
public int hashCode() {
int result = Objects.hashCode(lang);
result = 31 * result + Objects.hashCode(value);
return result;
}
public record Description(String lang, String value) {
}
Loading

0 comments on commit 784c786

Please sign in to comment.