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

Add a Bindings.map() method

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • 8u25
    • javafx
    • None
    • JDK 8u25, Win 7 Pro SP1, 64 Bit

    Description

      Rather often we came across the need to bind to a property of a bound object, like...

      windowTitleProperty.bind(Bindings.createStringBinding(() -> {switch(x.getY()) case ...}, x);

      ...which certainly works well but is not very smart to read particularly if "x" is a complex term itself. Often we noted that we therefore refactored "x" into a variable just for the sake of readability, which is not smart.

      Therefore we'd like to propose a minor addition to the Bindings API which makes complex mappings of properties much simpler to read, like...

      windowTitleProperty.bind(Bindings.map(o -> {switch(x.getY()) case ...}, x);

      ...which looks mostly the same for "x" being a variable or very short term, but clearly has a huge advantage in readbility once "x" gets a complex term: As the first parameter to "Bindings.map" is a Function<T, U> but not just a Callback<T>, it does provide the resolved term as parameter "o" already, hence preventing the unnecessary and cluttering resolution of "x" within the Callback<T> function!

      This makes particularly complex code shorter and more concise, so we would really be happy to find this in a future JavaFX release.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mkarg Markus Karg
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Imported: