-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor PSS/E duplicated ID handling #3643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…per ID Signed-off-by: Petr Janecek <[email protected]>
| } | ||
|
|
||
| private static void testInvalid(String resourcePath, String sample, String message) { | ||
| PsseException exception = Assertions.assertThrows(PsseException.class, () -> load(resourcePath, sample)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method is unused, you can remove it.
| unique.add(psseObject); | ||
| } | ||
| foundIds.add(id); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your method is perfectly valid, but since the map values are never null, we can simplify it a bit to be faster. Here is my proposal:
private <T> List<T> fixDuplicatedIds(List<T> psseObjects, Function<T, String> idBuilder, String elementTypeName) {
List<T> unique = new ArrayList<>();
Map<String, Integer> indexes = new HashMap<>();
psseObjects.forEach(psseObject -> {
var id = idBuilder.apply(psseObject);
Integer index = indexes.get(id);
if (index != null) {
LOGGER.warn("Duplicated {} Id: {}", elementTypeName, id);
unique.set(index, psseObject);
} else {
indexes.put(id, unique.size());
unique.add(psseObject);
}
});
return unique;
}
| @FunctionalInterface | ||
| public interface IdFixer<T> { | ||
| String fix(T t, Set<String> usedIds); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thinl this method is not used, we can remove it
|
I checked the performance by importing a large case, and I didn’t see any impact. |
|



Please check if the PR fulfills these requirements
Does this PR already have an issue describing the problem?
#3607
What kind of change does this PR introduce?
Refactor PSS/E duplicated ID handling.
What is the current behavior?
In the previous implementation, when a data record with the same ID was found, its ID was modified and a new element was created. This does not match PSS/E behavior, which in such cases updates the data of the existing element.
What is the new behavior (if this is a feature change)?
The new implementation uses a "last record wins" strategy - when a duplicate ID is encountered in the data, the last occurrence replaces all previous ones.
Does this PR introduce a breaking change or deprecate an API?
If yes, please check if the following requirements are fulfilled
What changes might users need to make in their application due to this PR? (migration steps)
Other information: