Skip to content

Increase code quality #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
10 changes: 5 additions & 5 deletions gradle/scripts/jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/sonarqube.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/edu/ie3/util/EmpiricalRandom.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
40 changes: 18 additions & 22 deletions src/main/java/edu/ie3/util/geo/GeoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Node, Set<Way>> intersections = new HashMap<>();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<Point> points, int precision, ConvexHullAlgorithm algorithm)
throws GeoPreparationException {
Expand Down Expand Up @@ -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<LatLon> sharedCoords =
a.getCoords().stream().filter(b::contains).collect(Collectors.toList());
List<LatLon> additionalCoords =
b.getCoords().stream().filter(a::contains).collect(Collectors.toList());
List<LatLon> sharedCoords = a.getCoords().stream().filter(b::contains).toList();
List<LatLon> additionalCoords = b.getCoords().stream().filter(a::contains).toList();

if (sharedCoords.isEmpty() && additionalCoords.isEmpty()) return null;
else {
Expand Down Expand Up @@ -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<Area> calcArea(Way w) throws GeoPreparationException {
if (!w.isClosed())
throw new GeoPreparationException(
Expand All @@ -633,7 +631,7 @@ public static Quantity<Area> 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<Area> calcArea(Polygon p) throws GeoPreparationException {
/* Get the boundary of the Polygon */
Bounds bounds = p.getBounds();
Expand Down Expand Up @@ -734,7 +732,7 @@ public static Quantity<Area> 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;
Expand Down Expand Up @@ -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<Area> calcGeo2qmNew(double geoArea, Quantity<Area> cor) {
double width = 51.5;
double length = 7.401;
Expand Down Expand Up @@ -814,7 +812,7 @@ public static Quantity<Area> calcGeo2qmNew(double geoArea, Quantity<Area> 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<Way> landUses) {
for (Way landUse : landUses) {
if (rayCasting(new Polygon(landUse), node)) return true;
Expand All @@ -826,7 +824,7 @@ public static boolean isInsideLanduse(LatLon node, List<Way> 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;

Expand All @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -913,9 +911,7 @@ public static Polygon radiusWithCircleAsPolygon(LatLon center, Quantity<Length>
List<LatLon> circlePoints = radiusWithCircle(center, radius);

List<LatLon> 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);
}
Expand All @@ -930,7 +926,7 @@ public static Polygon radiusWithCircleAsPolygon(LatLon center, Quantity<Length>
* @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<LatLon> radiusWithCircle(LatLon center, Quantity<Length> radius) {

double lat1 = Math.toRadians(center.getLat());
Expand Down Expand Up @@ -970,7 +966,7 @@ public static List<LatLon> radiusWithCircle(LatLon center, Quantity<Length> 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<Way> waysToChain, Quantity<Length> radius, int wayId) {

LinkedList<Way> waysCopy = new LinkedList<>(waysToChain);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/ie3/util/io/FileIOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> gzip(final String filename) {
return gzip(filename, "");
}
Expand All @@ -138,7 +138,7 @@ public static CompletableFuture<Boolean> 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<Boolean> gzip(
final String filename, final String outputFileName) {
return CompletableFuture.supplyAsync(
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/edu/ie3/util/quantities/EmptyQuantity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Number getValue() {
* on this Quantity
*/
@Override
@Deprecated
@Deprecated(since = "1.4", forRemoval = false)
public ComparableQuantity<Q> add(Quantity<Q> that) {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}
Expand All @@ -83,7 +83,7 @@ public ComparableQuantity<Q> add(Quantity<Q> that) {
* on this Quantity
*/
@Override
@Deprecated
@Deprecated(since = "1.4", forRemoval = false)
public ComparableQuantity<Q> subtract(Quantity<Q> that) {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}
Expand All @@ -98,7 +98,7 @@ public ComparableQuantity<Q> subtract(Quantity<Q> that) {
* on this Quantity
*/
@Override
@Deprecated
@Deprecated(since = "1.4", forRemoval = false)
public ComparableQuantity<?> divide(Quantity<?> that) {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}
Expand All @@ -113,7 +113,7 @@ public ComparableQuantity<?> divide(Quantity<?> that) {
* on this Quantity
*/
@Override
@Deprecated
@Deprecated(since = "1.4", forRemoval = false)
public ComparableQuantity<Q> divide(Number that) {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}
Expand All @@ -128,7 +128,7 @@ public ComparableQuantity<Q> divide(Number that) {
* on this Quantity
*/
@Override
@Deprecated
@Deprecated(since = "1.4", forRemoval = false)
public ComparableQuantity<?> multiply(Quantity<?> multiplier) {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}
Expand All @@ -143,7 +143,7 @@ public ComparableQuantity<?> multiply(Quantity<?> multiplier) {
* on this Quantity
*/
@Override
@Deprecated
@Deprecated(since = "1.4", forRemoval = false)
public ComparableQuantity<Q> multiply(Number multiplier) {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}
Expand All @@ -157,7 +157,7 @@ public ComparableQuantity<Q> multiply(Number multiplier) {
* on this Quantity
*/
@Override
@Deprecated
@Deprecated(since = "1.4", forRemoval = false)
public ComparableQuantity<?> inverse() {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}
Expand All @@ -171,7 +171,7 @@ public ComparableQuantity<?> inverse() {
* on this Quantity
*/
@Override
@Deprecated
@Deprecated(since = "1.4", forRemoval = false)
public Quantity<Q> negate() {
throw new EmptyQuantityException(EXCEPTION_MESSAGE);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/ie3/util/quantities/QuantityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static <Q extends Quantity<Q>> boolean isEquivalentAbs(
* @deprecated renamed to {@link QuantityUtil#isEquivalentAbs(Quantity, Quantity, double)} for
* clarity und uniformity
*/
@Deprecated
@Deprecated(since = "1.4", forRemoval = true)
public static <Q extends Quantity<Q>> boolean considerablyAbsEqual(
Quantity<Q> a, Quantity<Q> b, double absQuantityTolerance) {
return isEquivalentAbs(a, b, absQuantityTolerance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnergyDensity> {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
*
* @deprecated replaced by {@link Irradiance}
*/
@Deprecated
@Deprecated(since = "1.5", forRemoval = true)
public interface PowerDensity extends ComparableQuantity<PowerDensity> {}
25 changes: 24 additions & 1 deletion src/test/groovy/edu/ie3/util/geo/GeoUtilsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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 = [
Expand Down