Skip to content

Commit

Permalink
Use stream in checkDuplicateStaticId
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte authored and flo-dup committed Sep 26, 2023
1 parent 254b55e commit 6c4bcfd
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxM
.filter(EquipmentBlackBoxModel.class::isInstance)
.map(EquipmentBlackBoxModel.class::cast)
.collect(Collectors.toMap(EquipmentBlackBoxModel::getStaticId,
Function.identity(),
(bbm1, bbm2) -> {
throw new PowsyblException("Duplicate staticId: " + bbm1.getStaticId());
},
LinkedHashMap::new));
Function.identity(),
(bbm1, bbm2) -> {
throw new PowsyblException("Duplicate staticId: " + bbm1.getStaticId());
},
LinkedHashMap::new));
this.curves = Objects.requireNonNull(curves);
this.parameters = Objects.requireNonNull(parameters);
this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters);
Expand Down Expand Up @@ -170,18 +170,18 @@ public <T extends Model> T getPureDynamicModel(String dynamicId, Class<T> connec

private static List<BlackBoxModel> checkDuplicateStaticId(List<BlackBoxModel> dynamicModels) {
Set<String> staticIds = new HashSet<>();
Set<BlackBoxModel> duplicates = new HashSet<>();
for (BlackBoxModel bbm : dynamicModels) {
if (bbm instanceof EquipmentBlackBoxModel) {
EquipmentBlackBoxModel eBbm = (EquipmentBlackBoxModel) bbm;
if (!staticIds.add(eBbm.getStaticId())) {
duplicates.add(eBbm);
LOGGER.warn("Duplicate static id found: {} -> dynamic model {} {} will be skipped", eBbm.getStaticId(), eBbm.getLib(), eBbm.getDynamicModelId());
}
}
}
dynamicModels.removeAll(duplicates);
return dynamicModels;
return dynamicModels.stream()
.filter(bbm -> {
if (bbm instanceof EquipmentBlackBoxModel) {
EquipmentBlackBoxModel eBbm = (EquipmentBlackBoxModel) bbm;
if (!staticIds.add(eBbm.getStaticId())) {
LOGGER.warn("Duplicate static id found: {} -> dynamic model {} {} will be skipped", eBbm.getStaticId(), eBbm.getLib(), eBbm.getDynamicModelId());
return false;
}
}
return true;
})
.collect(Collectors.toList());
}

private static List<BlackBoxModel> checkEventModelIdUniqueness(List<BlackBoxModel> eventModels) {
Expand Down

0 comments on commit 6c4bcfd

Please sign in to comment.