RFR: 8273349: Check uses of Stream::peek in controls and replace as needed [v2]

Marius Hanl mhanl at openjdk.org
Wed Mar 27 12:26:26 UTC 2024


On Wed, 27 Mar 2024 09:07:15 GMT, drmarmac <duke at openjdk.org> wrote:

>> modules/javafx.controls/src/main/java/javafx/scene/control/ControlUtils.java line 176:
>> 
>>> 174:                     .distinct()
>>> 175:                     .filter(removeRowFilter)
>>> 176:                     .forEach(row -> {
>> 
>> In the java.util.stream package [docs](https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/stream/package-summary.html#SideEffects) it is mentioned that `forEach()` method operates only via side-effects. So do you think we should avoid using `forEach()` here and iterate the generated list separately to clear selected index?
>
> I'd say .forEach() is used correctly here, according to docs, it guarantees execution of the side-effects (add to removed list & clear index), just not in any particular order. This way we avoid multiple iteration.

Another idea is to use `toList()`, which is a very efficient operation and then iterate over it.

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1430#discussion_r1541003650


More information about the openjfx-dev mailing list