diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-10-20 08:59:17 +0200 |
---|---|---|
committer | Péter Török <31210544+torok-peter@users.noreply.github.com> | 2017-10-20 09:59:17 +0300 |
commit | 780e9cee6b7e976285402a00ad5b282a8e79619e (patch) | |
tree | fd3aec572018a6b0b32d63d0f5b424413d39dfea /server | |
parent | 70ba487b622ab13aa39f45cb53507065c180dc56 (diff) | |
download | vaadin-framework-780e9cee6b7e976285402a00ad5b282a8e79619e.tar.gz vaadin-framework-780e9cee6b7e976285402a00ad5b282a8e79619e.zip |
Simplify lambda expressions (#10198)
* Simplify lambda expressions
And remove unneeded 'return' keyword.
* Format
Diffstat (limited to 'server')
32 files changed, 128 insertions, 184 deletions
diff --git a/server/src/main/java/com/vaadin/data/Validator.java b/server/src/main/java/com/vaadin/data/Validator.java index 4f8f4dc8ca..be6b89188a 100644 --- a/server/src/main/java/com/vaadin/data/Validator.java +++ b/server/src/main/java/com/vaadin/data/Validator.java @@ -186,10 +186,9 @@ public interface Validator<T> try { if (guard.test(value)) { return ValidationResult.ok(); - } else { - return ValidationResult.create( - errorMessageProvider.apply(context), errorLevel); } + return ValidationResult.create( + errorMessageProvider.apply(context), errorLevel); } catch (Exception e) { return ValidationResult.create( errorMessageProvider.apply(context), errorLevel); diff --git a/server/src/main/java/com/vaadin/data/converter/StringToBigIntegerConverter.java b/server/src/main/java/com/vaadin/data/converter/StringToBigIntegerConverter.java index 40683abb22..840f6ae8c0 100644 --- a/server/src/main/java/com/vaadin/data/converter/StringToBigIntegerConverter.java +++ b/server/src/main/java/com/vaadin/data/converter/StringToBigIntegerConverter.java @@ -84,13 +84,12 @@ public class StringToBigIntegerConverter .map(number -> { if (number == null) { return null; - } else { - // Empty value will be a BigInteger - if (number instanceof BigInteger) { - return (BigInteger) number; - } - return ((BigDecimal) number).toBigInteger(); } + // Empty value will be a BigInteger + if (number instanceof BigInteger) { + return (BigInteger) number; + } + return ((BigDecimal) number).toBigInteger(); }); } diff --git a/server/src/main/java/com/vaadin/data/converter/StringToDoubleConverter.java b/server/src/main/java/com/vaadin/data/converter/StringToDoubleConverter.java index a2eb45dce1..627775fbba 100644 --- a/server/src/main/java/com/vaadin/data/converter/StringToDoubleConverter.java +++ b/server/src/main/java/com/vaadin/data/converter/StringToDoubleConverter.java @@ -72,9 +72,8 @@ public class StringToDoubleConverter return n.map(number -> { if (number == null) { return null; - } else { - return number.doubleValue(); } + return number.doubleValue(); }); } diff --git a/server/src/main/java/com/vaadin/data/converter/StringToFloatConverter.java b/server/src/main/java/com/vaadin/data/converter/StringToFloatConverter.java index 6598c0f6fd..37e159f844 100644 --- a/server/src/main/java/com/vaadin/data/converter/StringToFloatConverter.java +++ b/server/src/main/java/com/vaadin/data/converter/StringToFloatConverter.java @@ -70,9 +70,8 @@ public class StringToFloatConverter return n.map(number -> { if (number == null) { return null; - } else { - return number.floatValue(); } + return number.floatValue(); }); } diff --git a/server/src/main/java/com/vaadin/data/converter/StringToIntegerConverter.java b/server/src/main/java/com/vaadin/data/converter/StringToIntegerConverter.java index 71709e9927..88f2c29126 100644 --- a/server/src/main/java/com/vaadin/data/converter/StringToIntegerConverter.java +++ b/server/src/main/java/com/vaadin/data/converter/StringToIntegerConverter.java @@ -85,18 +85,16 @@ public class StringToIntegerConverter return n.flatMap(number -> { if (number == null) { return Result.ok(null); - } else { - int intValue = number.intValue(); - if (intValue == number.longValue()) { - // If the value of n is outside the range of long, the - // return value of longValue() is either Long.MIN_VALUE or - // Long.MAX_VALUE. The/ above comparison promotes int to - // long and thus does not need to consider wrap-around. - return Result.ok(intValue); - } else { - return Result.error(getErrorMessage()); - } } + int intValue = number.intValue(); + if (intValue == number.longValue()) { + // If the value of n is outside the range of long, the + // return value of longValue() is either Long.MIN_VALUE or + // Long.MAX_VALUE. The/ above comparison promotes int to + // long and thus does not need to consider wrap-around. + return Result.ok(intValue); + } + return Result.error(getErrorMessage()); }); } diff --git a/server/src/main/java/com/vaadin/data/converter/StringToLongConverter.java b/server/src/main/java/com/vaadin/data/converter/StringToLongConverter.java index 00364dbbc9..4e65296316 100644 --- a/server/src/main/java/com/vaadin/data/converter/StringToLongConverter.java +++ b/server/src/main/java/com/vaadin/data/converter/StringToLongConverter.java @@ -85,9 +85,8 @@ public class StringToLongConverter return n.map(number -> { if (number == null) { return null; - } else { - return number.longValue(); } + return number.longValue(); }); } diff --git a/server/src/main/java/com/vaadin/data/provider/InMemoryDataProviderHelpers.java b/server/src/main/java/com/vaadin/data/provider/InMemoryDataProviderHelpers.java index 556404911c..785079bb0d 100644 --- a/server/src/main/java/com/vaadin/data/provider/InMemoryDataProviderHelpers.java +++ b/server/src/main/java/com/vaadin/data/provider/InMemoryDataProviderHelpers.java @@ -46,9 +46,8 @@ public class InMemoryDataProviderHelpers { UI currentUi = UI.getCurrent(); if (currentUi != null) { return currentUi.getLocale(); - } else { - return Locale.getDefault(); } + return Locale.getDefault(); }; /** diff --git a/server/src/main/java/com/vaadin/navigator/Navigator.java b/server/src/main/java/com/vaadin/navigator/Navigator.java index 81e141319d..22b22678b0 100644 --- a/server/src/main/java/com/vaadin/navigator/Navigator.java +++ b/server/src/main/java/com/vaadin/navigator/Navigator.java @@ -120,10 +120,8 @@ public class Navigator implements Serializable { popStateListenerRegistration = null; } if (navigator != null) { - popStateListenerRegistration = ui.getPage() - .addPopStateListener(e -> { - navigator.navigateTo(getState()); - }); + popStateListenerRegistration = ui.getPage().addPopStateListener( + e -> navigator.navigateTo(getState())); } } @@ -700,10 +698,8 @@ public class Navigator implements Serializable { * parameters passed in the navigation state to the view */ protected void navigateTo(View view, String viewName, String parameters) { - runAfterLeaveConfirmation(() -> { - performNavigateTo(view, viewName, parameters); - }); - + runAfterLeaveConfirmation( + () -> performNavigateTo(view, viewName, parameters)); } /** diff --git a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java index b54c9622d6..c0221af38e 100644 --- a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java @@ -694,9 +694,7 @@ public class FileUploadHandler implements RequestHandler { private void cleanStreamVariable(VaadinSession session, final UI ui, final ClientConnector owner, final String variableName) { - session.accessSynchronously(() -> { - ui.getConnectorTracker().cleanStreamVariable(owner.getConnectorId(), - variableName); - }); + session.accessSynchronously(() -> ui.getConnectorTracker() + .cleanStreamVariable(owner.getConnectorId(), variableName)); } } diff --git a/server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java b/server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java index 9e15d5c0fe..04fcbd0c80 100644 --- a/server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java @@ -36,7 +36,6 @@ import org.atmosphere.interceptor.HeartbeatInterceptor; import org.atmosphere.util.VoidAnnotationProcessor; import com.vaadin.server.RequestHandler; -import com.vaadin.server.ServiceDestroyEvent; import com.vaadin.server.ServiceException; import com.vaadin.server.ServletPortletHelper; import com.vaadin.server.SessionExpiredHandler; @@ -66,9 +65,7 @@ public class PushRequestHandler public PushRequestHandler(VaadinServletService service) throws ServiceException { - service.addServiceDestroyListener((ServiceDestroyEvent event) -> { - destroy(); - }); + service.addServiceDestroyListener(e -> destroy()); final ServletConfig vaadinServletConfig = service.getServlet() .getServletConfig(); diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java index 2c9c40e668..88b42d5757 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java +++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java @@ -1388,10 +1388,10 @@ public abstract class AbstractComponent extends AbstractClientConnector // called if there are no listeners on the server-side. A client-side // connector can override this and use a different RPC channel. if (getRpcManager(ContextClickRpc.class.getName()) == null) { - registerRpc((ContextClickRpc) (MouseEventDetails details) -> { - fireEvent( - new ContextClickEvent(AbstractComponent.this, details)); - }); + registerRpc( + (ContextClickRpc) (MouseEventDetails details) -> fireEvent( + new ContextClickEvent(AbstractComponent.this, + details))); } return addListener(EventId.CONTEXT_CLICK, ContextClickEvent.class, diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index 6e03ed35e9..c6765dde1a 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -678,10 +678,9 @@ public class ComboBox<T> extends AbstractSingleSelect<T> @Override public Registration addValueChangeListener( HasValue.ValueChangeListener<T> listener) { - return addSelectionListener(event -> { - listener.valueChange(new ValueChangeEvent<>(event.getComponent(), - this, event.getOldValue(), event.isUserOriginated())); - }); + return addSelectionListener(event -> listener + .valueChange(new ValueChangeEvent<>(event.getComponent(), this, + event.getOldValue(), event.isUserOriginated()))); } @Override diff --git a/server/src/main/java/com/vaadin/ui/CssLayout.java b/server/src/main/java/com/vaadin/ui/CssLayout.java index a407859d08..4540a9feb9 100644 --- a/server/src/main/java/com/vaadin/ui/CssLayout.java +++ b/server/src/main/java/com/vaadin/ui/CssLayout.java @@ -76,10 +76,10 @@ import com.vaadin.ui.declarative.DesignContext; public class CssLayout extends AbstractLayout implements LayoutClickNotifier { private CssLayoutServerRpc rpc = (MouseEventDetails mouseDetails, - Connector clickedConnector) -> { - fireEvent(LayoutClickEvent.createEvent(CssLayout.this, mouseDetails, - clickedConnector)); - }; + Connector clickedConnector) -> fireEvent( + LayoutClickEvent.createEvent(CssLayout.this, mouseDetails, + clickedConnector)); + /** * Custom layout slots containing the components. */ diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 2b4723eaaa..de8f66ee58 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -403,12 +403,12 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * <p> * Usage: - * + * * <pre> * grid.addContextClickListener(event -> Notification.show( * ((GridContextClickEvent<Person>) event).getItem() + " Clicked")); * </pre> - * + * * @param <T> * the grid bean type */ @@ -836,9 +836,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, String id = getId(); if (id == null) { return Stream.empty(); - } else { - return Stream.of(new QuerySortOrder(id, direction)); } + return Stream.of(new QuerySortOrder(id, direction)); }; private SerializableComparator<T> comparator; @@ -3018,7 +3017,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * Note that all header, body and footer rows get the same height if * explicitly set. In automatic mode, each section is calculated separately * based on an empty row of that type. - * + * * @see #setBodyRowHeight(double) * @see #setHeaderRowHeight(double) * @see #setFooterRowHeight(double) @@ -3036,7 +3035,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * Sets the height of a body row. If -1 (default), the row height is * calculated based on the theme for an empty row before the Grid is * displayed. - * + * * @param rowHeight * The height of a row in pixels or -1 for automatic calculation * @since 8.2 @@ -3293,10 +3292,10 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, /** * Sets the visibility of the Header in this Grid. - * + * * @param headerVisible * {@code true} if visible; {@code false} if not - * + * * @since 8.1.1 */ public void setHeaderVisible(boolean headerVisible) { @@ -3305,9 +3304,9 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, /** * Gets the visibility of the Header in this Grid. - * + * * @return {@code true} if visible; {@code false} if not - * + * * @since 8.1.1 */ public boolean isHeaderVisible() { @@ -3466,10 +3465,10 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, /** * Sets the visibility of the Footer in this Grid. - * + * * @param footerVisible * {@code true} if visible; {@code false} if not - * + * * @since 8.1.1 */ public void setFooterVisible(boolean footerVisible) { @@ -3478,9 +3477,9 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, /** * Gets the visibility of the Footer in this Grid. - * + * * @return {@code true} if visible; {@code false} if not - * + * * @since 8.1.1 */ public boolean isFooterVisible() { @@ -3651,7 +3650,6 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, "setColumnOrder should not be called " + "with columns that are not in the grid."); } - }); List<String> stateColumnOrder = getState().columnOrder; @@ -4572,14 +4570,13 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * @return the comparator based on column sorting information. */ protected SerializableComparator<T> createSortingComparator() { + /* + * thenComparing is defined to return a serializable comparator as long + * as both original comparators are also serializable + */ BinaryOperator<SerializableComparator<T>> operator = (comparator1, - comparator2) -> { - /* - * thenComparing is defined to return a serializable comparator as - * long as both original comparators are also serializable - */ - return comparator1.thenComparing(comparator2)::compare; - }; + comparator2) -> + comparator1.thenComparing(comparator2)::compare; return sortOrder.stream().map( order -> order.getSorted().getComparator(order.getDirection())) .reduce((x, y) -> 0, operator); diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java index 27e1835b57..ebffa061e8 100644 --- a/server/src/main/java/com/vaadin/ui/GridLayout.java +++ b/server/src/main/java/com/vaadin/ui/GridLayout.java @@ -77,10 +77,10 @@ public class GridLayout extends AbstractLayout Layout.MarginHandler, LayoutClickNotifier { private GridLayoutServerRpc rpc = (MouseEventDetails mouseDetails, - Connector clickedConnector) -> { - fireEvent(LayoutClickEvent.createEvent(GridLayout.this, mouseDetails, - clickedConnector)); - }; + Connector clickedConnector) -> fireEvent( + LayoutClickEvent.createEvent(GridLayout.this, mouseDetails, + clickedConnector)); + /** * Cursor X position: this is where the next component with unspecified x,y * is inserted diff --git a/server/src/main/java/com/vaadin/ui/Image.java b/server/src/main/java/com/vaadin/ui/Image.java index 4f3650a9f2..4b1d7dae00 100644 --- a/server/src/main/java/com/vaadin/ui/Image.java +++ b/server/src/main/java/com/vaadin/ui/Image.java @@ -33,9 +33,9 @@ import com.vaadin.shared.ui.image.ImageState; @SuppressWarnings("serial") public class Image extends AbstractEmbedded { - protected ImageServerRpc rpc = (MouseEventDetails mouseDetails) -> { - fireEvent(new ClickEvent(Image.this, mouseDetails)); - }; + protected ImageServerRpc rpc = ( + MouseEventDetails mouseDetails) -> fireEvent( + new ClickEvent(Image.this, mouseDetails)); /** * Creates a new empty Image. diff --git a/server/src/main/java/com/vaadin/ui/Notification.java b/server/src/main/java/com/vaadin/ui/Notification.java index 83c145ec70..0c3158bf97 100644 --- a/server/src/main/java/com/vaadin/ui/Notification.java +++ b/server/src/main/java/com/vaadin/ui/Notification.java @@ -74,9 +74,8 @@ public class Notification extends AbstractExtension implements Serializable { * * @since 8.2 */ - protected NotificationServerRpc rpc = () -> { - fireEvent(new CloseEvent(Notification.this)); - }; + protected NotificationServerRpc rpc = () -> fireEvent( + new CloseEvent(Notification.this)); public enum Type { HUMANIZED_MESSAGE("humanized"), WARNING_MESSAGE( diff --git a/server/src/main/java/com/vaadin/ui/Panel.java b/server/src/main/java/com/vaadin/ui/Panel.java index def5893946..6b06b02fe4 100644 --- a/server/src/main/java/com/vaadin/ui/Panel.java +++ b/server/src/main/java/com/vaadin/ui/Panel.java @@ -53,9 +53,8 @@ public class Panel extends AbstractSingleComponentContainer */ protected ActionManager actionManager; - private PanelServerRpc rpc = (MouseEventDetails mouseDetails) -> { - fireEvent(new ClickEvent(Panel.this, mouseDetails)); - }; + private PanelServerRpc rpc = (MouseEventDetails mouseDetails) -> fireEvent( + new ClickEvent(Panel.this, mouseDetails)); /** * Creates a new empty panel. diff --git a/server/src/main/java/com/vaadin/ui/components/grid/GridDragSource.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDragSource.java index cf5051abb4..c84cc9534d 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/GridDragSource.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDragSource.java @@ -149,9 +149,8 @@ public class GridDragSource<T> extends DragSourceExtension<Grid<T>> { private void generateDragData(T item, JsonObject jsonObject) { JsonObject generatedValues = Json.createObject(); - generatorFunctions.forEach((type, generator) -> { - generatedValues.put(type, generator.apply(item)); - }); + generatorFunctions.forEach((type, generator) -> generatedValues + .put(type, generator.apply(item))); jsonObject.put(GridDragSourceState.JSONKEY_DRAG_DATA, generatedValues); } diff --git a/server/src/main/java/com/vaadin/ui/declarative/Design.java b/server/src/main/java/com/vaadin/ui/declarative/Design.java index 8d723ef47e..61d35297d0 100644 --- a/server/src/main/java/com/vaadin/ui/declarative/Design.java +++ b/server/src/main/java/com/vaadin/ui/declarative/Design.java @@ -490,9 +490,8 @@ public class Design implements Serializable { // create listener for component creations that binds the created // components to the componentRoot instance fields ComponentCreationListener creationListener = ( - ComponentCreatedEvent event) -> { - binder.bindField(event.getComponent(), event.getLocalId()); - }; + ComponentCreatedEvent event) -> binder.bindField( + event.getComponent(), event.getLocalId()); designContext.addComponentCreationListener(creationListener); // create subtree diff --git a/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java b/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java index 4cff2545e8..76c7195f60 100644 --- a/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java +++ b/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java @@ -24,10 +24,10 @@ import java.util.Objects; import com.vaadin.server.AbstractExtension; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.Registration; -import com.vaadin.shared.ui.dnd.criteria.ComparisonOperator; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.dnd.DropTargetRpc; import com.vaadin.shared.ui.dnd.DropTargetState; +import com.vaadin.shared.ui.dnd.criteria.ComparisonOperator; import com.vaadin.shared.ui.dnd.criteria.Criterion; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.dnd.event.DropEvent; @@ -73,11 +73,10 @@ public class DropTargetExtension<T extends AbstractComponent> */ protected void registerDropTargetRpc() { registerRpc( - (DropTargetRpc) (types, data, dropEffect, mouseEventDetails) -> { - onDrop(types, data, - DropEffect.valueOf(dropEffect.toUpperCase()), - mouseEventDetails); - }); + (DropTargetRpc) (types, data, dropEffect, mouseEventDetails) -> + onDrop(types, data, + DropEffect.valueOf(dropEffect.toUpperCase()), + mouseEventDetails)); } /** diff --git a/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java b/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java index 734aa5b194..a451e2b9be 100644 --- a/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java +++ b/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java @@ -127,9 +127,8 @@ public class BinderConverterValidatorTest Validator<Number> positiveNumberValidator = (value, context) -> { if (value.doubleValue() >= 0) { return ValidationResult.ok(); - } else { - return ValidationResult.error(NEGATIVE_ERROR_MESSAGE); } + return ValidationResult.error(NEGATIVE_ERROR_MESSAGE); }; binder.forField(salaryField) .withConverter(Double::valueOf, String::valueOf) @@ -227,7 +226,8 @@ public class BinderConverterValidatorTest .withConverter(presentation -> { if (presentation.equals("OK")) { return "1"; - } else if (presentation.equals("NOTOK")) { + } + if (presentation.equals("NOTOK")) { return "2"; } throw new IllegalArgumentException( @@ -235,12 +235,12 @@ public class BinderConverterValidatorTest }, model -> { if (model.equals("1")) { return "OK"; - } else if (model.equals("2")) { + } + if (model.equals("2")) { return "NOTOK"; - } else { - throw new IllegalArgumentException( - "Value in model must be 1 or 2"); } + throw new IllegalArgumentException( + "Value in model must be 1 or 2"); }); binding.bind(StatusBean::getStatus, StatusBean::setStatus); binder.setBean(bean); @@ -535,12 +535,9 @@ public class BinderConverterValidatorTest binder.forField(nameField).withConverter(fieldValue -> { if ("null".equals(fieldValue)) { return null; - } else { - return fieldValue; } - }, model -> { - return model; - }).bind(Person::getFirstName, Person::setFirstName); + return fieldValue; + }, model -> model).bind(Person::getFirstName, Person::setFirstName); Person person = new Person(); person.setFirstName("foo"); diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java index 032ce99580..7b45ee95e0 100644 --- a/server/src/test/java/com/vaadin/data/BinderTest.java +++ b/server/src/test/java/com/vaadin/data/BinderTest.java @@ -394,8 +394,9 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { String customNullPointerRepresentation = "foo"; Binder<Person> binder = new Binder<>(Person.class); binder.forField(nameField) - .withConverter(value -> value, value -> value == null - ? customNullPointerRepresentation : value) + .withConverter(value -> value, + value -> value == null ? customNullPointerRepresentation + : value) .bind("firstName"); Person person = new Person(); @@ -892,9 +893,8 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { .withConverter(new StringToIntegerConverter(ageError)) .bind(Person::getAge, Person::setAge); - binder.setValidationStatusHandler(status -> { - status.notifyBindingValidationStatusHandlers(); - }); + binder.setValidationStatusHandler( + status -> status.notifyBindingValidationStatusHandlers()); String initialName = item.getFirstName(); int initialAge = item.getAge(); diff --git a/server/src/test/java/com/vaadin/data/BinderValidationStatusTest.java b/server/src/test/java/com/vaadin/data/BinderValidationStatusTest.java index dcf568cafc..7df1537bd0 100644 --- a/server/src/test/java/com/vaadin/data/BinderValidationStatusTest.java +++ b/server/src/test/java/com/vaadin/data/BinderValidationStatusTest.java @@ -215,17 +215,16 @@ public class BinderValidationStatusTest public void binderWithStatusHandler_fieldValidationNoBeanValidation_handlerGetsStatusUpdates() { AtomicReference<BinderValidationStatus<?>> statusCapture = new AtomicReference<>(); binder.forField(nameField).withValidator(notEmpty) - .withValidationStatusHandler(evt -> { - fail("Using a custom status change handler so no change should end up here"); - }).bind(Person::getFirstName, Person::setFirstName); + .withValidationStatusHandler(evt -> fail( + "Using a custom status change handler so no change should end up here")) + .bind(Person::getFirstName, Person::setFirstName); binder.forField(ageField).withConverter(stringToInteger) - .withValidator(notNegative).withValidationStatusHandler(evt -> { - fail("Using a custom status change handler so no change should end up here"); - }).bind(Person::getAge, Person::setAge); + .withValidator(notNegative) + .withValidationStatusHandler(evt -> fail( + "Using a custom status change handler so no change should end up here")) + .bind(Person::getAge, Person::setAge); - binder.setValidationStatusHandler(r -> { - statusCapture.set(r); - }); + binder.setValidationStatusHandler(r -> statusCapture.set(r)); binder.setBean(item); assertNull(nameField.getComponentError()); @@ -303,20 +302,19 @@ public class BinderValidationStatusTest public void binderWithStatusHandler_fieldAndBeanLevelValidation_handlerGetsStatusUpdates() { AtomicReference<BinderValidationStatus<?>> statusCapture = new AtomicReference<>(); binder.forField(nameField).withValidator(notEmpty) - .withValidationStatusHandler(evt -> { - fail("Using a custom status change handler so no change should end up here"); - }).bind(Person::getFirstName, Person::setFirstName); + .withValidationStatusHandler(evt -> fail( + "Using a custom status change handler so no change should end up here")) + .bind(Person::getFirstName, Person::setFirstName); binder.forField(ageField).withConverter(stringToInteger) - .withValidator(notNegative).withValidationStatusHandler(evt -> { - fail("Using a custom status change handler so no change should end up here"); - }).bind(Person::getAge, Person::setAge); + .withValidator(notNegative) + .withValidationStatusHandler(evt -> fail( + "Using a custom status change handler so no change should end up here")) + .bind(Person::getAge, Person::setAge); binder.withValidator( bean -> !bean.getFirstName().isEmpty() && bean.getAge() > 0, "Need first name and age"); - binder.setValidationStatusHandler(r -> { - statusCapture.set(r); - }); + binder.setValidationStatusHandler(r -> statusCapture.set(r)); binder.setBean(item); assertNull(nameField.getComponentError()); @@ -489,13 +487,9 @@ public class BinderValidationStatusTest BindingBuilder<Person, String> binding = binder.forField(nameField); binding.bind(Person::getFirstName, Person::setFirstName); - binder.setValidationStatusHandler(results -> { - fail(); - }); + binder.setValidationStatusHandler(results -> fail()); - binder.setValidationStatusHandler(results -> { - capture.set(results); - }); + binder.setValidationStatusHandler(results -> capture.set(results)); nameField.setValue("foo"); binder.validate(); diff --git a/server/src/test/java/com/vaadin/data/ValidatorTest.java b/server/src/test/java/com/vaadin/data/ValidatorTest.java index 7d29b6941e..b2c21581f5 100644 --- a/server/src/test/java/com/vaadin/data/ValidatorTest.java +++ b/server/src/test/java/com/vaadin/data/ValidatorTest.java @@ -61,7 +61,8 @@ public class ValidatorTest extends ValidatorTestBase { if (locale.getLanguage().equals("fi")) { return finnishError; - } else if (locale.getLanguage().equals("en")) { + } + if (locale.getLanguage().equals("en")) { return englishError; } return notTranslatableError; diff --git a/server/src/test/java/com/vaadin/server/VaadinServiceTest.java b/server/src/test/java/com/vaadin/server/VaadinServiceTest.java index 6219be0a29..6e40fdf0ce 100644 --- a/server/src/test/java/com/vaadin/server/VaadinServiceTest.java +++ b/server/src/test/java/com/vaadin/server/VaadinServiceTest.java @@ -158,9 +158,8 @@ public class VaadinServiceTest { MockVaadinSession session = new MockVaadinSession(service); session.lock(); - service.accessSession(session, () -> { - CurrentInstance.set(String.class, "Set in task"); - }); + service.accessSession(session, + () -> CurrentInstance.set(String.class, "Set in task")); CurrentInstance.set(String.class, "Original value"); service.runPendingAccessTasks(session); diff --git a/server/src/test/java/com/vaadin/tests/data/converter/ConverterTest.java b/server/src/test/java/com/vaadin/tests/data/converter/ConverterTest.java index 3c31fddd7e..81304885c3 100644 --- a/server/src/test/java/com/vaadin/tests/data/converter/ConverterTest.java +++ b/server/src/test/java/com/vaadin/tests/data/converter/ConverterTest.java @@ -14,9 +14,8 @@ public class ConverterTest { SerializableFunction<String, Result<String>> toModel = presentation -> { if (presentation.startsWith("presentation-")) { return Result.ok(presentation.substring("presentation-".length())); - } else { - return Result.error("invalid prefix: " + presentation); } + return Result.error("invalid prefix: " + presentation); }; SerializableFunction<String, String> toPresentation = model -> "presentation-" diff --git a/server/src/test/java/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java b/server/src/test/java/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java index f3a44a7bf2..5a21e7e793 100644 --- a/server/src/test/java/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java +++ b/server/src/test/java/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java @@ -15,7 +15,6 @@ */ package com.vaadin.tests.design.designroot; -import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Notification; import com.vaadin.ui.TextField; @@ -29,12 +28,8 @@ public class ExtendedDesignWithEmptyAnnotation customField.setPlaceholder("Something"); addComponent(customField); - ok.addClickListener((ClickEvent event) -> { - Notification.show("OK"); - }); + ok.addClickListener(e -> Notification.show("OK")); - CaNCEL.addClickListener((ClickEvent event) -> { - Notification.show("cancel"); - }); + CaNCEL.addClickListener(e -> Notification.show("cancel")); } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java b/server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java index 2adbfe2df8..45844bee25 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java @@ -10,7 +10,6 @@ import org.junit.Test; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.UI; /** @@ -23,9 +22,7 @@ public class ButtonClickTest { public void clickDetachedButton() { Button b = new Button(); AtomicInteger counter = new AtomicInteger(0); - b.addClickListener((ClickEvent event) -> { - counter.incrementAndGet(); - }); + b.addClickListener(e -> counter.incrementAndGet()); b.click(); assertEquals(1, counter.get()); @@ -65,8 +62,6 @@ public class ButtonClickTest { private void addClickListener(Button b) { clicked = false; - b.addClickListener((ClickEvent ev) -> { - clicked = true; - }); + b.addClickListener(e -> clicked = true); } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/window/AttachDetachWindowTest.java b/server/src/test/java/com/vaadin/tests/server/component/window/AttachDetachWindowTest.java index cd7570e7b6..50385c5aed 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/window/AttachDetachWindowTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/window/AttachDetachWindowTest.java @@ -3,15 +3,12 @@ package com.vaadin.tests.server.component.window; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import org.junit.Assert; import org.junit.Test; import com.vaadin.server.ClientConnector; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinSession; import com.vaadin.tests.util.AlwaysLockedVaadinSession; -import com.vaadin.ui.HasComponents.ComponentAttachEvent; -import com.vaadin.ui.HasComponents.ComponentDetachEvent; import com.vaadin.ui.Label; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; @@ -222,12 +219,10 @@ public class AttachDetachWindowTest { final Window window = new Window(); final boolean[] eventFired = new boolean[1]; - ui.addComponentAttachListener((ComponentAttachEvent event) -> { - eventFired[0] = event.getAttachedComponent().equals(window); - }); + ui.addComponentAttachListener( + e -> eventFired[0] = e.getAttachedComponent().equals(window)); ui.addWindow(window); - assertTrue("Attach event is not fired for added window", - eventFired[0]); + assertTrue("Attach event is not fired for added window", eventFired[0]); } @Test @@ -236,9 +231,8 @@ public class AttachDetachWindowTest { final Window window = new Window(); final boolean[] eventFired = new boolean[1]; - ui.addComponentDetachListener((ComponentDetachEvent event) -> { - eventFired[0] = event.getDetachedComponent().equals(window); - }); + ui.addComponentDetachListener( + e -> eventFired[0] = e.getDetachedComponent().equals(window)); ui.addWindow(window); ui.removeWindow(window); diff --git a/server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java b/server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java index 2a756da1cb..ee520a78f9 100644 --- a/server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java +++ b/server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java @@ -1283,9 +1283,7 @@ public class NavigatorTest { navigator.navigateTo("view1"); AtomicInteger leaveCount = new AtomicInteger(0); - navigator.runAfterLeaveConfirmation(() -> { - leaveCount.incrementAndGet(); - }); + navigator.runAfterLeaveConfirmation(() -> leaveCount.incrementAndGet()); assertEquals(0, leaveCount.get()); eventRef.get().navigate(); assertEquals(1, leaveCount.get()); diff --git a/server/src/test/java/com/vaadin/ui/CheckBoxTest.java b/server/src/test/java/com/vaadin/ui/CheckBoxTest.java index d2c280f12d..076c129914 100644 --- a/server/src/test/java/com/vaadin/ui/CheckBoxTest.java +++ b/server/src/test/java/com/vaadin/ui/CheckBoxTest.java @@ -49,9 +49,8 @@ public class CheckBoxTest { CheckBox cb = new CheckBox(); ui.setContent(cb); AtomicBoolean userOriginated = new AtomicBoolean(false); - cb.addValueChangeListener(e -> { - userOriginated.set(e.isUserOriginated()); - }); + cb.addValueChangeListener( + e -> userOriginated.set(e.isUserOriginated())); ComponentTest.syncToClient(cb); ServerRpcManager.getRpcProxy(cb, CheckBoxServerRpc.class) .setChecked(true, new MouseEventDetails()); @@ -69,9 +68,8 @@ public class CheckBoxTest { CheckBox cb = new CheckBox(); ui.setContent(cb); AtomicBoolean userOriginated = new AtomicBoolean(true); - cb.addValueChangeListener(e -> { - userOriginated.set(e.isUserOriginated()); - }); + cb.addValueChangeListener( + e -> userOriginated.set(e.isUserOriginated())); cb.setValue(true); assertFalse(userOriginated.get()); userOriginated.set(true); |