diff --git a/CHANGELOG.md b/CHANGELOG.md index f5527239..ac9fc79f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Enable using JUnit platform - Fix broken tests - Let scalatest and JUnit tests run together +- Improve code quality to meet minimum standards [#203](https://github.com/ie3-institute/PowerSystemUtils/issues/203) + - Use `Stream#toList` + - Enhance deprecation annotations +- Fix formatting for MarkDown files +- Configure gradle jacoco plugin according to newest documentation ## [1.6.0] diff --git a/gradle/scripts/jacoco.gradle b/gradle/scripts/jacoco.gradle index 5f9629b4..ed31577d 100644 --- a/gradle/scripts/jacoco.gradle +++ b/gradle/scripts/jacoco.gradle @@ -4,15 +4,15 @@ // general configuration jacoco { toolVersion = "0.8.7" - reportsDir = file("$buildDir/reports/jacoco") + reportsDirectory = layout.buildDirectory.dir("$buildDir/reports/jacoco") } jacocoTestReport { reports { - xml.enabled true - csv.enabled false - html.enabled true - html.destination file("${buildDir}/reports/jacoco") + csv.required = false + html.required = true + xml.required = true + html.outputLocation = layout.buildDirectory.dir("${buildDir}/reports/jacoco") } // what to exclude from coverage report (files that should not be analyzed!) diff --git a/gradle/scripts/sonarqube.gradle b/gradle/scripts/sonarqube.gradle index 4cd55c51..98184972 100644 --- a/gradle/scripts/sonarqube.gradle +++ b/gradle/scripts/sonarqube.gradle @@ -33,7 +33,7 @@ sonarqube { property 'sonar.groovy.jacoco.itReportPath', 'build/jacoco/allTests.exec' property 'sonar.groovy.binaries', 'build/classes/groovy' // groovy binaries // scala specific stuff - property 'sonar.scala.coverage.reportPaths', 'build/reports/scoverage/scoverage.xml' + //property 'sonar.scala.coverage.reportPaths', 'build/reports/scoverage/scoverage.xml' } } diff --git a/src/main/java/edu/ie3/util/EmpiricalRandom.java b/src/main/java/edu/ie3/util/EmpiricalRandom.java index 4befea0c..a20f6995 100644 --- a/src/main/java/edu/ie3/util/EmpiricalRandom.java +++ b/src/main/java/edu/ie3/util/EmpiricalRandom.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Map; import java.util.Random; -import java.util.stream.Collectors; import org.eclipse.collections.impl.UnmodifiableMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,7 +68,7 @@ public C nextEmpirical() { this.empiricalCdf.entrySet().stream() .filter(entry -> entry.getValue() >= rand) .map(Map.Entry::getKey) - .collect(Collectors.toList()); + .toList(); if (candidates.isEmpty()) { logger.error("There is no candidate, which is not supposed to happen. Take first one"); return empiricalCdf.keySet().iterator().next(); diff --git a/src/main/java/edu/ie3/util/geo/GeoUtils.java b/src/main/java/edu/ie3/util/geo/GeoUtils.java index 39857f30..71b3e534 100644 --- a/src/main/java/edu/ie3/util/geo/GeoUtils.java +++ b/src/main/java/edu/ie3/util/geo/GeoUtils.java @@ -238,7 +238,7 @@ public static org.locationtech.jts.geom.Point xyToPoint(double x, double y) { * @return Deep copy of the {@code relation} with closed ways * @deprecated This method is currently not under test and has to be revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static Relation buildClosedWays(Relation relation) throws GeoPreparationException { /* Copy relation and empty the Members */ Relation closedRelation = DeepCopy.copy(relation); @@ -253,7 +253,7 @@ public static Relation buildClosedWays(Relation relation) throws GeoPreparationE relation.getMembers().stream() .filter(e -> e.getEntity() instanceof Way) .map(e -> (Way) e.getEntity()) - .collect(Collectors.toList()); + .toList(); /* Get an idea, of which ways do have intersections and where */ HashMap> intersections = new HashMap<>(); @@ -303,7 +303,7 @@ public static Relation buildClosedWays(Relation relation) throws GeoPreparationE intersections.entrySet().stream() .filter(e -> e.getValue().contains(currentWay)) .map(Map.Entry::getKey) - .collect(Collectors.toList()); + .toList(); Node secondIntersection; if (candidateNodes.size() > 1) throw new GeoPreparationException( @@ -372,7 +372,7 @@ else if (candidateNodes.isEmpty()) { * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static Polygon buildConvexHull( Set points, int precision, ConvexHullAlgorithm algorithm) throws GeoPreparationException { @@ -566,12 +566,10 @@ public static Polygon buildConvexHull( * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static Polygon getIntersection(Polygon a, Polygon b) { - List sharedCoords = - a.getCoords().stream().filter(b::contains).collect(Collectors.toList()); - List additionalCoords = - b.getCoords().stream().filter(a::contains).collect(Collectors.toList()); + List sharedCoords = a.getCoords().stream().filter(b::contains).toList(); + List additionalCoords = b.getCoords().stream().filter(a::contains).toList(); if (sharedCoords.isEmpty() && additionalCoords.isEmpty()) return null; else { @@ -615,7 +613,7 @@ > calcHaversine( * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static Quantity calcArea(Way w) throws GeoPreparationException { if (!w.isClosed()) throw new GeoPreparationException( @@ -633,7 +631,7 @@ public static Quantity calcArea(Way w) throws GeoPreparationException { * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static Quantity calcArea(Polygon p) throws GeoPreparationException { /* Get the boundary of the Polygon */ Bounds bounds = p.getBounds(); @@ -734,7 +732,7 @@ public static Quantity calcArea(Polygon p) throws GeoPreparationException * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static boolean isBetween(Node a, Node b, Node c) { double crossProduct; double dotProduct; @@ -779,7 +777,7 @@ public static boolean isBetween(Node a, Node b, Node c) { * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static Quantity calcGeo2qmNew(double geoArea, Quantity cor) { double width = 51.5; double length = 7.401; @@ -814,7 +812,7 @@ public static Quantity calcGeo2qmNew(double geoArea, Quantity cor) { * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static boolean isInsideLanduse(LatLon node, List landUses) { for (Way landUse : landUses) { if (rayCasting(new Polygon(landUse), node)) return true; @@ -826,7 +824,7 @@ public static boolean isInsideLanduse(LatLon node, List landUses) { * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static boolean rayCasting(Polygon shape, LatLon node) { boolean inside = false; @@ -843,7 +841,7 @@ public static boolean rayCasting(Polygon shape, LatLon node) { * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) private static boolean intersects(LatLon aIn, LatLon bIn, LatLon nIn) { // convert LatLons to arrays @@ -875,7 +873,7 @@ private static boolean intersects(LatLon aIn, LatLon bIn, LatLon nIn) { * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static double calculateBuildingArea(Way building) { double area = 0.0; @@ -913,9 +911,7 @@ public static Polygon radiusWithCircleAsPolygon(LatLon center, Quantity List circlePoints = radiusWithCircle(center, radius); List circlePointsLatLon = - circlePoints.stream() - .map(point -> new LatLon(point.getLat(), point.getLon())) - .collect(Collectors.toList()); + circlePoints.stream().map(point -> new LatLon(point.getLat(), point.getLon())).toList(); return new Polygon(circlePointsLatLon); } @@ -930,7 +926,7 @@ public static Polygon radiusWithCircleAsPolygon(LatLon center, Quantity * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static List radiusWithCircle(LatLon center, Quantity radius) { double lat1 = Math.toRadians(center.getLat()); @@ -970,7 +966,7 @@ public static List radiusWithCircle(LatLon center, Quantity radi * @deprecated ATTENTION! DON'T REMOVE: This method is currently not under test and has to be * revised thoroughly */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public static Way wayFromWays(List waysToChain, Quantity radius, int wayId) { LinkedList waysCopy = new LinkedList<>(waysToChain); diff --git a/src/main/java/edu/ie3/util/io/FileIOUtils.java b/src/main/java/edu/ie3/util/io/FileIOUtils.java index ca7469b3..38231ec8 100755 --- a/src/main/java/edu/ie3/util/io/FileIOUtils.java +++ b/src/main/java/edu/ie3/util/io/FileIOUtils.java @@ -122,7 +122,7 @@ public static BufferedWriter getBufferedWriter( * @deprecated replaced by #compressFile(Path, Path). Add ".gz" to the input path and pass it as * output filepath in compressFile() for a similar functionality. */ - @Deprecated + @Deprecated(since = "1.5", forRemoval = true) public static CompletableFuture gzip(final String filename) { return gzip(filename, ""); } @@ -138,7 +138,7 @@ public static CompletableFuture gzip(final String filename) { * @return a Future containing a boolean which is either true on success or false otherwise * @deprecated replaced by #compressFile(Path, Path) */ - @Deprecated + @Deprecated(since = "1.5", forRemoval = true) public static CompletableFuture gzip( final String filename, final String outputFileName) { return CompletableFuture.supplyAsync( diff --git a/src/main/java/edu/ie3/util/quantities/EmptyQuantity.java b/src/main/java/edu/ie3/util/quantities/EmptyQuantity.java index 1eb7656b..d710dc20 100644 --- a/src/main/java/edu/ie3/util/quantities/EmptyQuantity.java +++ b/src/main/java/edu/ie3/util/quantities/EmptyQuantity.java @@ -68,7 +68,7 @@ public Number getValue() { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public ComparableQuantity add(Quantity that) { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } @@ -83,7 +83,7 @@ public ComparableQuantity add(Quantity that) { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public ComparableQuantity subtract(Quantity that) { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } @@ -98,7 +98,7 @@ public ComparableQuantity subtract(Quantity that) { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public ComparableQuantity divide(Quantity that) { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } @@ -113,7 +113,7 @@ public ComparableQuantity divide(Quantity that) { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public ComparableQuantity divide(Number that) { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } @@ -128,7 +128,7 @@ public ComparableQuantity divide(Number that) { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public ComparableQuantity multiply(Quantity multiplier) { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } @@ -143,7 +143,7 @@ public ComparableQuantity multiply(Quantity multiplier) { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public ComparableQuantity multiply(Number multiplier) { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } @@ -157,7 +157,7 @@ public ComparableQuantity multiply(Number multiplier) { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public ComparableQuantity inverse() { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } @@ -171,7 +171,7 @@ public ComparableQuantity inverse() { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public Quantity negate() { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } @@ -206,7 +206,7 @@ public boolean equals(Object that) { * on this Quantity */ @Override - @Deprecated + @Deprecated(since = "1.4", forRemoval = false) public int hashCode() { throw new EmptyQuantityException(EXCEPTION_MESSAGE); } diff --git a/src/main/java/edu/ie3/util/quantities/QuantityUtil.java b/src/main/java/edu/ie3/util/quantities/QuantityUtil.java index 6cac1503..c8efc236 100644 --- a/src/main/java/edu/ie3/util/quantities/QuantityUtil.java +++ b/src/main/java/edu/ie3/util/quantities/QuantityUtil.java @@ -102,7 +102,7 @@ public static > boolean isEquivalentAbs( * @deprecated renamed to {@link QuantityUtil#isEquivalentAbs(Quantity, Quantity, double)} for * clarity und uniformity */ - @Deprecated + @Deprecated(since = "1.4", forRemoval = true) public static > boolean considerablyAbsEqual( Quantity a, Quantity b, double absQuantityTolerance) { return isEquivalentAbs(a, b, absQuantityTolerance); diff --git a/src/main/java/edu/ie3/util/quantities/interfaces/EnergyDensity.java b/src/main/java/edu/ie3/util/quantities/interfaces/EnergyDensity.java index d115f4a7..608d94fd 100644 --- a/src/main/java/edu/ie3/util/quantities/interfaces/EnergyDensity.java +++ b/src/main/java/edu/ie3/util/quantities/interfaces/EnergyDensity.java @@ -8,5 +8,5 @@ import tech.units.indriya.ComparableQuantity; /** @deprecated replaced by {@link Irradiation} */ -@Deprecated +@Deprecated(since = "1.5", forRemoval = true) public interface EnergyDensity extends ComparableQuantity {} diff --git a/src/main/java/edu/ie3/util/quantities/interfaces/PowerDensity.java b/src/main/java/edu/ie3/util/quantities/interfaces/PowerDensity.java index 1c821700..360de090 100644 --- a/src/main/java/edu/ie3/util/quantities/interfaces/PowerDensity.java +++ b/src/main/java/edu/ie3/util/quantities/interfaces/PowerDensity.java @@ -12,5 +12,5 @@ * * @deprecated replaced by {@link Irradiance} */ -@Deprecated +@Deprecated(since = "1.5", forRemoval = true) public interface PowerDensity extends ComparableQuantity {} diff --git a/src/test/groovy/edu/ie3/util/geo/GeoUtilsTest.groovy b/src/test/groovy/edu/ie3/util/geo/GeoUtilsTest.groovy index e1d312cc..6ea690a0 100644 --- a/src/test/groovy/edu/ie3/util/geo/GeoUtilsTest.groovy +++ b/src/test/groovy/edu/ie3/util/geo/GeoUtilsTest.groovy @@ -9,6 +9,8 @@ import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.quantities.QuantityUtil import org.locationtech.jts.geom.Coordinate import org.locationtech.jts.geom.LineString +import org.locationtech.jts.geom.Point +import org.locationtech.jts.geom.PrecisionModel import org.locationtech.jts.io.geojson.GeoJsonReader import spock.lang.Shared @@ -34,6 +36,15 @@ class GeoUtilsTest extends Specification { geoJsonReader = new GeoJsonReader() } + def "Trying to instantiate the GeoUtils leads to an exception"() { + when: + new GeoUtils() + + then: + def ex = thrown(IllegalStateException) + ex.message == "Utility classes cannot be instantiated" + } + def "Test haversine (distance between two points given lat/lon)"() { given: LatLon start = new LatLon(37.87532764735112, -122.25311279296875) @@ -64,7 +75,19 @@ class GeoUtilsTest extends Specification { // Value from Google Maps, error range of +-10 km } - def "The GridAndGeoUtils should get the CoordinateDistances between a base point and a collection of other points correctly"() { + def "LatLon can properly be converted to Point"() { + given: + def latLon = new LatLon(49d, 7d) + def expected = new Point(new Coordinate(7d, 49d), new PrecisionModel(), 4326) + + when: + def actual = GeoUtils.latlonToPoint(latLon) + + then: + actual == expected + } + + def "The GeoUtils should get the CoordinateDistances between a base point and a collection of other points correctly"() { given: def basePoint = GeoUtils.xyToPoint(49d, 7d) def points = [