Skip to content

Commit 896786d

Browse files
committed
Avoid linear scanning of the list of bay propertyBag by using a map instead
Signed-off-by: Laurent Garnier <[email protected]>
1 parent e4aaf19 commit 896786d

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

cgmes/cgmes-measurements/src/main/java/com/powsybl/cgmes/measurements/CgmesAnalogPostProcessor.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.powsybl.iidm.network.*;
1212
import com.powsybl.iidm.network.extensions.*;
1313
import com.powsybl.triplestore.api.PropertyBag;
14-
import com.powsybl.triplestore.api.PropertyBags;
14+
1515
import org.slf4j.Logger;
1616
import org.slf4j.LoggerFactory;
1717

@@ -26,7 +26,9 @@ public final class CgmesAnalogPostProcessor {
2626

2727
private static final Logger LOG = LoggerFactory.getLogger(CgmesAnalogPostProcessor.class);
2828

29-
public static void process(Network network, String id, String terminalId, String powerSystemResourceId, String measurementType, PropertyBags bays, Map<String, String> typesMapping) {
29+
public static void process(Network network, String id, String terminalId,
30+
String powerSystemResourceId, String measurementType,
31+
Map<String, PropertyBag> idToBayBag, Map<String, String> typesMapping) {
3032
if (terminalId != null) {
3133
Identifiable<?> identifiable = network.getIdentifiable(terminalId);
3234
if (identifiable != null) {
@@ -40,7 +42,7 @@ public static void process(Network network, String id, String terminalId, String
4042
createMeas(identifiable, id, terminalId, measurementType, typesMapping);
4143
return;
4244
}
43-
PropertyBag bay = bays.stream().filter(b -> b.getId("Bay").equals(powerSystemResourceId)).findFirst().orElse(null);
45+
PropertyBag bay = idToBayBag.get(powerSystemResourceId);
4446
if (bay != null) {
4547
String voltageLevelId = bay.getId("VoltageLevel");
4648
LOG.info("Power resource system {} of Analog {} is a Bay: Analog is attached to the associated voltage level {}",

cgmes/cgmes-measurements/src/main/java/com/powsybl/cgmes/measurements/CgmesDiscretePostProcessor.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.powsybl.iidm.network.*;
1111
import com.powsybl.iidm.network.extensions.*;
1212
import com.powsybl.triplestore.api.PropertyBag;
13-
import com.powsybl.triplestore.api.PropertyBags;
13+
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
1616

@@ -27,7 +27,9 @@ public final class CgmesDiscretePostProcessor {
2727

2828
private static final Logger LOG = LoggerFactory.getLogger(CgmesDiscretePostProcessor.class);
2929

30-
public static void process(Network network, String id, String terminalId, String powerSystemResourceId, String measurementType, PropertyBags bays, Map<String, String> typesMapping) {
30+
public static void process(Network network, String id, String terminalId,
31+
String powerSystemResourceId, String measurementType,
32+
Map<String, PropertyBag> idToBayBag, Map<String, String> typesMapping) {
3133
if (terminalId != null) {
3234
Identifiable<?> identifiable = network.getIdentifiable(terminalId);
3335
if (identifiable != null) {
@@ -41,7 +43,7 @@ public static void process(Network network, String id, String terminalId, String
4143
createDisMeas(identifiable, id, measurementType, typesMapping);
4244
return;
4345
}
44-
PropertyBag bay = bays.stream().filter(b -> b.getId("Bay").equals(powerSystemResourceId)).findFirst().orElse(null);
46+
PropertyBag bay = idToBayBag.get(powerSystemResourceId);
4547
if (bay != null) {
4648
String voltageLevelId = bay.getId("VoltageLevel");
4749
LOG.info("Power resource system {} of Discrete {} is a Bay: Discrete is attached to the associated voltage level {}",

cgmes/cgmes-measurements/src/main/java/com/powsybl/cgmes/measurements/CgmesMeasurementsPostProcessor.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,24 @@ public String getName() {
6262
public void process(Network network, TripleStore tripleStore) {
6363
CgmesMeasurementsModel model = new CgmesMeasurementsModel(tripleStore);
6464
PropertyBags bays = model.bays();
65+
Map<String, PropertyBag> idToBayBag = bays.stream().collect(Collectors.toMap(b -> b.getId("Bay"), b -> b));
66+
Map<String, String> analogTypesMapping = createTypesMapping(
67+
Parameter.readStringList("CGMES", null, ANALOG_TYPES_MAPPING_PARAMETER, defaultValueConfig));
6568
for (PropertyBag analog : model.analogs()) {
6669
CgmesAnalogPostProcessor.process(network, analog.getId("Analog"), analog.getId("Terminal"),
6770
analog.getId("powerSystemResource"),
6871
analog.getId("type"),
69-
bays,
70-
createTypesMapping(Parameter.readStringList("CGMES", null, ANALOG_TYPES_MAPPING_PARAMETER, defaultValueConfig)));
72+
idToBayBag,
73+
analogTypesMapping);
7174
}
75+
Map<String, String> discreteTypesMapping = createTypesMapping(
76+
Parameter.readStringList("CGMES", null, DISCRETE_TYPES_MAPPING_PARAMETER, defaultValueConfig));
7277
for (PropertyBag discrete : model.discretes()) {
7378
CgmesDiscretePostProcessor.process(network, discrete.getId("Discrete"), discrete.getId("Terminal"),
7479
discrete.getId("powerSystemResource"),
7580
discrete.getId("type"),
76-
bays,
77-
createTypesMapping(Parameter.readStringList("CGMES", null, DISCRETE_TYPES_MAPPING_PARAMETER, defaultValueConfig)));
81+
idToBayBag,
82+
discreteTypesMapping);
7883
}
7984
}
8085

0 commit comments

Comments
 (0)