-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lisrte <[email protected]>
- Loading branch information
Showing
12 changed files
with
193 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/BuilderEquipmentsList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com/) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.dynawaltz.builders; | ||
|
||
import com.powsybl.commons.reporter.Reporter; | ||
import com.powsybl.iidm.network.Identifiable; | ||
import com.powsybl.iidm.network.IdentifiableType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>} | ||
*/ | ||
public class BuilderEquipmentsList<T extends Identifiable<?>> { | ||
|
||
private final String equipmentType; | ||
private final String fieldName; | ||
// when set to true equipment ids not found in the network are seen as dynamic ids for automatons and reported as such | ||
private final boolean missingIdsHasDynamicIds; | ||
protected List<String> missingEquipmentIds = new ArrayList<>(); | ||
protected final List<T> equipments = new ArrayList<>(); | ||
|
||
public BuilderEquipmentsList(IdentifiableType identifiableType, String fieldName) { | ||
this(identifiableType.toString(), fieldName, false); | ||
} | ||
|
||
public BuilderEquipmentsList(String equipmentType, String fieldName) { | ||
this(equipmentType, fieldName, false); | ||
} | ||
|
||
public BuilderEquipmentsList(String equipmentType, String fieldName, boolean missingIdsHasDynamicIds) { | ||
this.equipmentType = equipmentType; | ||
this.fieldName = fieldName; | ||
this.missingIdsHasDynamicIds = missingIdsHasDynamicIds; | ||
} | ||
|
||
public void addEquipments(String[] staticIds, Function<String, T> equipmentsSupplier) { | ||
addEquipments(() -> Arrays.stream(staticIds).iterator(), equipmentsSupplier); | ||
} | ||
|
||
public void addEquipments(Iterable<String> staticIds, Function<String, T> equipmentsSupplier) { | ||
staticIds.forEach(id -> { | ||
T equipment = equipmentsSupplier.apply(id); | ||
if (equipment != null) { | ||
equipments.add(equipment); | ||
} else { | ||
missingEquipmentIds.add(id); | ||
} | ||
}); | ||
} | ||
|
||
public boolean checkEquipmentData(Reporter reporter) { | ||
boolean emptyList = equipments.isEmpty(); | ||
if (missingEquipmentIds.isEmpty() && emptyList) { | ||
Reporters.reportFieldNotSet(reporter, fieldName); | ||
return false; | ||
} else if (!missingIdsHasDynamicIds) { | ||
missingEquipmentIds.forEach(missingId -> | ||
Reporters.reportStaticIdUnknown(reporter, fieldName, missingId, equipmentType)); | ||
if (emptyList) { | ||
Reporters.reportEmptyList(reporter, fieldName); | ||
} | ||
return !emptyList; | ||
} else { | ||
missingEquipmentIds.forEach(missingId -> | ||
Reporters.reportUnknownStaticIdHandling(reporter, fieldName, missingId, equipmentType)); | ||
return true; | ||
} | ||
} | ||
|
||
public List<T> getEquipments() { | ||
return equipments; | ||
} | ||
|
||
public List<String> getMissingEquipmentIds() { | ||
return missingEquipmentIds; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/BuilderIdListEquipmentList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com/) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.dynawaltz.builders; | ||
|
||
import com.powsybl.iidm.network.Identifiable; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>} | ||
*/ | ||
public class BuilderIdListEquipmentList<T extends Identifiable<?>> extends BuilderEquipmentsList<T> { | ||
|
||
public BuilderIdListEquipmentList(String equipmentType, String fieldName) { | ||
super(equipmentType, fieldName); | ||
} | ||
|
||
public void addEquipments(Collection<String>[] staticIdsArray, Function<String, T> equipmentSupplier) { | ||
for (Collection<String> staticIds : staticIdsArray) { | ||
addEquipment(staticIds, equipmentSupplier); | ||
} | ||
} | ||
|
||
private void addEquipment(Collection<String> staticIds, Function<String, T> equipmentSupplier) { | ||
staticIds.stream() | ||
.map(equipmentSupplier) | ||
.filter(Objects::nonNull) | ||
.findFirst() | ||
.ifPresentOrElse(equipments::add, | ||
() -> missingEquipmentIds.add(staticIds.toString())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.