Skip to content

Commit 46fc1b1

Browse files
authored
Merge branch 'dev' into ms/#827-use-java-streams-on-sql-fetsches-effectively
2 parents ba15e89 + ffe05f0 commit 46fc1b1

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Added test for invalid input data in `CsvRawGridSource` [#1021](https://github.com/ie3-institute/PowerSystemDataModel/issues/1021)
2424
- Added `CsvThermalGridSource` [#1009](https://github.com/ie3-institute/PowerSystemDataModel/issues/1009)
2525
- Enhance documentation for CSV timeseries [#825](https://github.com/ie3-institute/PowerSystemDataModel/issues/825)
26+
- Enhancing `VoltageLevel` with `equals` method [#1063](https://github.com/ie3-institute/PowerSystemDataModel/issues/1063)
2627

2728
### Fixed
2829
- Fixed Couchbase integration tests that randomly failed [#755](https://github.com/ie3-institute/PowerSystemDataModel/issues/755)

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
id 'signing'
66
id 'pmd' // code check, working on source code
77
id 'com.diffplug.spotless' version '6.25.0' //code format
8-
id 'com.github.spotbugs' version '6.0.10' // code check, working on byte code
8+
id 'com.github.spotbugs' version '6.0.11' // code check, working on byte code
99
id 'de.undercouch.download' version '5.6.0'
1010
id 'kr.motd.sphinx' version '2.10.1' // documentation generation
1111
id 'jacoco' // java code coverage plugin
@@ -17,7 +17,7 @@ ext {
1717
//version (changing these should be considered thoroughly!)
1818
javaVersion = JavaVersion.VERSION_17
1919
groovyVersion = "4.0"
20-
groovyBinaryVersion = "4.0.20"
20+
groovyBinaryVersion = "4.0.21"
2121
testcontainersVersion = '1.19.7'
2222

2323
scriptsLocation = 'gradle' + File.separator + 'scripts' + File.separator //location of script plugins

src/main/java/edu/ie3/datamodel/models/voltagelevels/CommonVoltageLevel.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
import edu.ie3.datamodel.exceptions.VoltageLevelException;
99
import edu.ie3.util.interval.RightOpenInterval;
10-
import java.util.Collections;
11-
import java.util.Set;
12-
import java.util.SortedSet;
13-
import java.util.TreeSet;
10+
import java.util.*;
1411
import javax.measure.quantity.ElectricPotential;
1512
import tech.units.indriya.ComparableQuantity;
1613

@@ -79,6 +76,21 @@ public boolean covers(String id, ComparableQuantity<ElectricPotential> vRated)
7976
return idCovered; /* voltage covered is always true, otherwise the exception would have been thrown. */
8077
}
8178

79+
@Override
80+
public boolean equals(Object o) {
81+
if (this == o) return true;
82+
if (o == null || getClass() != o.getClass()) return false;
83+
if (!super.equals(o)) return false;
84+
85+
CommonVoltageLevel that = (CommonVoltageLevel) o;
86+
return this.voltageRange.equals(that.voltageRange);
87+
}
88+
89+
@Override
90+
public int hashCode() {
91+
return Objects.hash(super.hashCode(), synonymousIds, voltageRange);
92+
}
93+
8294
@Override
8395
public String toString() {
8496
return "CommonVoltageLevel{"

src/main/java/edu/ie3/datamodel/models/voltagelevels/VoltageLevel.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package edu.ie3.datamodel.models.voltagelevels;
77

88
import java.io.Serializable;
9+
import java.util.Objects;
910
import javax.measure.quantity.ElectricPotential;
1011
import tech.units.indriya.ComparableQuantity;
1112

@@ -47,6 +48,20 @@ public ComparableQuantity<ElectricPotential> getNominalVoltage() {
4748
return nominalVoltage;
4849
}
4950

51+
@Override
52+
public boolean equals(Object o) {
53+
if (this == o) return true;
54+
if (o == null || getClass() != o.getClass()) return false;
55+
56+
VoltageLevel that = (VoltageLevel) o;
57+
return this.nominalVoltage.isEquivalentTo(that.nominalVoltage);
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return Objects.hash(id, nominalVoltage);
63+
}
64+
5065
@Override
5166
public String toString() {
5267
return "VoltageLevel{" + "id='" + id + '\'' + ", nominalVoltage=" + nominalVoltage + '}';

src/test/groovy/edu/ie3/datamodel/models/CommonVoltageLevelTest.groovy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import static tech.units.indriya.unit.Units.VOLT
1010

1111
import edu.ie3.datamodel.exceptions.VoltageLevelException
1212
import edu.ie3.datamodel.models.voltagelevels.CommonVoltageLevel
13+
import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils
14+
import edu.ie3.datamodel.models.voltagelevels.VoltageLevel
1315
import edu.ie3.util.interval.RightOpenInterval
1416
import spock.lang.Shared
1517
import spock.lang.Specification
@@ -57,4 +59,24 @@ class CommonVoltageLevelTest extends Specification {
5759
VoltageLevelException ex = thrown()
5860
ex.message == "The provided id \"HS\" and rated voltage \"500 V\" could possibly meet the voltage level \"Niederspannung\" (Interval [0.0 kV, 10 kV)), but are inconsistent."
5961
}
62+
63+
def "A common voltage level should test the equality correctly"() {
64+
given:
65+
def mv = GermanVoltageLevelUtils.MV_10KV
66+
67+
expect:
68+
mv == new CommonVoltageLevel(
69+
"MS",
70+
Quantities.getQuantity(10d, KILOVOLT),
71+
new HashSet<>(Arrays.asList("mv_10kV")),
72+
new RightOpenInterval<>(Quantities.getQuantity(10d, KILOVOLT), Quantities.getQuantity(20d, KILOVOLT)))
73+
74+
75+
mv != new CommonVoltageLevel("MS",
76+
Quantities.getQuantity(10d, KILOVOLT),
77+
new HashSet<>(Arrays.asList("mv")),
78+
new RightOpenInterval<>(Quantities.getQuantity(10d, KILOVOLT), Quantities.getQuantity(19.9, KILOVOLT)))
79+
80+
mv != new VoltageLevel("mv", Quantities.getQuantity(10d, KILOVOLT))
81+
}
6082
}

0 commit comments

Comments
 (0)