From ca99fa8cd2f47e6e2bcfbd163dece27241f8e221 Mon Sep 17 00:00:00 2001 From: Markus Fleischhacker Date: Sun, 9 Oct 2022 13:52:01 +0200 Subject: [PATCH] Fix reflection and modularity errors wrt. jakarta and gson. --- build.gradle | 6 +++ .../BoundingBoxPredictionEntry.java | 39 +++++++++++++++++- .../model/io/restclients/ModelEntry.java | 40 ++++++++++++++++++- .../model/io/ModelIoTests.java | 11 +++++ 4 files changed, 94 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index d7d38b5..4de8736 100644 --- a/build.gradle +++ b/build.gradle @@ -197,6 +197,12 @@ jlink { forceMerge 'jakarta' + mergedModule { + additive = true + uses 'jakarta.ws.rs.client.ClientBuilder' + uses 'jakarta.ws.rs.ext.RuntimeDelegate' + } + imageZip = project.file("${buildDir}/distributions/boundingboxeditor-${javafx.platform.classifier}.zip") jpackage { diff --git a/src/main/java/com/github/mfl28/boundingboxeditor/model/io/restclients/BoundingBoxPredictionEntry.java b/src/main/java/com/github/mfl28/boundingboxeditor/model/io/restclients/BoundingBoxPredictionEntry.java index e04c58f..cc3f89b 100644 --- a/src/main/java/com/github/mfl28/boundingboxeditor/model/io/restclients/BoundingBoxPredictionEntry.java +++ b/src/main/java/com/github/mfl28/boundingboxeditor/model/io/restclients/BoundingBoxPredictionEntry.java @@ -20,6 +20,43 @@ import java.util.List; import java.util.Map; +import java.util.Objects; -public record BoundingBoxPredictionEntry(Map> categoryToBoundingBoxes, Double score) { +public final class BoundingBoxPredictionEntry { + private final Map> categoryToBoundingBoxes; + private final Double score; + + public BoundingBoxPredictionEntry(Map> categoryToBoundingBoxes, Double score) { + this.categoryToBoundingBoxes = categoryToBoundingBoxes; + this.score = score; + } + + public Map> categoryToBoundingBoxes() { + return categoryToBoundingBoxes; + } + + public Double score() { + return score; + } + + @Override + public boolean equals(Object obj) { + if(obj == this) { + return true; + } + + if(obj == null || obj.getClass() != this.getClass()) { + return false; + } + + BoundingBoxPredictionEntry that = (BoundingBoxPredictionEntry) obj; + + return Objects.equals(this.categoryToBoundingBoxes, that.categoryToBoundingBoxes) && + Objects.equals(this.score, that.score); + } + + @Override + public int hashCode() { + return Objects.hash(categoryToBoundingBoxes, score); + } } diff --git a/src/main/java/com/github/mfl28/boundingboxeditor/model/io/restclients/ModelEntry.java b/src/main/java/com/github/mfl28/boundingboxeditor/model/io/restclients/ModelEntry.java index 623ca3f..aaea426 100644 --- a/src/main/java/com/github/mfl28/boundingboxeditor/model/io/restclients/ModelEntry.java +++ b/src/main/java/com/github/mfl28/boundingboxeditor/model/io/restclients/ModelEntry.java @@ -18,5 +18,43 @@ */ package com.github.mfl28.boundingboxeditor.model.io.restclients; -public record ModelEntry(String modelName, String modelUrl) { +import java.util.Objects; + +public final class ModelEntry { + private final String modelName; + private final String modelUrl; + + public ModelEntry(String modelName, String modelUrl) { + this.modelName = modelName; + this.modelUrl = modelUrl; + } + + public String modelName() { + return modelName; + } + + public String modelUrl() { + return modelUrl; + } + + @Override + public boolean equals(Object obj) { + if(obj == this) { + return true; + } + + if(obj == null || obj.getClass() != this.getClass()) { + return false; + } + + ModelEntry that = (ModelEntry) obj; + + return Objects.equals(this.modelName, that.modelName) && + Objects.equals(this.modelUrl, that.modelUrl); + } + + @Override + public int hashCode() { + return Objects.hash(modelName, modelUrl); + } } diff --git a/src/test/java/com/github/mfl28/boundingboxeditor/model/io/ModelIoTests.java b/src/test/java/com/github/mfl28/boundingboxeditor/model/io/ModelIoTests.java index 7120c04..7c89810 100644 --- a/src/test/java/com/github/mfl28/boundingboxeditor/model/io/ModelIoTests.java +++ b/src/test/java/com/github/mfl28/boundingboxeditor/model/io/ModelIoTests.java @@ -21,8 +21,11 @@ import com.github.mfl28.boundingboxeditor.model.data.BoundingBoxData; import com.github.mfl28.boundingboxeditor.model.data.BoundingPolygonData; import com.github.mfl28.boundingboxeditor.model.data.ObjectCategory; +import com.github.mfl28.boundingboxeditor.model.io.restclients.BoundingBoxPredictionEntry; +import com.github.mfl28.boundingboxeditor.model.io.restclients.ModelEntry; import javafx.geometry.BoundingBox; import javafx.scene.paint.Color; +import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -106,7 +109,15 @@ void onBoundingPolygonDataEqualityCheck_ShouldHandleCorrectly() { 15.0), Collections.emptyList()); Assertions.assertNotEquals(boundingPolygonData1, boundingPolygonData4); + } + @Test + void checkRestModelEntryEqualityContract() { + EqualsVerifier.simple().forClass(ModelEntry.class).verify(); } + @Test + void checkRestBoundingBoxPredictionEntryEqualityContract() { + EqualsVerifier.simple().forClass(BoundingBoxPredictionEntry.class).verify(); + } }