diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTopology.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTopology.java index 63f36ad07..7d1fc553a 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTopology.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTopology.java @@ -367,24 +367,20 @@ private void getVAndAngleFromConfiguredBus(NetworkObjectIndex index, ConnectedSetResult connectedSet, AtomicDouble v, AtomicDouble angle) { - AtomicReference foundConfiguredBus = new AtomicReference<>(); - index.getConfiguredBuses(voltageLevelResource.getId()).forEach(bus -> { - if (foundConfiguredBus.get() == null) { - ConfiguredBusImpl configuredBus = (ConfiguredBusImpl) bus; - configuredBus.getAllTerminals().stream() - .filter(Terminal::isConnected) - .forEach(t -> { - if (foundConfiguredBus.get() == null) { - connectedSet.getConnectedVertices().stream().filter(vertex -> - vertex.getId().equals(t.getConnectable().getId()) - ).findFirst().ifPresent(vertex -> foundConfiguredBus.set(configuredBus)); + // Search with early return for a first configured bus with a connected terminal matching a vertex in the connectedSet of this bus + for (Bus bus: index.getConfiguredBuses(voltageLevelResource.getId())) { + ConfiguredBusImpl configuredBus = (ConfiguredBusImpl) bus; + for (Terminal t: configuredBus.getAllTerminals()) { + if (t.isConnected()) { + for (Vertex vertex: connectedSet.getConnectedVertices()) { + if (vertex.getId().equals(t.getConnectable().getId())) { + v.set(configuredBus.getResource().getAttributes().getV()); + angle.set(configuredBus.getResource().getAttributes().getAngle()); + return; } - }); + } + } } - }); - if (foundConfiguredBus.get() != null) { - v.set(foundConfiguredBus.get().getResource().getAttributes().getV()); - angle.set(foundConfiguredBus.get().getResource().getAttributes().getAngle()); } } @@ -394,11 +390,14 @@ private void getVAndAngleFromOtherView(NetworkObjectIndex index, AtomicDouble v, AtomicDouble angle, boolean isBusView) { - // TODO Some day we may decide to start preserving values in nodebreaker topology after invalidating the views, - // so we could remove this check for isCalculatedBusesValid. Here it controls preserving - // the value accross the other view, we have it to be consistent with preserving values - // from the same view (currently not preserved) - if (voltageLevelResource.getAttributes().getTopologyKind() == TopologyKind.NODE_BREAKER && voltageLevelResource.getAttributes().isCalculatedBusesValid()) { + if (voltageLevelResource.getAttributes().getTopologyKind() == TopologyKind.NODE_BREAKER) { + if (!voltageLevelResource.getAttributes().isCalculatedBusesValid()) { + // TODO Some day we may decide to start preserving values in nodebreaker topology after invalidating the views, + // so we could remove this check for isCalculatedBusesValid. Here it controls preserving + // the value accross the other view, we have it to be consistent with preserving values + // from the same view (currently not preserved) + return; + } List calculatedBusAttributes = isBusView ? voltageLevelResource.getAttributes().getCalculatedBusesForBusBreakerView() : voltageLevelResource.getAttributes().getCalculatedBusesForBusView(); if (!CollectionUtils.isEmpty(calculatedBusAttributes)) { Map nodesToCalculatedBuses = isBusView ? voltageLevelResource.getAttributes().getNodeToCalculatedBusForBusBreakerView() : voltageLevelResource.getAttributes().getNodeToCalculatedBusForBusView();