Batch-select optimization in CustomMultipleSelectionModel to reduce redundant listener updates #235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the robustness and efficiency of the
selectIndices(int, int...)method inCustomMultipleSelectionModel. It addresses both functional correctness and performance optimization:Key Improvements
✅ Avoids repeated listener notifications
Previously, selecting indices one-by-one triggered multiple selection events and list mutations. This version performs batch updates to minimize unnecessary UI refreshes and observable change events.
✅ Null-safe handling for
int... indicesPrevents
NullPointerExceptionifnullis passed.✅ Single-pass filtering
Combines validation, deduplication, and unselected checks in a single stream.
✅ No-op guard
Efficiently skips updates if all indices are already selected.
✅ Predictive memory allocation
Uses
new ArrayList<>(1 + indices.length)to avoid internal array resizing.✅ Consistent final selection state
Aligns with JavaFX: in both
SINGLEandMULTIPLEselection modes, the last valid index is treated as the active one (selectedIndex,selectedItem).