The Property interface should be extended to get the following methods:
public void bindBidirectional(Property<S> other, Mapper<T, S> mapper1, Mapper<S, T> mapper2);
public void unbindBidirectional(Object other);
The Bindings class will likewise get a new method:
public void bindBidirectional(Property<T> property1, Property<S> property2, Mapper<T, S> mapper1, Mapper<S, T> mapper2);
Extending an existing interface and the Mapper interface (a SAM type) are features that will very likely be added in JDK 8. Therefore it makes sense to wait.
public interface Mapper<U, V> {
V extract(U element);
}
Basically Mapper is a SAM, that allows you to define a mapping from a type U to a type V. It will be part of the collections framework in JDK 8, maybe not exactly like this, but something close. It will allow you to map one collection onto another. For example, if you want to get a list of all names from a list of persons, you will be able to write "personList.map(Person::getName)". (Person::getName is a method reference and stands for "Person p -> p.getName()")
The idea is, that once we have Lambda expressions, it would be far easier to specify two Mappers, instead of a class with two methods. For example, let's say you have a custom class Person with a useful toString() implementation and a static parse() method. With that you can simply define a bidirectional binding between a personProperty and a stringProperty like this:
Bindings.bindBidirectional(personProperty, stringProperty, Person::toString, s -> Person.parse(s))
public void bindBidirectional(Property<S> other, Mapper<T, S> mapper1, Mapper<S, T> mapper2);
public void unbindBidirectional(Object other);
The Bindings class will likewise get a new method:
public void bindBidirectional(Property<T> property1, Property<S> property2, Mapper<T, S> mapper1, Mapper<S, T> mapper2);
Extending an existing interface and the Mapper interface (a SAM type) are features that will very likely be added in JDK 8. Therefore it makes sense to wait.
public interface Mapper<U, V> {
V extract(U element);
}
Basically Mapper is a SAM, that allows you to define a mapping from a type U to a type V. It will be part of the collections framework in JDK 8, maybe not exactly like this, but something close. It will allow you to map one collection onto another. For example, if you want to get a list of all names from a list of persons, you will be able to write "personList.map(Person::getName)". (Person::getName is a method reference and stands for "Person p -> p.getName()")
The idea is, that once we have Lambda expressions, it would be far easier to specify two Mappers, instead of a class with two methods. For example, let's say you have a custom class Person with a useful toString() implementation and a static parse() method. With that you can simply define a bidirectional binding between a personProperty and a stringProperty like this:
Bindings.bindBidirectional(personProperty, stringProperty, Person::toString, s -> Person.parse(s))
- duplicates
-
JDK-8102529 Double bindings based on a difference factor between 2 values
-
- Closed
-
- relates to
-
JDK-8101274 Add bidirectional bindings with conversion
-
- Closed
-