Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8274771: Map, FlatMap and OrElse fluent bindings for ObservableValue #675

Closed
wants to merge 27 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d9bfefe
Initial proposal
hjohn Oct 7, 2021
312fb50
Upgrade tests to JUnit 5
hjohn Dec 15, 2021
30e8cea
Apply changes suggested in review and updated copyright years to 2022
hjohn Jan 5, 2022
040bfe4
Fix grammar mistakes and did some small rephrases
hjohn Jan 10, 2022
b013e2d
Change code according to review comments
hjohn Jan 27, 2022
14048a9
Clean up some missed asserts and some nested class names
hjohn Jan 27, 2022
30733cc
Fix wrong test values
hjohn Jan 27, 2022
29dc2af
Process review comments
hjohn Mar 10, 2022
8f9bf89
Process review comments (2)
hjohn Mar 10, 2022
72cd24d
Add line feed at last line where it was missing
hjohn Mar 18, 2022
711ea90
Fix code blocks
hjohn Mar 18, 2022
8ba9e92
Clean up docs in Subscription
hjohn Mar 18, 2022
49e1f81
Add missing javadoc tags
hjohn Mar 18, 2022
6a5358d
Reword flat map docs a bit and fixed a link
hjohn Mar 18, 2022
cb01f11
Update API docs for ObservableValue
hjohn Mar 21, 2022
e09186c
Small wording change in API of ObservableValue after proof reading
hjohn Mar 21, 2022
e2703e6
Fix wording
hjohn Mar 22, 2022
a880666
Add since tags to all new API
hjohn May 28, 2022
c352390
Expand flatMap javadoc with additional wording from Optional#flatMap
hjohn May 28, 2022
3ac734b
Rename observeInputs to observeSources
hjohn Jun 30, 2022
baa97bd
Fix typos in LazyObjectBinding
hjohn Jun 30, 2022
abe1333
Fix bug invalidation bug in FlatMappedBinding
hjohn Jun 30, 2022
a93b826
Add note to Bindings#select to consider ObservableValue#flatMap
hjohn Jun 30, 2022
2c3a9d9
Move private binding classes to com.sun.javafx.binding package
hjohn Jun 30, 2022
60b3311
Update copyrights
hjohn Jul 1, 2022
6ae74d1
Add null checks in Subscription
hjohn Jul 1, 2022
d66f2ba
Merge branch 'openjdk:master' into feature/fluent-bindings
hjohn Jul 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -141,11 +141,10 @@ public interface ObservableValue<T> extends Observable {
T getValue();

/**
* Creates an {@code ObservableValue} that holds the result of applying a
* mapping on this {@code ObservableValue}'s value. The result is updated
* when this {@code ObservableValue}'s value changes. If this value is
* {@code null}, no mapping is applied and the resulting value is also
* {@code null}.
* Returns an {@code ObservableValue} that holds the result of applying the
* given mapping function on this {@code ObservableValue}. The result is updated
* when this {@code ObservableValue} changes. If this value is {@code null},
* no mapping is applied and the resulting value is also {@code null}.
* <p>
* For example, mapping a string to an upper case string:
* <pre>{@code
@@ -160,19 +159,21 @@ public interface ObservableValue<T> extends Observable {
* }</pre>
*
* @param <U> the type of values held by the resulting {@code ObservableValue}
* @param mapper a {@code Function} that converts a given value to a new value, cannot be {@code null}
* @return an {@code ObservableValue} holding the result of mapping this {@code ObservableValue}'s
* value, or {@code null} when it is {@code null}; never returns {@code null}
* @param mapper the mapping function to apply to a value, cannot be {@code null}
* @return an {@code ObservableValue} that holds the result of applying the given
* mapping function on this {@code ObservableValue}, or {@code null} when it
* is {@code null}; never returns {@code null}
* @throws NullPointerException if the mapping function is {@code null}
*/
default <U> ObservableValue<U> map(Function<? super T, ? extends U> mapper) {
return new MappedBinding<>(this, mapper);
}

/**
* Creates an {@code ObservableValue} that holds this {@code ObservableValue}'s
* value, or the given value if it is {@code null}. The result is updated when
* this {@code ObservableValue}'s value changes. This method, when combined with
* {@link #map(Function)}, allows handling of all values including {@code null} values.
* Returns an {@code ObservableValue} that holds this value, or the given constant if
* it is {@code null}. The result is updated when this {@code ObservableValue} changes. This
* method, when combined with {@link #map(Function)}, allows handling of all values
* including {@code null} values.
* <p>
* For example, mapping a string to an upper case string, but leaving it blank
* if the input is {@code null}:
@@ -185,20 +186,20 @@ default <U> ObservableValue<U> map(Function<? super T, ? extends U> mapper) {
* upperCase.getValue(); // Returns ""
* }</pre>
*
* @param constant an alternative value to use when this {@code ObservableValue}
* @param constant the value to use when this {@code ObservableValue}
* holds {@code null}; can be {@code null}
* @return an {@code ObservableValue} holding this {@code ObservableValue}'s value,
* or the given value if it is {@code null}; never returns {@code null}
* @return an {@code ObservableValue} that holds this value, or the given constant if
* it is {@code null}; never returns {@code null}
*/
default ObservableValue<T> orElse(T constant) {
return new OrElseBinding<>(this, constant);
}

/**
* Creates a new {@code ObservableValue} that holds the value of a nested {@code ObservableValue}
* by applying a mapping function to extract the nested {@code ObservableValue}. The result
* Returns an {@code ObservableValue} that holds the value of an {@code ObservableValue}
* produced by applying the given mapping function to this {@ObservableValue}. The result
* is updated when either this {@code ObservableValue} or the {@code ObservableValue}
* resulting from the mapping changes. If this value is {@code null}, no mapping is applied
* produced by the mapping changes. If this value is {@code null}, no mapping is applied
* and the resulting value is {@code null}. If the mapping resulted in {@code null}, then
* the resulting value is also {@code null}.
* <p>
@@ -223,18 +224,18 @@ default ObservableValue<T> orElse(T constant) {
* listView.getParent().getChildren().remove(listView);
* isShowing().getValue(); // Returns false
* }</pre>
* Changes in the values of any of: the scene of {@code listView}, the window of that scene, or
* Changes in any of the values of: the scene of {@code listView}, the window of that scene, or
* the showing of that window, will update the boolean value {@code isShowing}.
* <p>
* This method is preferred over {@link javafx.beans.binding.Bindings#select Bindings} methods
* since it is type safe.
*
* @param <U> the type of values held by the resulting {@code ObservableValue}
* @param mapper a {@code Function} that converts a given value to an
* {@code ObservableValue}; cannot be {@code null}
* @return an {@code ObservableValue} holding the value of an {@code ObservableValue}
* resulting from mapping this {@code ObservableValue}'s value, or {@code null} when
* the value is {@code null}; never returns {@code null}
* @param mapper the mapping function to apply to a value, cannot be {@code null}
* @return an {@code ObservableValue} that holds the value of an {@code ObservableValue}
* produced by applying the given mapping function to this {@ObservableValue}, or
* {@code null} when the value is {@code null}; never returns {@code null}
* @throws NullPointerException if the mapping function is {@code null}
*/
default <U> ObservableValue<U> flatMap(Function<? super T, ? extends ObservableValue<? extends U>> mapper) {
return new FlatMappedBinding<>(this, mapper);