On Wed, 15 Oct 2025 15:09:02 GMT, Michael Strauß <[email protected]> wrote:

>> I was restricting it because "set" does not allow you to add an element 
>> either when giving `size()` as the index.  I only belatedly realized that 
>> `setAll(int, int, Collection)` is violating this, and allows to add elements 
>> and so changes the list size.
>> 
>> Naming is really important, so calling the range method `setAll` then is I 
>> think a poor choice.  So the possible methods we could introduce are:
>> 
>> - `setAll(int, Collection)` and disallow it to change size; this method is a 
>> combination of `setAll(Collection)` and `set(int, T)` similar to how 
>> `addAll(int, Collection)` is a combination of `add(int, T)` and 
>> `addAll(Collection)`. 
>> - `replaceAll(int, Collection)` similar to the above, but allows adding of 
>> elements if it runs out of elements to update
>> - `replaceAll(int, int, Collection)` a proper name for `setAll(int, int, 
>> Collection)` (`splice` was also suggested in the ticket).
>> 
>> For me I'd either go with:
>> - Have `setAll(int, Collection)`
>> - Have both `setAll(int, Collection)` and `replaceAll(int, int, Collection)`
>> 
>> The `replaceAll(int, Collection)` I think does not carry its weight, and 
>> would just be confusing given that there would be a much more clear variant 
>> `replaceAll(int, int, Collection)`.
>
> * `setAll(int, Collection)` and disallow it to change size
> I think this doesn't carry its weight. It's just an explicit name for a 
> narrow special case of a more general operation. However, if we're going to 
> have a method with this signature, I suggest to not go for the narrow special 
> case, but instead at least allow me to overlap the new list across the end of 
> the existing list.
> 
> * `replaceAll(int, int, Collection)`
> We already have `List.replaceAll(UnaryOperator)`, which does something quite 
> different (namely, replacing all elements with different elements). I think 
> your proposed operation really is more like a `replaceRange`.

Sorry, I meant your suggestion `replace` or `replaceRange`, not `replaceAll`.  
If only I could have used `replaceAll(UnaryOperator)` to do what I wanted, but 
it fails to tell me the index of the element it is replacing...

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1937#discussion_r2433342591

Reply via email to