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

Karthik P K kpk at openjdk.org
Tue Mar 26 16:39:41 UTC 2024


On Sun, 24 Mar 2024 15:10:22 GMT, drmarmac <duke at openjdk.org> wrote:

> This PR removes potentially incorrect usages of Stream.peek().
> The changed code should be covered by the tests that are already present.

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?

modules/javafx.controls/src/main/java/javafx/scene/control/ControlUtils.java line 185:

> 183:                     .mapToInt(TablePositionBase::getRow)
> 184:                     .distinct()
> 185:                     .forEach(row -> {

Similar comment as above. Here if we do not use `forEach()` on streams, we can also avoid using array of size one for keeping count as well right?

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

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


More information about the openjfx-dev mailing list