Skip to content

Commit

Permalink
Review 2
Browse files Browse the repository at this point in the history
Signed-off-by: Slimane AMAR <amarsli@gm0winl104.bureau.si.interne>
  • Loading branch information
Slimane AMAR committed Feb 7, 2025
1 parent c30f85f commit 99fea07
Showing 1 changed file with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,15 @@ private void flushEquipmentInfos() {
equipmentInfosService.addAllEquipmentInfos(modifiedEquipments);
}

private List<? extends AbstractBaseImpact> reduceDeletionImpacts() {
List<SimpleElementImpact> deletionImpacts = getDeletionSimpleImpacts();
return (getImpactedSubstationIds(deletionImpacts).size() >= collectionThreshold) ? getFullNetworkImpact() : deletionImpacts;
}

private List<AbstractBaseImpact> reduceNoDeletionImpacts() {
private List<AbstractBaseImpact> reduceNetworkImpacts() {
List<AbstractBaseImpact> reducedImpacts = new ArrayList<>();
Set<String> impactedSubstationsIds = new HashSet<>();
List<SimpleElementImpact> deletionImpacts = getDeletionSimpleImpacts();

// All network is impacted by deletions
if (getImpactedSubstationIds(deletionImpacts).size() >= collectionThreshold) {
getFullNetworkImpact();
}

// Group simple impacts over same element type into collection impact
// And compute impactedSubstationsIds on the way
Expand All @@ -290,7 +291,7 @@ private List<AbstractBaseImpact> reduceNoDeletionImpacts() {
}
}

// All network is impacted ? then return only one substation collection impact
// All network is impacted by modifications and/or creations
if (impactedSubstationsIds.size() >= collectionThreshold) {
return getFullNetworkImpact();
}
Expand All @@ -307,23 +308,8 @@ private List<AbstractBaseImpact> reduceNoDeletionImpacts() {
).toList()
);

return reducedImpacts;
}

private List<AbstractBaseImpact> reduceNetworkImpacts() {

List<? extends AbstractBaseImpact> reducedDeletionImpacts = reduceDeletionImpacts();
if (isAllNetworkImpacted(reducedDeletionImpacts)) {
return getFullNetworkImpact();
}

List<AbstractBaseImpact> reducedModificationImpacts = reduceNoDeletionImpacts();
if (isAllNetworkImpacted(reducedModificationImpacts)) {
return getFullNetworkImpact();
}

// fuse both reduced impacts
return Stream.concat(reducedModificationImpacts.stream(), reducedDeletionImpacts.stream()).toList();
// Fuse both reduced impacts
return Stream.concat(reducedImpacts.stream(), deletionImpacts.stream()).toList();
}

private List<AbstractBaseImpact> getFullNetworkImpact() {
Expand All @@ -332,13 +318,6 @@ private List<AbstractBaseImpact> getFullNetworkImpact() {
.build());
}

private boolean isAllNetworkImpacted(List<? extends AbstractBaseImpact> impacts) {
return impacts.stream()
.filter(AbstractBaseImpact::isCollection)
.filter(c -> c.getElementType() == IdentifiableType.SUBSTATION)
.count() > 0;
}

private Set<String> getImpactedSubstationIds(List<SimpleElementImpact> impacts) {
Set<String> impactedSubstationsIds = new HashSet<>();
impactedSubstationsIds.addAll(impacts.stream().flatMap(i -> i.getSubstationIds().stream()).toList());
Expand Down

0 comments on commit 99fea07

Please sign in to comment.