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

Dynamic evaluation for binding.When

    Details

    • Type: Enhancement
    • Status: In Progress
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 8, 9, 10
    • Fix Version/s: tbd
    • Component/s: javafx
    • Subcomponent:
    • Understanding:
      Cause Known

      Description

      When's current API evaluates both 'then' and 'othwerise' on creation. As a binding equivalent of a ternary expression, where only one of the results is evaluated, When is missing the functionality for evaluating the 'then' and 'otherwise' "on demand". See JDK-8089579.

      One option is adding public API that takes a Supplier<T> for 'then' and 'otherwise'. The result would be an ObjectBinding<T> that holds the value returned by Supplier#get at the moment of evaluation of the condition.

      This approach allows an alternative to

      boolean b = cond.get() ? getBooleanForTrue() : getBooleanForFalse();
      cond.addListener((obs, ov, nv) -> b = nv ? getBooleanForTrue() : getBooleanForFalse());

      by using

      BooleanBinding b = new When(cond).then( () -> getBooleanForTrue() ).otherwise( () -> getBooleanForFalse() );

      Something to think about would be if this new API can mix with the current one. That is, if 'then' takes a Supplier<T>, must 'otherwise' also take a Supplier<T>, or can it take an ObservableObjectValue<T> or T?

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nlisker Nir Lisker
                Reporter:
                nlisker Nir Lisker
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: