From a95dadcde5a223aacc3005b298d66e00419454e8 Mon Sep 17 00:00:00 2001 From: Aleksi Hietanen Date: Thu, 8 Dec 2016 18:44:32 +0200 Subject: Change return type of Binder#getBean to BEAN --- server/src/main/java/com/vaadin/data/Binder.java | 28 ++++++++++++---------- .../com/vaadin/ui/components/grid/EditorImpl.java | 4 +++- .../vaadin/data/BinderConverterValidatorTest.java | 8 +++---- .../src/test/java/com/vaadin/data/BinderTest.java | 16 ++++++------- 4 files changed, 31 insertions(+), 25 deletions(-) (limited to 'server/src') 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 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 implements Serializable { List binderValidationResults = Collections .emptyList(); ValidationStatus 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 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 getBean() { - return Optional.ofNullable(bean); + public BEAN getBean() { + return bean; } /** @@ -1371,10 +1373,11 @@ public class Binder implements Serializable { */ private List validateBean(BEAN bean) { Objects.requireNonNull(bean, "bean cannot be null"); - List results = Collections.unmodifiableList(validators - .stream() - .map(validator -> validator.apply(bean, new ValueContext())) - .collect(Collectors.toList())); + List results = Collections + .unmodifiableList(validators.stream() + .map(validator -> validator.apply(bean, + new ValueContext())) + .collect(Collectors.toList())); return results; } @@ -1471,7 +1474,8 @@ public class Binder implements Serializable { *
  • {@link #readBean(Object)} is called *
  • {@link #setBean(Object)} is called *
  • {@link #removeBean()} is called - *
  • {@link BindingBuilder#bind(SerializableFunction, SerializableBiConsumer)} + *
  • + * {@link BindingBuilder#bind(SerializableFunction, SerializableBiConsumer)} * is called *
  • {@link Binder#validate()} or {@link Binding#validate()} is called * 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 extends AbstractGridExtension } if (ok) { - binder.getBean().ifPresent(t -> refresh(t)); + if (binder.getBean() != null) { + refresh(binder.getBean()); + } rpc.setErrorMessage(null, Collections.emptyList()); } else { List 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, 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, 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, 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()); -- cgit v1.2.3