Skip to content

Commit 4eab5be

Browse files
Merge pull request #1550 from ie3-institute/df/#1549-thermalGrid-validation
Small harmonisation in `ThermalGrid` validation
2 parents 78e7af4 + edf5654 commit 4eab5be

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
133133
- Replaced `LoadProfileInput` with `LoadProfileTimeSeries` [#1228](https://github.com/ie3-institute/PowerSystemDataModel/issues/1228)
134134
- Enhance `CsvDataSource` [#1246](https://github.com/ie3-institute/PowerSystemDataModel/issues/1246)
135135
- Updated `_joint_grid` csv files from simona [#750](https://github.com/ie3-institute/PowerSystemDataModel/issues/750)
136+
- Small harmonisation in `ThermalGrid` validation [#1549](https://github.com/ie3-institute/PowerSystemDataModel/issues/1549)
136137

137138
### Updates
138139
- Updated gradle to v8.13 [#1264](https://github.com/ie3-institute/PowerSystemDataModel/issues/1264)

src/main/java/edu/ie3/datamodel/utils/validation/ThermalValidationUtils.java

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.ArrayList;
1515
import java.util.List;
1616
import java.util.Set;
17+
import java.util.function.Function;
18+
import java.util.stream.Stream;
1719
import javax.measure.Quantity;
1820

1921
public class ThermalValidationUtils extends ValidationUtils {
@@ -24,7 +26,7 @@ private ThermalValidationUtils() {
2426
}
2527

2628
/**
27-
* Validates a thermal unit if:
29+
* Validates a thermal grid if:
2830
*
2931
* <ul>
3032
* <li>it is not null
@@ -33,34 +35,28 @@ private ThermalValidationUtils() {
3335
* A "distribution" method, that forwards the check request to specific implementations to fulfill
3436
* the checking task, based on the class of the given object.
3537
*
36-
* @param thermalUnitInput ThermalUnitInput to validate
38+
* @param thermalGrid ThermalGrid to validate
3739
* @return a list of try objects either containing an {@link ValidationException} or an empty
3840
* Success
3941
*/
40-
protected static List<Try<Void, ? extends ValidationException>> check(
41-
ThermalUnitInput thermalUnitInput) {
42-
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalUnitInput, "a thermal unit");
42+
protected static List<Try<Void, ? extends ValidationException>> check(ThermalGrid thermalGrid) {
43+
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalGrid, "a thermal grid");
4344

4445
if (isNull.isFailure()) {
4546
return List.of(isNull);
4647
}
4748

48-
List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();
49-
50-
// Further checks for subclasses
51-
if (ThermalSinkInput.class.isAssignableFrom(thermalUnitInput.getClass())) {
52-
exceptions.addAll(checkThermalSink((ThermalSinkInput) thermalUnitInput));
53-
} else if (ThermalStorageInput.class.isAssignableFrom(thermalUnitInput.getClass())) {
54-
exceptions.addAll(checkThermalStorage((ThermalStorageInput) thermalUnitInput));
55-
} else {
56-
logNotImplemented(thermalUnitInput);
57-
}
58-
59-
return exceptions;
49+
return Stream.of(
50+
thermalGrid.houses().stream().map(ThermalValidationUtils::check),
51+
thermalGrid.heatStorages().stream().map(ThermalValidationUtils::check),
52+
thermalGrid.domesticHotWaterStorages().stream().map(ThermalValidationUtils::check))
53+
.flatMap(Function.identity())
54+
.flatMap(List::stream)
55+
.toList();
6056
}
6157

6258
/**
63-
* Validates a thermal grid if:
59+
* Validates a thermal unit if:
6460
*
6561
* <ul>
6662
* <li>it is not null
@@ -69,32 +65,27 @@ private ThermalValidationUtils() {
6965
* A "distribution" method, that forwards the check request to specific implementations to fulfill
7066
* the checking task, based on the class of the given object.
7167
*
72-
* @param thermalGrid ThermalGrid to validate
68+
* @param thermalUnitInput ThermalUnitInput to validate
7369
* @return a list of try objects either containing an {@link ValidationException} or an empty
7470
* Success
7571
*/
76-
protected static List<Try<Void, ? extends ValidationException>> check(ThermalGrid thermalGrid) {
77-
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalGrid, "a thermal grid");
72+
protected static List<Try<Void, ? extends ValidationException>> check(
73+
ThermalUnitInput thermalUnitInput) {
74+
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalUnitInput, "a thermal unit");
7875

7976
if (isNull.isFailure()) {
8077
return List.of(isNull);
8178
}
8279

8380
List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();
8481

85-
// Validate houses
86-
for (ThermalHouseInput house : thermalGrid.houses()) {
87-
exceptions.addAll(checkThermalHouse(house));
88-
}
89-
90-
// Validate heat storages
91-
for (ThermalStorageInput storage : thermalGrid.heatStorages()) {
92-
exceptions.addAll(check(storage));
93-
}
94-
95-
// Validate domestic hot water storages
96-
for (ThermalStorageInput storage : thermalGrid.domesticHotWaterStorages()) {
97-
exceptions.addAll(check(storage));
82+
// Further checks for subclasses
83+
if (ThermalSinkInput.class.isAssignableFrom(thermalUnitInput.getClass())) {
84+
exceptions.addAll(checkThermalSink((ThermalSinkInput) thermalUnitInput));
85+
} else if (ThermalStorageInput.class.isAssignableFrom(thermalUnitInput.getClass())) {
86+
exceptions.addAll(checkThermalStorage((ThermalStorageInput) thermalUnitInput));
87+
} else {
88+
logNotImplemented(thermalUnitInput);
9889
}
9990

10091
return exceptions;

0 commit comments

Comments
 (0)