@@ -178,7 +178,10 @@ private void prepareGeoDataForComputation(Network network, Map<String, Substatio
178
178
neighboursToBeTreated .forEach (neighbourId -> {
179
179
if (geoDataForComputation .get (neighbourId ) == null && !substationsToCalculate .contains (neighbourId )) {
180
180
substationsToCalculate .add (neighbourId );
181
- substations .add (network .getSubstation (neighbourId ));
181
+ Substation sub = network .getSubstation (neighbourId );
182
+ if (sub != null ) {
183
+ substations .add (sub );
184
+ }
182
185
}
183
186
});
184
187
Map <String , Set <String >> newNeighbours = getNeighbours (substations );
@@ -283,17 +286,19 @@ private void step(Step step, Network network, Map<String, Set<String>> sortedNei
283
286
for (Iterator <String > it = substationsToCalculate .iterator (); it .hasNext ();) {
284
287
String substationId = it .next ();
285
288
Set <String > neighbours = sortedNeighbours .get (substationId );
286
- double neighborhoodOffset = calculatedSubstationsOffset .get (neighbours ) != null ? nextNeighborhoodOffset (calculatedSubstationsOffset .get (neighbours )) : 0 ;
287
-
288
- // centroid calculation
289
- Substation substation = network .getSubstation (substationId );
290
- SubstationGeoData substationGeoData = calculateCentroidGeoData (substation , neighbours , step , substationsGeoData , neighborhoodOffset );
291
-
292
- if (substationGeoData != null ) {
293
- calculated ++;
294
- substationsGeoData .put (substationId , substationGeoData );
295
- calculatedSubstationsOffset .put (neighbours , neighborhoodOffset );
296
- it .remove ();
289
+ if (neighbours != null ) {
290
+ double neighborhoodOffset = calculatedSubstationsOffset .get (neighbours ) != null ? nextNeighborhoodOffset (calculatedSubstationsOffset .get (neighbours )) : 0 ;
291
+
292
+ // centroid calculation
293
+ Substation substation = network .getSubstation (substationId );
294
+ SubstationGeoData substationGeoData = calculateCentroidGeoData (substation , neighbours , step , substationsGeoData , neighborhoodOffset );
295
+
296
+ if (substationGeoData != null ) {
297
+ calculated ++;
298
+ substationsGeoData .put (substationId , substationGeoData );
299
+ calculatedSubstationsOffset .put (neighbours , neighborhoodOffset );
300
+ it .remove ();
301
+ }
297
302
}
298
303
}
299
304
LOGGER .info ("Step {}, iteration {}, {} substation's coordinates have been calculated, {} remains unknown" ,
@@ -536,7 +541,12 @@ public List<LineGeoData> getLinesByIds(Network network, Set<String> linesIds) {
536
541
537
542
List <Line > lines = new ArrayList <>();
538
543
539
- linesIds .forEach (id -> lines .add (network .getLine (id )));
544
+ linesIds .forEach (id -> {
545
+ Line line = network .getLine (id );
546
+ if (line != null ) {
547
+ lines .add (line );
548
+ }
549
+ });
540
550
541
551
// read lines from DB
542
552
Map <String , LineGeoData > linesGeoDataDb = lineRepository .findAllById (linesIds ).stream ().collect (Collectors .toMap (LineEntity ::getId , this ::toDto ));
0 commit comments