mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-07 12:24:58 +10:00
fix issue with null objects in groups
This commit is contained in:
@@ -164,8 +164,12 @@ public class Project implements Serializable, Cloneable {
|
||||
|
||||
if (groups != null && !groups.isEmpty()) {
|
||||
for (Set<IDIYComponent<?>> group : groups) {
|
||||
ComponentGroup newGroup = ComponentGroup.from(group, null);
|
||||
groupsEx.add(newGroup);
|
||||
Set<IDIYComponent<?>> nonNullIds =
|
||||
group.stream().filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
if (!nonNullIds.isEmpty()) {
|
||||
ComponentGroup newGroup = ComponentGroup.from(group, null);
|
||||
groupsEx.add(newGroup);
|
||||
}
|
||||
}
|
||||
groups.clear();
|
||||
}
|
||||
|
||||
@@ -278,8 +278,6 @@ public class Presenter implements IPlugInPort {
|
||||
drawingManager.clearContinuityArea();
|
||||
DrawingCache.Instance.clear();
|
||||
updateSelection(EMPTY_SELECTION);
|
||||
// Clean up any invalid groups that may have been loaded
|
||||
cleanupInvalidGroups();
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart, filename);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject.getLockedLayers());
|
||||
@@ -2218,22 +2216,6 @@ public class Presenter implements IPlugInPort {
|
||||
group -> group.getComponentIds() != null && group.getComponentIds().stream()
|
||||
.anyMatch(id -> id != null && componentIds.contains(id)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes invalid groups (groups with null IDs or empty sets) from the project.
|
||||
* This should be called periodically to clean up corrupted groups.
|
||||
*/
|
||||
private void cleanupInvalidGroups() {
|
||||
int initialSize = currentProject.getGroupsEx().size();
|
||||
currentProject.getGroupsEx().removeIf(group ->
|
||||
group.getComponentIds() == null ||
|
||||
group.getComponentIds().isEmpty() ||
|
||||
group.getComponentIds().stream().allMatch(id -> id == null));
|
||||
int removed = initialSize - currentProject.getGroupsEx().size();
|
||||
if (removed > 0) {
|
||||
LOG.warn("Removed " + removed + " invalid group(s) with null or empty component IDs");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all components that are grouped with the specified component. This should be called any
|
||||
|
||||
Reference in New Issue
Block a user