1414import java .util .ArrayList ;
1515import java .util .List ;
1616import java .util .Set ;
17+ import java .util .function .Function ;
18+ import java .util .stream .Stream ;
1719import javax .measure .Quantity ;
1820
1921public 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