Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8274771

Map, FlatMap and OrElse fluent bindings for ObservableValue



    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • None
    • jfx19
    • javafx
    • None


      Add support for creating derived bindings directly from ObservableValue with new API in the ObservableValue interface. The API will be null safe (no user provided functions should be called with null) and offers alternative ways to deal with nulls similar to Optional.

      The API should be intuitive to use and address issues currently seen in JavaFX requiring weak listeners and the storing of references to intermediate bindings to make sure they don't get garbage collected. This will be resolved by introducing lazy bindings in a derivative class of ObjectBinding called LazyObjectBinding.

      Lazy bindings in effect are always invalid when not themselves observed. This allows for easier garbage collection (once the last observer is removed, a chain of bindings will stop observing their parents severing the hard reference from parent to child) and less listener management when dealing with nested properties.

      Lazy bindings will also allow the safe inclusion of derived properties in top level classes like Node without causing listeners to be created for every Node created (increasing memory consumption and time spent on listener management), as long as these derived properties are not in actual use.

      This ticket addresses JDK-8091544 which is a feature request for type a safe alternative to Bindings#select. It also provides arbitrary conversion of bindings which addresses JDK-8091316.

      A PoC can be found here: https://github.com/openjdk/jfx/pull/434 and here https://github.com/openjdk/jfx-sandbox/tree/jfx-sandbox/nlisker_fuent_bindings

      For a minimal implementation the following new public API should be introduced in ObservableValue:

      - map: Returns an ObservableValue which holds a mapping of the value held by this ObservableValue, and is null when this ObservableValue null
      - flatMap: Returns an ObservableValue which holds the value in the ObservableValue given by applying a mapper on the value of this ObservableValue, and is null when this ObservableValue is null.
      - orElse: Returns an ObservableValue}which holds a mapping of the value held by this ObservableValue, or the value held by alternativeValue when this ObservableValue is null


        Issue Links



              jhendrikx John Hendrikx
              jhendrikx John Hendrikx
              0 Vote for this issue
              2 Start watching this issue