diff options
author | Aleksi Hietanen <aleksi@vaadin.com> | 2016-12-08 18:44:32 +0200 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2016-12-08 18:44:32 +0200 |
commit | a95dadcde5a223aacc3005b298d66e00419454e8 (patch) | |
tree | 7283d3e3b99f2be36571b05b9d7a3ea3792018a6 /server | |
parent | 474057c6a77dded2ffc6cc131c3053341c8959ee (diff) | |
download | vaadin-framework-a95dadcde5a223aacc3005b298d66e00419454e8.tar.gz vaadin-framework-a95dadcde5a223aacc3005b298d66e00419454e8.zip |
Change return type of Binder#getBean to BEAN
Diffstat (limited to 'server')
4 files changed, 31 insertions, 25 deletions
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java index da52cfd116..41c07a4c08 100644 --- a/server/src/main/java/com/vaadin/data/Binder.java +++ b/server/src/main/java/com/vaadin/data/Binder.java @@ -544,7 +544,9 @@ public class Binder<BEAN> implements Serializable { this, getter, setter); getBinder().bindings.add(binding); - getBinder().getBean().ifPresent(binding::initFieldValue); + if (getBinder().getBean() != null) { + binding.initFieldValue(getBinder().getBean()); + } getBinder().fireStatusChangeEvent(false); bound = true; @@ -813,8 +815,8 @@ public class Binder<BEAN> implements Serializable { List<ValidationResult> binderValidationResults = Collections .emptyList(); ValidationStatus<TARGET> fieldValidationStatus; - if (getBinder().getBean().isPresent()) { - BEAN bean = getBinder().getBean().get(); + if (getBinder().getBean() != null) { + BEAN bean = getBinder().getBean(); fieldValidationStatus = writeFieldValue(bean); if (!getBinder().bindings.stream() .map(BindingImpl::doValidation) @@ -964,13 +966,13 @@ public class Binder<BEAN> implements Serializable { private boolean hasChanges = false; /** - * Returns an {@code Optional} of the bean that has been bound with - * {@link #bind}, or an empty optional if a bean is not currently bound. + * Returns the bean that has been bound with {@link #bind}, or null if a + * bean is not currently bound. * * @return the currently bound bean if any */ - public Optional<BEAN> getBean() { - return Optional.ofNullable(bean); + public BEAN getBean() { + return bean; } /** @@ -1371,10 +1373,11 @@ public class Binder<BEAN> implements Serializable { */ private List<ValidationResult> validateBean(BEAN bean) { Objects.requireNonNull(bean, "bean cannot be null"); - List<ValidationResult> results = Collections.unmodifiableList(validators - .stream() - .map(validator -> validator.apply(bean, new ValueContext())) - .collect(Collectors.toList())); + List<ValidationResult> results = Collections + .unmodifiableList(validators.stream() + .map(validator -> validator.apply(bean, + new ValueContext())) + .collect(Collectors.toList())); return results; } @@ -1471,7 +1474,8 @@ public class Binder<BEAN> implements Serializable { * <li>{@link #readBean(Object)} is called * <li>{@link #setBean(Object)} is called * <li>{@link #removeBean()} is called - * <li>{@link BindingBuilder#bind(SerializableFunction, SerializableBiConsumer)} + * <li> + * {@link BindingBuilder#bind(SerializableFunction, SerializableBiConsumer)} * is called * <li>{@link Binder#validate()} or {@link Binding#validate()} is called * </ul> diff --git a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java index bc83547488..bd8ba27b51 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java @@ -58,7 +58,9 @@ public class EditorImpl<T> extends AbstractGridExtension<T> } if (ok) { - binder.getBean().ifPresent(t -> refresh(t)); + if (binder.getBean() != null) { + refresh(binder.getBean()); + } rpc.setErrorMessage(null, Collections.emptyList()); } else { List<Component> fields = status.getFieldValidationErrors() diff --git a/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java b/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java index f6a7463a12..81cfbb5484 100644 --- a/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java +++ b/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java @@ -202,16 +202,16 @@ public class BinderConverterValidatorTest @Test public void convertDataToField() { bindAgeWithValidatorConverterValidator(); - binder.getBean().get().setAge(12); - binder.readBean(binder.getBean().get()); + binder.getBean().setAge(12); + binder.readBean(binder.getBean()); assertEquals("12", ageField.getValue()); } @Test public void convertNotValidatableDataToField() { bindAgeWithValidatorConverterValidator(); - binder.getBean().get().setAge(-12); - binder.readBean(binder.getBean().get()); + binder.getBean().setAge(-12); + binder.readBean(binder.getBean()); assertEquals("-12", ageField.getValue()); } diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java index d1f831003b..397676c062 100644 --- a/server/src/test/java/com/vaadin/data/BinderTest.java +++ b/server/src/test/java/com/vaadin/data/BinderTest.java @@ -1,9 +1,9 @@ package com.vaadin.data; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import java.util.Locale; import java.util.Objects; @@ -34,10 +34,10 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { @Test public void bindNullBean_noBeanPresent() { binder.setBean(item); - assertTrue(binder.getBean().isPresent()); + assertNotNull(binder.getBean()); binder.setBean(null); - assertFalse(binder.getBean().isPresent()); + assertNull(binder.getBean()); } @Test(expected = NullPointerException.class) @@ -76,16 +76,16 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { @Test public void bound_getBean_returnsBoundBean() { - assertFalse(binder.getBean().isPresent()); + assertNull(binder.getBean()); binder.setBean(item); - assertSame(item, binder.getBean().get()); + assertSame(item, binder.getBean()); } @Test public void unbound_getBean_returnsNothing() { binder.setBean(item); binder.removeBean(); - assertFalse(binder.getBean().isPresent()); + assertNull(binder.getBean()); } @Test @@ -122,7 +122,7 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { binder.setBean(p2); assertEquals("Marlon", nameField.getValue()); assertEquals("Leif", item.getFirstName()); - assertSame(p2, binder.getBean().get()); + assertSame(p2, binder.getBean()); nameField.setValue("Ilia"); assertEquals("Ilia", p2.getFirstName()); |