Skip to content

Commit

Permalink
Add JavaDoc, Rename 'extract' binding to 'map'
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-mauky committed Sep 8, 2014
1 parent 9ca4a40 commit 84b4bd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 10 additions & 8 deletions src/main/java/eu/lestard/advanced_bindings/api/ObjectBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class ObjectBindings {
* <p>
*
* This binding is null safe: When the given observable has a value of <code>null</code> the created binding
* will also contain <code>null</code>.<br>
* (Hint: if you like to specify another default value look at {@link #extract(javafx.beans.value.ObservableValue, java.util.function.Function, Object)}).
* will also contain <code>null</code> but will <strong>not</strong> throw a {@link java.lang.NullPointerException}.<br>
* (Hint: if you like to specify another default value look at {@link #map(javafx.beans.value.ObservableValue, java.util.function.Function, Object)}).
* <p>
* If the given observable's value is <b>not</b> <code>null</code> the function will be applied to the value and the
* If the given observable`s value is <strong>not</strong> <code>null</code> the function will be applied to the value and the
* return value of the function is used as the value of the created binding.
* <p>
* A common use case for this binding is when you are interested in a property of the object of an observable value.
Expand All @@ -35,7 +35,7 @@ public class ObjectBindings {
*
* ObjectProperty{@code<Person>} personProperty = ...
*
* ObjectBinding{@code<String>} name = ObjectBindings.extract(personProperty, Person::getName);
* ObjectBinding{@code<String>} name = ObjectBindings.map(personProperty, Person::getName);
* </pre>
*
* The "name" binding in the example always contains the name of the Person that the "personProperty" is holding.
Expand All @@ -49,15 +49,17 @@ public class ObjectBindings {
* assertThat(name.get()).isNull();
* </pre>
*
* Your mapping function will only be called when the observable value is not null. This means that you don't need to check for <code>null</code> param
* in you mapping function.
*
* @param source the observable value that is the source for this binding.
* @param function a function that maps the value of the source to the target binding.
* @param <S> the generic type of the source observable.
* @param <R> the generic type of the resulting binding.
* @return the created binding.
*/
public static <S, R> ObjectBinding<R> extract(ObservableValue<S> source, Function<? super S, ? extends R> function) {
return extract(source, function, null);
public static <S, R> ObjectBinding<R> map(ObservableValue<S> source, Function<? super S, ? extends R> function) {
return map(source, function, null);
}

/**
Expand All @@ -67,7 +69,7 @@ public static <S, R> ObjectBinding<R> extract(ObservableValue<S> source, Functio
* <p>
* The given function will never get <code>null</code> as param so you don't need to check for this.
* <p>
* See {@link #extract(javafx.beans.value.ObservableValue, java.util.function.Function, Object)} for a detailed explanation of
* See {@link #map(javafx.beans.value.ObservableValue, java.util.function.Function, Object)} for a detailed explanation of
* the binding.
*
* @param source the observable value that is the source for this binding.
Expand All @@ -77,7 +79,7 @@ public static <S, R> ObjectBinding<R> extract(ObservableValue<S> source, Functio
* @param <R> the generic type of the resulting binding.
* @return the created binding.
*/
public static <S, R> ObjectBinding<R> extract(ObservableValue<S> source, Function<? super S, ? extends R> function, R defaultValue){
public static <S, R> ObjectBinding<R> map(ObservableValue<S> source, Function<? super S, ? extends R> function, R defaultValue){
return Bindings.createObjectBinding(()->{
S sourceValue = source.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import static eu.lestard.assertj.javafx.api.Assertions.*;

public class ObjectBindings_extract_Test {
public class ObjectBindings_map_Test {

private static class Person{
private final String name;
Expand All @@ -26,10 +26,10 @@ public String getName() {


@Test
public void testExtract(){
public void testMap(){
ObjectProperty<Person> selectedPerson = new SimpleObjectProperty<>();

ObjectBinding<String> name = ObjectBindings.extract(selectedPerson, Person::getName);
ObjectBinding<String> name = ObjectBindings.map(selectedPerson, Person::getName);
assertThat(name).hasNullValue();

selectedPerson.set(obi);
Expand All @@ -40,10 +40,10 @@ public void testExtract(){
}

@Test
public void testExtractWithDefaultValue(){
public void testMapWithDefaultValue(){
ObjectProperty<Person> selectedPerson = new SimpleObjectProperty<>();

ObjectBinding<String> name = ObjectBindings.extract(selectedPerson, Person::getName, "empty");
ObjectBinding<String> name = ObjectBindings.map(selectedPerson, Person::getName, "empty");
assertThat(name).hasValue("empty");
selectedPerson.set(obi);
assertThat(name).hasValue("Obi-Wan");
Expand Down

0 comments on commit 84b4bd8

Please sign in to comment.