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

Dynamic evaluation for binding.When

    XMLWordPrintable

Details

    • Enhancement
    • Status: In Progress
    • P3
    • Resolution: Unresolved
    • 8, 9, 10
    • tbd
    • javafx
    • 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

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

              Dates

                Created:
                Updated: