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

Dynamic evaluation for binding.When

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 8, 9, 10
    • javafx
    • Cause Known

      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?

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

              Created:
              Updated: