From 92fb2e6c4a94b7590b1d8913fe0f383746912a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Kir=C3=A1ly?= Date: Fri, 8 Dec 2023 13:13:00 +0100 Subject: [PATCH] Implement SonarCloud quality suggestions #159 --- .../metadataqa/api/calculator/AnnotationCalculator.java | 1 - .../api/configuration/MeasurementConfiguration.java | 2 +- src/main/java/de/gwdg/metadataqa/api/json/DataElement.java | 5 ++--- .../metadataqa/api/model/selector/SelectorFactory.java | 4 ---- src/main/java/de/gwdg/metadataqa/api/util/Converter.java | 6 +++--- .../api/calculator/CompletenessCalculatorLimitedTest.java | 7 +++++++ 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/gwdg/metadataqa/api/calculator/AnnotationCalculator.java b/src/main/java/de/gwdg/metadataqa/api/calculator/AnnotationCalculator.java index 9afd75d2..d7f6ace9 100644 --- a/src/main/java/de/gwdg/metadataqa/api/calculator/AnnotationCalculator.java +++ b/src/main/java/de/gwdg/metadataqa/api/calculator/AnnotationCalculator.java @@ -8,7 +8,6 @@ import java.io.Serializable; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/src/main/java/de/gwdg/metadataqa/api/configuration/MeasurementConfiguration.java b/src/main/java/de/gwdg/metadataqa/api/configuration/MeasurementConfiguration.java index 4d5cc397..0761fbae 100644 --- a/src/main/java/de/gwdg/metadataqa/api/configuration/MeasurementConfiguration.java +++ b/src/main/java/de/gwdg/metadataqa/api/configuration/MeasurementConfiguration.java @@ -676,7 +676,7 @@ public MeasurementConfiguration withAnnotationColumns(String jsonString) { ObjectMapper mapper = new ObjectMapper(); annottaionColumns = new LinkedHashMap<>(); try { - Map map = (Map) mapper.readValue(jsonString, Map.class); + Map map = mapper.readValue(jsonString, Map.class); for (Map.Entry entry : map.entrySet()) { Object value = entry.getValue(); if (value instanceof String || value instanceof Integer || value instanceof Double) diff --git a/src/main/java/de/gwdg/metadataqa/api/json/DataElement.java b/src/main/java/de/gwdg/metadataqa/api/json/DataElement.java index cfd95a0b..162557da 100644 --- a/src/main/java/de/gwdg/metadataqa/api/json/DataElement.java +++ b/src/main/java/de/gwdg/metadataqa/api/json/DataElement.java @@ -2,7 +2,6 @@ import de.gwdg.metadataqa.api.configuration.schema.Rule; import de.gwdg.metadataqa.api.model.Category; -import de.gwdg.metadataqa.api.rule.singlefieldchecker.MinCountChecker; import de.gwdg.metadataqa.api.schema.Format; import de.gwdg.metadataqa.api.schema.Schema; import org.apache.commons.lang3.SerializationUtils; @@ -254,12 +253,12 @@ public String toString() { } public static DataElement copy(DataElement other) throws CloneNotSupportedException { - DataElement cloned = (DataElement) SerializationUtils.clone(other); + DataElement cloned = SerializationUtils.clone(other); if (other.children != null && !other.children.isEmpty()) { List clonedChildren = new ArrayList<>(); for (DataElement child : other.children) { - DataElement clonedChild = (DataElement) SerializationUtils.clone(child); + DataElement clonedChild = SerializationUtils.clone(child); clonedChild.parent = cloned; clonedChildren.add(clonedChild); } diff --git a/src/main/java/de/gwdg/metadataqa/api/model/selector/SelectorFactory.java b/src/main/java/de/gwdg/metadataqa/api/model/selector/SelectorFactory.java index dcb8fe4e..86810575 100644 --- a/src/main/java/de/gwdg/metadataqa/api/model/selector/SelectorFactory.java +++ b/src/main/java/de/gwdg/metadataqa/api/model/selector/SelectorFactory.java @@ -1,10 +1,6 @@ package de.gwdg.metadataqa.api.model.selector; import de.gwdg.metadataqa.api.model.XmlFieldInstance; -import de.gwdg.metadataqa.api.model.selector.CsvSelector; -import de.gwdg.metadataqa.api.model.selector.JsonSelector; -import de.gwdg.metadataqa.api.model.selector.Selector; -import de.gwdg.metadataqa.api.model.selector.XmlSelector; import de.gwdg.metadataqa.api.schema.Format; import java.util.Map; diff --git a/src/main/java/de/gwdg/metadataqa/api/util/Converter.java b/src/main/java/de/gwdg/metadataqa/api/util/Converter.java index ef524ae5..8eeb63a3 100644 --- a/src/main/java/de/gwdg/metadataqa/api/util/Converter.java +++ b/src/main/java/de/gwdg/metadataqa/api/util/Converter.java @@ -68,13 +68,13 @@ public static Integer asInteger(Object value) { intValue = (Integer) value; break; case "java.lang.Double": - intValue = (Integer) ((Long) Math.round((Double) value)).intValue(); + intValue = ((Long) Math.round((Double) value)).intValue(); break; case "java.lang.Long": - intValue = (Integer) ((Long) value).intValue(); + intValue = ((Long) value).intValue(); break; case "java.lang.Float": - intValue = (Integer) Math.round((float)value); + intValue = Math.round((float)value); break; case "java.lang.String": intValue = asInteger(Double.parseDouble((String)value)); diff --git a/src/test/java/de/gwdg/metadataqa/api/calculator/CompletenessCalculatorLimitedTest.java b/src/test/java/de/gwdg/metadataqa/api/calculator/CompletenessCalculatorLimitedTest.java index d95ccaff..9da67bd2 100644 --- a/src/test/java/de/gwdg/metadataqa/api/calculator/CompletenessCalculatorLimitedTest.java +++ b/src/test/java/de/gwdg/metadataqa/api/calculator/CompletenessCalculatorLimitedTest.java @@ -155,6 +155,13 @@ public void testExistenceMap() throws URISyntaxException, IOException { if (existing) existingFieldCounter++; assertEquals(14, existingFieldCounter); + } + + @Test + public void testExistenceMap_2() throws URISyntaxException, IOException { + calculator.collectFields(true); + calculator.measure(cache); + Map existenceMap = calculator.getExistenceMap(); assertTrue(existenceMap.get("edm:ProvidedCHO/@about")); assertTrue(existenceMap.get("Proxy/dc:title"));