From: Per-Åke Minborg Date: Fri, 28 Oct 2016 23:01:40 +0000 (-0700) Subject: Use lambdas where appropriate X-Git-Tag: 8.0.0.alpha7~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=25eba3c79655287027301b844d74a92812fc741a;p=vaadin-framework.git Use lambdas where appropriate Change-Id: I80b73b653e97904605dc62484a7448f3bfbf722d --- diff --git a/server/src/main/java/com/vaadin/server/AbstractClientConnector.java b/server/src/main/java/com/vaadin/server/AbstractClientConnector.java index 3299568778..b1c543b46e 100644 --- a/server/src/main/java/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/main/java/com/vaadin/server/AbstractClientConnector.java @@ -537,36 +537,30 @@ public abstract class AbstractClientConnector final Iterator componentsIterator = ((HasComponents) connector) .iterator(); final Iterator extensionsIterator = extensions.iterator(); - Iterable combinedIterable = new Iterable() { - + Iterable combinedIterable = () -> new Iterator() { + @Override - public Iterator iterator() { - return new Iterator() { - - @Override - public boolean hasNext() { - return componentsIterator.hasNext() - || extensionsIterator.hasNext(); - } - - @Override - public ClientConnector next() { - if (componentsIterator.hasNext()) { - return componentsIterator.next(); - } - if (extensionsIterator.hasNext()) { - return extensionsIterator.next(); - } - throw new NoSuchElementException(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - }; + public boolean hasNext() { + return componentsIterator.hasNext() + || extensionsIterator.hasNext(); + } + + @Override + public ClientConnector next() { + if (componentsIterator.hasNext()) { + return componentsIterator.next(); + } + if (extensionsIterator.hasNext()) { + return extensionsIterator.next(); + } + throw new NoSuchElementException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); } + }; return combinedIterable; } diff --git a/server/src/main/java/com/vaadin/server/JavaScriptCallbackHelper.java b/server/src/main/java/com/vaadin/server/JavaScriptCallbackHelper.java index cdd42c19da..9b066a4ff8 100644 --- a/server/src/main/java/com/vaadin/server/JavaScriptCallbackHelper.java +++ b/server/src/main/java/com/vaadin/server/JavaScriptCallbackHelper.java @@ -72,15 +72,12 @@ public class JavaScriptCallbackHelper implements Serializable { private void ensureRpc() { if (javascriptCallbackRpc == null) { - javascriptCallbackRpc = new JavaScriptCallbackRpc() { - @Override - public void call(String name, JsonArray arguments) { - JavaScriptFunction callback = callbacks.get(name); - try { - callback.call(arguments); - } catch (JsonException e) { - throw new IllegalArgumentException(e); - } + javascriptCallbackRpc = (String name, JsonArray arguments) -> { + JavaScriptFunction callback = callbacks.get(name); + try { + callback.call(arguments); + } catch (JsonException e) { + throw new IllegalArgumentException(e); } }; connector.registerRpc(javascriptCallbackRpc); diff --git a/server/src/main/java/com/vaadin/server/LegacyVaadinPortlet.java b/server/src/main/java/com/vaadin/server/LegacyVaadinPortlet.java index ab0f9666e9..4553f577a2 100644 --- a/server/src/main/java/com/vaadin/server/LegacyVaadinPortlet.java +++ b/server/src/main/java/com/vaadin/server/LegacyVaadinPortlet.java @@ -46,17 +46,13 @@ public class LegacyVaadinPortlet extends VaadinPortlet { public void init(PortletConfig portletConfig) throws PortletException { super.init(portletConfig); - getService().addSessionInitListener(new SessionInitListener() { - @Override - public void sessionInit(SessionInitEvent event) - throws ServiceException { - try { - onVaadinSessionStarted( - (VaadinPortletRequest) event.getRequest(), - (VaadinPortletSession) event.getSession()); - } catch (PortletException e) { - throw new ServiceException(e); - } + getService().addSessionInitListener((SessionInitEvent event) -> { + try { + onVaadinSessionStarted( + (VaadinPortletRequest) event.getRequest(), + (VaadinPortletSession) event.getSession()); + } catch (PortletException e) { + throw new ServiceException(e); } }); } diff --git a/server/src/main/java/com/vaadin/server/LegacyVaadinServlet.java b/server/src/main/java/com/vaadin/server/LegacyVaadinServlet.java index 7f27c4dd19..06628d644a 100644 --- a/server/src/main/java/com/vaadin/server/LegacyVaadinServlet.java +++ b/server/src/main/java/com/vaadin/server/LegacyVaadinServlet.java @@ -47,16 +47,12 @@ public class LegacyVaadinServlet extends VaadinServlet { public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); - getService().addSessionInitListener(new SessionInitListener() { - @Override - public void sessionInit(SessionInitEvent event) - throws ServiceException { - try { - onVaadinSessionStarted(event.getRequest(), - event.getSession()); - } catch (ServletException e) { - throw new ServiceException(e); - } + getService().addSessionInitListener((SessionInitEvent event) -> { + try { + onVaadinSessionStarted(event.getRequest(), + event.getSession()); + } catch (ServletException e) { + throw new ServiceException(e); } }); } diff --git a/server/src/main/java/com/vaadin/server/VaadinService.java b/server/src/main/java/com/vaadin/server/VaadinService.java index af61064ada..28b7ca04a1 100644 --- a/server/src/main/java/com/vaadin/server/VaadinService.java +++ b/server/src/main/java/com/vaadin/server/VaadinService.java @@ -457,42 +457,35 @@ public abstract class VaadinService implements Serializable { */ public void fireSessionDestroy(VaadinSession vaadinSession) { final VaadinSession session = vaadinSession; - session.access(new Runnable() { - @Override - public void run() { - if (session.getState() == State.CLOSED) { - return; - } - if (session.getState() == State.OPEN) { - closeSession(session); - } - ArrayList uis = new ArrayList<>(session.getUIs()); - for (final UI ui : uis) { - ui.accessSynchronously(new Runnable() { - @Override - public void run() { - /* - * close() called here for consistency so that it is - * always called before a UI is removed. - * UI.isClosing() is thus always true in UI.detach() - * and associated detach listeners. - */ - if (!ui.isClosing()) { - ui.close(); - } - session.removeUI(ui); - } - }); - } - // for now, use the session error handler; in the future, could - // have an API for using some other handler for session init and - // destroy listeners - eventRouter.fireEvent( - new SessionDestroyEvent(VaadinService.this, session), - session.getErrorHandler()); - - session.setState(State.CLOSED); + session.access(() -> { + if (session.getState() == State.CLOSED) { + return; + } + if (session.getState() == State.OPEN) { + closeSession(session); } + ArrayList uis = new ArrayList<>(session.getUIs()); + for (final UI ui : uis) { + ui.accessSynchronously(() -> { + /* + * close() called here for consistency so that it is + * always called before a UI is removed. + * UI.isClosing() is thus always true in UI.detach() + * and associated detach listeners. + */ + if (!ui.isClosing()) { + ui.close(); + } + session.removeUI(ui); + }); + } + // for now, use the session error handler; in the future, could + // have an API for using some other handler for session init and + // destroy listeners + eventRouter.fireEvent( + new SessionDestroyEvent(VaadinService.this, session), + session.getErrorHandler()); + session.setState(State.CLOSED); }); } @@ -1193,13 +1186,10 @@ public abstract class VaadinService implements Serializable { ArrayList uis = new ArrayList<>(session.getUIs()); for (final UI ui : uis) { if (ui.isClosing()) { - ui.accessSynchronously(new Runnable() { - @Override - public void run() { - getLogger().log(Level.FINER, "Removing closed UI {0}", - ui.getUIId()); - session.removeUI(ui); - } + ui.accessSynchronously(() -> { + getLogger().log(Level.FINER, "Removing closed UI {0}", + ui.getUIId()); + session.removeUI(ui); }); } } @@ -1215,14 +1205,11 @@ public abstract class VaadinService implements Serializable { final String sessionId = session.getSession().getId(); for (final UI ui : session.getUIs()) { if (!isUIActive(ui) && !ui.isClosing()) { - ui.accessSynchronously(new Runnable() { - @Override - public void run() { - getLogger().log(Level.FINE, - "Closing inactive UI #{0} in session {1}", - new Object[] { ui.getUIId(), sessionId }); - ui.close(); - } + ui.accessSynchronously(() -> { + getLogger().log(Level.FINE, + "Closing inactive UI #{0} in session {1}", + new Object[] { ui.getUIId(), sessionId }); + ui.close(); }); } } 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 6a860bd5e2..2a5af77b84 100644 --- a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java @@ -686,12 +686,9 @@ public class FileUploadHandler implements RequestHandler { private void cleanStreamVariable(VaadinSession session, final UI ui, final ClientConnector owner, final String variableName) { - session.accessSynchronously(new Runnable() { - @Override - public void run() { - 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/LegacyUidlWriter.java b/server/src/main/java/com/vaadin/server/communication/LegacyUidlWriter.java index 498dcf5bf4..52c32ff892 100644 --- a/server/src/main/java/com/vaadin/server/communication/LegacyUidlWriter.java +++ b/server/src/main/java/com/vaadin/server/communication/LegacyUidlWriter.java @@ -89,27 +89,24 @@ public class LegacyUidlWriter implements Serializable { // Vaadin 6 requires parents to be painted before children as component // containers rely on that their updateFromUIDL method has been called // before children start calling e.g. updateCaption - Collections.sort(paintables, new Comparator() { - @Override - public int compare(Component c1, Component c2) { - int depth1 = 0; - while (c1.getParent() != null) { - depth1++; - c1 = c1.getParent(); - } - int depth2 = 0; - while (c2.getParent() != null) { - depth2++; - c2 = c2.getParent(); - } - if (depth1 < depth2) { - return -1; - } - if (depth1 > depth2) { - return 1; - } - return 0; + Collections.sort(paintables, (Component c1, Component c2) -> { + int depth1 = 0; + while (c1.getParent() != null) { + depth1++; + c1 = c1.getParent(); } + int depth2 = 0; + while (c2.getParent() != null) { + depth2++; + c2 = c2.getParent(); + } + if (depth1 < depth2) { + return -1; + } + if (depth1 > depth2) { + return 1; + } + return 0; }); } diff --git a/server/src/main/java/com/vaadin/server/communication/PushHandler.java b/server/src/main/java/com/vaadin/server/communication/PushHandler.java index 6727adc427..5423226e6a 100644 --- a/server/src/main/java/com/vaadin/server/communication/PushHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/PushHandler.java @@ -71,43 +71,40 @@ public class PushHandler { * open by calling resource.suspend(). If there is a pending push, send it * now. */ - private final PushEventCallback establishCallback = new PushEventCallback() { - @Override - public void run(AtmosphereResource resource, UI ui) throws IOException { - getLogger().log(Level.FINER, - "New push connection for resource {0} with transport {1}", - new Object[] { resource.uuid(), resource.transport() }); - - resource.getResponse().setContentType("text/plain; charset=UTF-8"); - - VaadinSession session = ui.getSession(); - if (resource.transport() == TRANSPORT.STREAMING) { - // Must ensure that the streaming response contains - // "Connection: close", otherwise iOS 6 will wait for the - // response to this request before sending another request to - // the same server (as it will apparently try to reuse the same - // connection) - resource.getResponse().addHeader("Connection", "close"); - } - - String requestToken = resource.getRequest() - .getParameter(ApplicationConstants.CSRF_TOKEN_PARAMETER); - if (!VaadinService.isCsrfTokenValid(session, requestToken)) { - getLogger().log(Level.WARNING, - "Invalid CSRF token in new connection received from {0}", - resource.getRequest().getRemoteHost()); - // Refresh on client side, create connection just for - // sending a message - sendRefreshAndDisconnect(resource); - return; - } - - suspend(resource); - - AtmospherePushConnection connection = getConnectionForUI(ui); - assert (connection != null); - connection.connect(resource); + private final PushEventCallback establishCallback = (AtmosphereResource resource, UI ui) -> { + getLogger().log(Level.FINER, + "New push connection for resource {0} with transport {1}", + new Object[] { resource.uuid(), resource.transport() }); + + resource.getResponse().setContentType("text/plain; charset=UTF-8"); + + VaadinSession session = ui.getSession(); + if (resource.transport() == TRANSPORT.STREAMING) { + // Must ensure that the streaming response contains + // "Connection: close", otherwise iOS 6 will wait for the + // response to this request before sending another request to + // the same server (as it will apparently try to reuse the same + // connection) + resource.getResponse().addHeader("Connection", "close"); } + + String requestToken = resource.getRequest() + .getParameter(ApplicationConstants.CSRF_TOKEN_PARAMETER); + if (!VaadinService.isCsrfTokenValid(session, requestToken)) { + getLogger().log(Level.WARNING, + "Invalid CSRF token in new connection received from {0}", + resource.getRequest().getRemoteHost()); + // Refresh on client side, create connection just for + // sending a message + sendRefreshAndDisconnect(resource); + return; + } + + suspend(resource); + + AtmospherePushConnection connection = getConnectionForUI(ui); + assert (connection != null); + connection.connect(resource); }; /** @@ -117,48 +114,45 @@ public class PushHandler { * the request and send changed UI state via the push channel (we do not * respond to the request directly.) */ - private final PushEventCallback receiveCallback = new PushEventCallback() { - @Override - public void run(AtmosphereResource resource, UI ui) throws IOException { - getLogger().log(Level.FINER, "Received message from resource {0}", - resource.uuid()); - - AtmosphereRequest req = resource.getRequest(); - - AtmospherePushConnection connection = getConnectionForUI(ui); - - assert connection != null : "Got push from the client " - + "even though the connection does not seem to be " - + "valid. This might happen if a HttpSession is " - + "serialized and deserialized while the push " - + "connection is kept open or if the UI has a " - + "connection of unexpected type."; - - Reader reader = connection.receiveMessage(req.getReader()); - if (reader == null) { - // The whole message was not yet received - return; - } - - // Should be set up by caller - VaadinRequest vaadinRequest = VaadinService.getCurrentRequest(); - assert vaadinRequest != null; - - try { - new ServerRpcHandler().handleRpc(ui, reader, vaadinRequest); - connection.push(false); - } catch (JsonException e) { - getLogger().log(Level.SEVERE, "Error writing JSON to response", - e); - // Refresh on client side - sendRefreshAndDisconnect(resource); - } catch (InvalidUIDLSecurityKeyException e) { - getLogger().log(Level.WARNING, - "Invalid security key received from {0}", - resource.getRequest().getRemoteHost()); - // Refresh on client side - sendRefreshAndDisconnect(resource); - } + private final PushEventCallback receiveCallback = (AtmosphereResource resource, UI ui) -> { + getLogger().log(Level.FINER, "Received message from resource {0}", + resource.uuid()); + + AtmosphereRequest req = resource.getRequest(); + + AtmospherePushConnection connection = getConnectionForUI(ui); + + assert connection != null : "Got push from the client " + + "even though the connection does not seem to be " + + "valid. This might happen if a HttpSession is " + + "serialized and deserialized while the push " + + "connection is kept open or if the UI has a " + + "connection of unexpected type."; + + Reader reader = connection.receiveMessage(req.getReader()); + if (reader == null) { + // The whole message was not yet received + return; + } + + // Should be set up by caller + VaadinRequest vaadinRequest = VaadinService.getCurrentRequest(); + assert vaadinRequest != null; + + try { + new ServerRpcHandler().handleRpc(ui, reader, vaadinRequest); + connection.push(false); + } catch (JsonException e) { + getLogger().log(Level.SEVERE, "Error writing JSON to response", + e); + // Refresh on client side + sendRefreshAndDisconnect(resource); + } catch (InvalidUIDLSecurityKeyException e) { + getLogger().log(Level.WARNING, + "Invalid security key received from {0}", + resource.getRequest().getRemoteHost()); + // Refresh on client side + sendRefreshAndDisconnect(resource); } }; 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 9f1c039123..140e41b992 100644 --- a/server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java +++ b/server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java @@ -67,11 +67,8 @@ public class PushRequestHandler public PushRequestHandler(VaadinServletService service) throws ServiceException { - service.addServiceDestroyListener(new ServiceDestroyListener() { - @Override - public void serviceDestroy(ServiceDestroyEvent event) { - destroy(); - } + service.addServiceDestroyListener((ServiceDestroyEvent event) -> { + destroy(); }); final ServletConfig vaadinServletConfig = service.getServlet() diff --git a/server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java b/server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java index 92684a689e..a087a1ed31 100644 --- a/server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java +++ b/server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java @@ -23,7 +23,6 @@ import java.io.PrintStream; import java.net.URL; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -101,20 +100,16 @@ public class SASSAddonImportFileCreator { // Sort addon styles so that CSS imports are first and SCSS import // last List paths = new ArrayList<>(addonThemes.keySet()); - Collections.sort(paths, new Comparator() { - - @Override - public int compare(String path1, String path2) { - if (path1.toLowerCase().endsWith(".css") - && path2.toLowerCase().endsWith(".scss")) { - return -1; - } - if (path1.toLowerCase().endsWith(".scss") - && path2.toLowerCase().endsWith(".css")) { - return 1; - } - return 0; + Collections.sort(paths, (String path1, String path2) -> { + if (path1.toLowerCase().endsWith(".css") + && path2.toLowerCase().endsWith(".scss")) { + return -1; } + if (path1.toLowerCase().endsWith(".scss") + && path2.toLowerCase().endsWith(".css")) { + return 1; + } + return 0; }); List mixins = new ArrayList<>(); diff --git a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java index 1e159a68c3..b5e377fffc 100644 --- a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java +++ b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java @@ -58,14 +58,11 @@ public class ClassPathExplorer { /** * File filter that only accepts directories. */ - private final static FileFilter DIRECTORIES_ONLY = new FileFilter() { - @Override - public boolean accept(File f) { - if (f.exists() && f.isDirectory()) { - return true; - } else { - return false; - } + private final static FileFilter DIRECTORIES_ONLY = (File f) -> { + if (f.exists() && f.isDirectory()) { + return true; + } else { + return false; } }; diff --git a/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java b/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java index 04c53fa84c..e968568a09 100644 --- a/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java +++ b/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Objects; import org.jsoup.nodes.Attributes; import org.jsoup.nodes.Element; @@ -55,14 +54,10 @@ public class AbsoluteLayout extends AbstractLayout private static final String ATTR_LEFT = ":left"; private static final String ATTR_Z_INDEX = ":z-index"; - private AbsoluteLayoutServerRpc rpc = new AbsoluteLayoutServerRpc() { - - @Override - public void layoutClick(MouseEventDetails mouseDetails, - Connector clickedConnector) { - fireEvent(LayoutClickEvent.createEvent(AbsoluteLayout.this, - mouseDetails, clickedConnector)); - } + private final AbsoluteLayoutServerRpc rpc = (MouseEventDetails mouseDetails, + Connector clickedConnector) -> { + fireEvent(LayoutClickEvent.createEvent(AbsoluteLayout.this, + mouseDetails, clickedConnector)); }; // Maps each component to a position private LinkedHashMap componentToCoordinates = new LinkedHashMap<>(); diff --git a/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java b/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java index b950361798..7f79cecf55 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java +++ b/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java @@ -87,13 +87,7 @@ public abstract class AbstractColorPicker extends AbstractField { } } - private ColorPickerServerRpc rpc = new ColorPickerServerRpc() { - - @Override - public void openPopup(boolean open) { - showPopup(open); - } - }; + private ColorPickerServerRpc rpc = this::showPopup; protected static final String STYLENAME_DEFAULT = "v-colorpicker"; protected static final String STYLENAME_BUTTON = "v-button"; diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java index dd6e44735d..f827e3c6f4 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java +++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java @@ -1374,12 +1374,9 @@ 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(new ContextClickRpc() { - @Override - public void contextClick(MouseEventDetails details) { - fireEvent(new ContextClickEvent(AbstractComponent.this, - details)); - } + registerRpc((ContextClickRpc) (MouseEventDetails details) -> { + fireEvent(new ContextClickEvent(AbstractComponent.this, + details)); }); } diff --git a/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java index f4fadeacfb..6c995611fb 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java @@ -44,14 +44,10 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier, Layout.MarginHandler { - private AbstractOrderedLayoutServerRpc rpc = new AbstractOrderedLayoutServerRpc() { - - @Override - public void layoutClick(MouseEventDetails mouseDetails, - Connector clickedConnector) { - fireEvent(LayoutClickEvent.createEvent(AbstractOrderedLayout.this, - mouseDetails, clickedConnector)); - } + private final AbstractOrderedLayoutServerRpc rpc = ( + MouseEventDetails mouseDetails, Connector clickedConnector) -> { + fireEvent(LayoutClickEvent.createEvent(AbstractOrderedLayout.this, + mouseDetails, clickedConnector)); }; public static final Alignment ALIGNMENT_DEFAULT = Alignment.TOP_LEFT; @@ -507,8 +503,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout // write default attributes super.writeDesign(design, designContext); - AbstractOrderedLayout def = designContext - .getDefaultInstance(this); + AbstractOrderedLayout def = designContext.getDefaultInstance(this); writeMargin(design, getMargin(), def.getMargin(), designContext); diff --git a/server/src/main/java/com/vaadin/ui/CheckBox.java b/server/src/main/java/com/vaadin/ui/CheckBox.java index 72d5f9a56c..8048bcd899 100644 --- a/server/src/main/java/com/vaadin/ui/CheckBox.java +++ b/server/src/main/java/com/vaadin/ui/CheckBox.java @@ -38,34 +38,28 @@ import com.vaadin.ui.declarative.DesignContext; public class CheckBox extends AbstractField implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier { - private CheckBoxServerRpc rpc = new CheckBoxServerRpc() { - - @Override - public void setChecked(boolean checked, - MouseEventDetails mouseEventDetails) { - if (isReadOnly()) { - return; - } - - /* - * Client side updates the state before sending the event so we need - * to make sure the cached state is updated to match the client. If - * we do not do this, a reverting setValue() call in a listener will - * not cause the new state to be sent to the client. - * - * See #11028, #10030. - */ - getUI().getConnectorTracker().getDiffState(CheckBox.this) - .put("checked", checked); - - final Boolean oldValue = getValue(); - final Boolean newValue = checked; - - if (!newValue.equals(oldValue)) { - // The event is only sent if the switch state is changed - setValue(newValue); - } - + private CheckBoxServerRpc rpc = (boolean checked, MouseEventDetails mouseEventDetails) -> { + if (isReadOnly()) { + return; + } + + /* + * Client side updates the state before sending the event so we need + * to make sure the cached state is updated to match the client. If + * we do not do this, a reverting setValue() call in a listener will + * not cause the new state to be sent to the client. + * + * See #11028, #10030. + */ + getUI().getConnectorTracker().getDiffState(CheckBox.this) + .put("checked", checked); + + final Boolean oldValue = getValue(); + final Boolean newValue = checked; + + if (!newValue.equals(oldValue)) { + // The event is only sent if the switch state is changed + setValue(newValue); } }; diff --git a/server/src/main/java/com/vaadin/ui/CssLayout.java b/server/src/main/java/com/vaadin/ui/CssLayout.java index da88a442a7..2c2c838cb2 100644 --- a/server/src/main/java/com/vaadin/ui/CssLayout.java +++ b/server/src/main/java/com/vaadin/ui/CssLayout.java @@ -75,14 +75,9 @@ import com.vaadin.ui.declarative.DesignContext; */ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { - private CssLayoutServerRpc rpc = new CssLayoutServerRpc() { - - @Override - public void layoutClick(MouseEventDetails mouseDetails, - Connector clickedConnector) { - fireEvent(LayoutClickEvent.createEvent(CssLayout.this, mouseDetails, - clickedConnector)); - } + private CssLayoutServerRpc rpc = (MouseEventDetails mouseDetails, 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/DragAndDropWrapper.java b/server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java index deffa06631..7f2e558220 100644 --- a/server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java +++ b/server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java @@ -112,12 +112,8 @@ public class DragAndDropWrapper extends CustomComponent } - private final DragAndDropWrapperServerRpc rpc = new DragAndDropWrapperServerRpc() { - - @Override - public void poll() { - // #19616 RPC to poll the server for changes - } + private final DragAndDropWrapperServerRpc rpc = () -> { + // #19616 RPC to poll the server for changes }; private Map receivers = new HashMap<>(); diff --git a/server/src/main/java/com/vaadin/ui/Embedded.java b/server/src/main/java/com/vaadin/ui/Embedded.java index 4d4c3472b5..6c5d5e26dc 100644 --- a/server/src/main/java/com/vaadin/ui/Embedded.java +++ b/server/src/main/java/com/vaadin/ui/Embedded.java @@ -104,11 +104,8 @@ public class Embedded extends AbstractComponent implements LegacyComponent { private String altText; - private EmbeddedServerRpc rpc = new EmbeddedServerRpc() { - @Override - public void click(MouseEventDetails mouseDetails) { - fireEvent(new ClickEvent(Embedded.this, mouseDetails)); - } + private EmbeddedServerRpc rpc = (MouseEventDetails mouseDetails) -> { + fireEvent(new ClickEvent(Embedded.this, mouseDetails)); }; /** diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java index 81f14a4f1b..afcc780e84 100644 --- a/server/src/main/java/com/vaadin/ui/GridLayout.java +++ b/server/src/main/java/com/vaadin/ui/GridLayout.java @@ -76,15 +76,9 @@ public class GridLayout extends AbstractLayout implements Layout.AlignmentHandler, Layout.SpacingHandler, Layout.MarginHandler, LayoutClickNotifier { - private GridLayoutServerRpc rpc = new GridLayoutServerRpc() { - - @Override - public void layoutClick(MouseEventDetails mouseDetails, - Connector clickedConnector) { - fireEvent(LayoutClickEvent.createEvent(GridLayout.this, - mouseDetails, clickedConnector)); - - } + private GridLayoutServerRpc rpc = (MouseEventDetails mouseDetails, Connector clickedConnector) -> { + fireEvent(LayoutClickEvent.createEvent(GridLayout.this, + mouseDetails, clickedConnector)); }; /** * Cursor X position: this is where the next component with unspecified x,y diff --git a/server/src/main/java/com/vaadin/ui/Image.java b/server/src/main/java/com/vaadin/ui/Image.java index fca1bc7b8a..5b7ce9ce6b 100644 --- a/server/src/main/java/com/vaadin/ui/Image.java +++ b/server/src/main/java/com/vaadin/ui/Image.java @@ -34,11 +34,8 @@ import com.vaadin.shared.ui.image.ImageState; @SuppressWarnings("serial") public class Image extends AbstractEmbedded { - protected ImageServerRpc rpc = new ImageServerRpc() { - @Override - public void click(MouseEventDetails mouseDetails) { - fireEvent(new ClickEvent(Image.this, mouseDetails)); - } + protected ImageServerRpc rpc = (MouseEventDetails mouseDetails) -> { + fireEvent(new ClickEvent(Image.this, mouseDetails)); }; /** diff --git a/server/src/main/java/com/vaadin/ui/JavaScript.java b/server/src/main/java/com/vaadin/ui/JavaScript.java index 92320c6df1..97fd0ad3f3 100644 --- a/server/src/main/java/com/vaadin/ui/JavaScript.java +++ b/server/src/main/java/com/vaadin/ui/JavaScript.java @@ -52,16 +52,13 @@ public class JavaScript extends AbstractExtension { * object. */ public JavaScript() { - registerRpc(new JavaScriptCallbackRpc() { - @Override - public void call(String name, JsonArray arguments) { - JavaScriptFunction function = functions.get(name); - // TODO handle situation if name is not registered - try { - function.call(arguments); - } catch (JsonException e) { - throw new IllegalArgumentException(e); - } + registerRpc((JavaScriptCallbackRpc) (String name, JsonArray arguments) -> { + JavaScriptFunction function = functions.get(name); + // TODO handle situation if name is not registered + try { + function.call(arguments); + } catch (JsonException e) { + throw new IllegalArgumentException(e); } }); } diff --git a/server/src/main/java/com/vaadin/ui/LoginForm.java b/server/src/main/java/com/vaadin/ui/LoginForm.java index fe31eb3d75..74432d001a 100644 --- a/server/src/main/java/com/vaadin/ui/LoginForm.java +++ b/server/src/main/java/com/vaadin/ui/LoginForm.java @@ -315,12 +315,7 @@ public class LoginForm extends AbstractSingleComponentContainer { resource.setCacheTime(-1); setResource(LoginFormConstants.LOGIN_RESOURCE_NAME, resource); - registerRpc(new LoginFormRpc() { - @Override - public void submitCompleted() { - login(); - } - }); + registerRpc((LoginFormRpc) this::login); initialized = true; diff --git a/server/src/main/java/com/vaadin/ui/Panel.java b/server/src/main/java/com/vaadin/ui/Panel.java index 95dddb0003..c179df9be2 100644 --- a/server/src/main/java/com/vaadin/ui/Panel.java +++ b/server/src/main/java/com/vaadin/ui/Panel.java @@ -53,11 +53,8 @@ public class Panel extends AbstractSingleComponentContainer */ protected ActionManager actionManager; - private PanelServerRpc rpc = new PanelServerRpc() { - @Override - public void click(MouseEventDetails mouseDetails) { - fireEvent(new ClickEvent(Panel.this, mouseDetails)); - } + private PanelServerRpc rpc = (MouseEventDetails mouseDetails) -> { + fireEvent(new ClickEvent(Panel.this, mouseDetails)); }; /** diff --git a/server/src/main/java/com/vaadin/ui/PopupView.java b/server/src/main/java/com/vaadin/ui/PopupView.java index 7223facdfe..ba47023425 100644 --- a/server/src/main/java/com/vaadin/ui/PopupView.java +++ b/server/src/main/java/com/vaadin/ui/PopupView.java @@ -57,13 +57,7 @@ public class PopupView extends AbstractComponent implements HasComponents { } } - private final PopupViewServerRpc rpc = new PopupViewServerRpc() { - - @Override - public void setPopupVisibility(boolean visible) { - setPopupVisible(visible); - } - }; + private final PopupViewServerRpc rpc = this::setPopupVisible; /* Constructors */ diff --git a/server/src/main/java/com/vaadin/ui/Slider.java b/server/src/main/java/com/vaadin/ui/Slider.java index 3a1d77e38f..f6cc37f61a 100644 --- a/server/src/main/java/com/vaadin/ui/Slider.java +++ b/server/src/main/java/com/vaadin/ui/Slider.java @@ -35,37 +35,32 @@ import com.vaadin.ui.declarative.DesignContext; */ public class Slider extends AbstractField { - private SliderServerRpc rpc = new SliderServerRpc() { - - @Override - public void valueChanged(double value) { - - /* - * Client side updates the state before sending the event so we need - * to make sure the cached state is updated to match the client. If - * we do not do this, a reverting setValue() call in a listener will - * not cause the new state to be sent to the client. - * - * See #12133. - */ - getUI().getConnectorTracker().getDiffState(Slider.this).put("value", - value); - - try { - setValue(value, true); - } catch (final ValueOutOfBoundsException e) { - // Convert to nearest bound - double out = e.getValue().doubleValue(); - if (out < getState().minValue) { - out = getState().minValue; - } - if (out > getState().maxValue) { - out = getState().maxValue; - } - Slider.super.setValue(new Double(out), false); + private SliderServerRpc rpc = (double value) -> { + + /* + * Client side updates the state before sending the event so we need to + * make sure the cached state is updated to match the client. If we do + * not do this, a reverting setValue() call in a listener will not cause + * the new state to be sent to the client. + * + * See #12133. + */ + getUI().getConnectorTracker().getDiffState(Slider.this).put("value", + value); + + try { + setValue(value, true); + } catch (final ValueOutOfBoundsException e) { + // Convert to nearest bound + double out = e.getValue().doubleValue(); + if (out < getState().minValue) { + out = getState().minValue; } + if (out > getState().maxValue) { + out = getState().maxValue; + } + Slider.super.setValue(new Double(out), false); } - }; /** diff --git a/server/src/main/java/com/vaadin/ui/TabSheet.java b/server/src/main/java/com/vaadin/ui/TabSheet.java index 12d8bdf683..5623166357 100644 --- a/server/src/main/java/com/vaadin/ui/TabSheet.java +++ b/server/src/main/java/com/vaadin/ui/TabSheet.java @@ -138,13 +138,7 @@ public class TabSheet extends AbstractComponentContainer // expand horizontally by default setWidth(100, UNITS_PERCENTAGE); - setCloseHandler(new CloseHandler() { - - @Override - public void onTabClose(TabSheet tabsheet, Component c) { - tabsheet.removeComponent(c); - } - }); + setCloseHandler(TabSheet::removeComponent); } /** 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 b5b6762f20..0644b27877 100644 --- a/server/src/main/java/com/vaadin/ui/declarative/Design.java +++ b/server/src/main/java/com/vaadin/ui/declarative/Design.java @@ -472,11 +472,8 @@ public class Design implements Serializable { } // create listener for component creations that binds the created // components to the componentRoot instance fields - ComponentCreationListener creationListener = new ComponentCreationListener() { - @Override - public void componentCreated(ComponentCreatedEvent event) { - binder.bindField(event.getComponent(), event.getLocalId()); - } + ComponentCreationListener creationListener = (ComponentCreatedEvent event) -> { + binder.bindField(event.getComponent(), event.getLocalId()); }; designContext.addComponentCreationListener(creationListener); // create subtree diff --git a/server/src/main/java/com/vaadin/ui/declarative/ShouldWriteDataDelegate.java b/server/src/main/java/com/vaadin/ui/declarative/ShouldWriteDataDelegate.java index d0aa9faf70..5ad97fb4ef 100644 --- a/server/src/main/java/com/vaadin/ui/declarative/ShouldWriteDataDelegate.java +++ b/server/src/main/java/com/vaadin/ui/declarative/ShouldWriteDataDelegate.java @@ -35,12 +35,8 @@ public interface ShouldWriteDataDelegate extends Serializable { * is provided by a data source connected to a back end system and that the * data should thus not be written. */ - public static final ShouldWriteDataDelegate DEFAULT = new ShouldWriteDataDelegate() { - @Override - public boolean shouldWriteData(Component component) { - return false; - } - }; + public static final ShouldWriteDataDelegate DEFAULT = ( + Component component) -> false; /** * Determines whether the container data of a component should be written diff --git a/server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java b/server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java index 18287d7f90..3073517b65 100644 --- a/server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java +++ b/server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java @@ -126,19 +126,13 @@ public abstract class ClickableRenderer extends AbstractRenderer { protected ClickableRenderer(Class presentationType, String nullRepresentation) { super(presentationType, nullRepresentation); - registerRpc(new RendererClickRpc() { - - @Override - public void click(String rowKey, String columnId, - MouseEventDetails mouseDetails) { - - Grid grid = getParentGrid(); - T item = grid.getDataCommunicator().getKeyMapper().get(rowKey); - Column column = grid.getColumn(columnId); - - fireEvent(new RendererClickEvent<>(grid, item, column, - mouseDetails)); - } + registerRpc((RendererClickRpc) (String rowKey, String columnId, MouseEventDetails mouseDetails) -> { + Grid grid = getParentGrid(); + T item = grid.getDataCommunicator().getKeyMapper().get(rowKey); + Column column = grid.getColumn(columnId); + + fireEvent(new RendererClickEvent<>(grid, item, column, + mouseDetails)); }); } diff --git a/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java b/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java index ba3804ca8b..c567f6e5df 100644 --- a/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java +++ b/server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java @@ -91,12 +91,8 @@ public class BinderConverterValidatorTest binding.withValidator(Validator.alwaysPass()); String msg1 = "foo"; String msg2 = "bar"; - binding.withValidator(new Validator() { - @Override - public ValidationResult apply(String value, ValueContext context) { - return ValidationResult.error(msg1); - } - }); + binding.withValidator((String value, + ValueContext context) -> ValidationResult.error(msg1)); binding.withValidator(value -> false, msg2); binding.bind(Person::getFirstName, Person::setFirstName); @@ -356,8 +352,8 @@ public class BinderConverterValidatorTest bindName(); AtomicBoolean beanLevelValidationRun = new AtomicBoolean(); - binder.withValidator(Validator.from( - bean -> beanLevelValidationRun.getAndSet(true), "")); + binder.withValidator(Validator + .from(bean -> beanLevelValidationRun.getAndSet(true), "")); ageField.setValue("not a number"); @@ -373,8 +369,8 @@ public class BinderConverterValidatorTest bindName(); AtomicBoolean beanLevelValidationRun = new AtomicBoolean(); - binder.withValidator(Validator.from( - bean -> beanLevelValidationRun.getAndSet(true), "")); + binder.withValidator(Validator + .from(bean -> beanLevelValidationRun.getAndSet(true), "")); ageField.setValue(String.valueOf(12)); diff --git a/server/src/test/java/com/vaadin/server/VaadinSessionTest.java b/server/src/test/java/com/vaadin/server/VaadinSessionTest.java index 0310b9293d..0a26bef1f6 100644 --- a/server/src/test/java/com/vaadin/server/VaadinSessionTest.java +++ b/server/src/test/java/com/vaadin/server/VaadinSessionTest.java @@ -37,7 +37,6 @@ import org.junit.Before; import org.junit.Test; import com.vaadin.server.ClientConnector.DetachEvent; -import com.vaadin.server.ClientConnector.DetachListener; import com.vaadin.server.communication.UIInitHandler; import com.vaadin.ui.Label; import com.vaadin.ui.UI; @@ -146,24 +145,21 @@ public class VaadinSessionTest implements Serializable { // this simulates servlet container's session invalidation from another // thread - new Thread(new Runnable() { - @Override - public void run() { + new Thread(() -> { + try { + Thread.sleep(150); // delay selected so that VaadinSession + // will be already locked by the main + // thread + // when we get here + httpSessionLock.lock();// simulating servlet container's + // session lock try { - Thread.sleep(150); // delay selected so that VaadinSession - // will be already locked by the main - // thread - // when we get here - httpSessionLock.lock();// simulating servlet container's - // session lock - try { - mockService.fireSessionDestroy(session); - } finally { - httpSessionLock.unlock(); - } - } catch (InterruptedException e) { - throw new RuntimeException(e); + mockService.fireSessionDestroy(session); + } finally { + httpSessionLock.unlock(); } + } catch (InterruptedException e) { + throw new RuntimeException(e); } }).start(); @@ -180,16 +176,13 @@ public class VaadinSessionTest implements Serializable { throws InterruptedException { final AtomicBoolean detachCalled = new AtomicBoolean(false); - ui.addDetachListener(new DetachListener() { - @Override - public void detach(DetachEvent event) { - detachCalled.set(true); - Assert.assertEquals(ui, UI.getCurrent()); - Assert.assertEquals(ui.getPage(), Page.getCurrent()); - Assert.assertEquals(session, VaadinSession.getCurrent()); - Assert.assertEquals(mockService, VaadinService.getCurrent()); - Assert.assertEquals(mockServlet, VaadinServlet.getCurrent()); - } + ui.addDetachListener((DetachEvent event) -> { + detachCalled.set(true); + Assert.assertEquals(ui, UI.getCurrent()); + Assert.assertEquals(ui.getPage(), Page.getCurrent()); + Assert.assertEquals(session, VaadinSession.getCurrent()); + Assert.assertEquals(mockService, VaadinService.getCurrent()); + Assert.assertEquals(mockServlet, VaadinServlet.getCurrent()); }); session.valueUnbound( @@ -206,16 +199,13 @@ public class VaadinSessionTest implements Serializable { @Test public void threadLocalsAfterSessionDestroy() throws InterruptedException { final AtomicBoolean detachCalled = new AtomicBoolean(false); - ui.addDetachListener(new DetachListener() { - @Override - public void detach(DetachEvent event) { - detachCalled.set(true); - Assert.assertEquals(ui, UI.getCurrent()); - Assert.assertEquals(ui.getPage(), Page.getCurrent()); - Assert.assertEquals(session, VaadinSession.getCurrent()); - Assert.assertEquals(mockService, VaadinService.getCurrent()); - Assert.assertEquals(mockServlet, VaadinServlet.getCurrent()); - } + ui.addDetachListener((DetachEvent event) -> { + detachCalled.set(true); + Assert.assertEquals(ui, UI.getCurrent()); + Assert.assertEquals(ui.getPage(), Page.getCurrent()); + Assert.assertEquals(session, VaadinSession.getCurrent()); + Assert.assertEquals(mockService, VaadinService.getCurrent()); + Assert.assertEquals(mockServlet, VaadinServlet.getCurrent()); }); CurrentInstance.clearAll(); session.close(); diff --git a/server/src/test/java/com/vaadin/tests/VaadinClasses.java b/server/src/test/java/com/vaadin/tests/VaadinClasses.java index ac40622a02..3e3c641de8 100644 --- a/server/src/test/java/com/vaadin/tests/VaadinClasses.java +++ b/server/src/test/java/com/vaadin/tests/VaadinClasses.java @@ -152,14 +152,7 @@ public class VaadinClasses { findPackages(juc, basePackage, baseClass, classes); } - Collections.sort(classes, new Comparator>() { - - @Override - public int compare(Class o1, Class o2) { - return o1.getName().compareTo(o2.getName()); - } - - }); + Collections.sort(classes, (Class o1, Class o2) -> o1.getName().compareTo(o2.getName())); return classes; } diff --git a/server/src/test/java/com/vaadin/tests/design/ComponentFactoryTest.java b/server/src/test/java/com/vaadin/tests/design/ComponentFactoryTest.java index 977a96f245..1aacaf44cc 100644 --- a/server/src/test/java/com/vaadin/tests/design/ComponentFactoryTest.java +++ b/server/src/test/java/com/vaadin/tests/design/ComponentFactoryTest.java @@ -40,18 +40,14 @@ public class ComponentFactoryTest { // Set static component factory that delegate to a thread local factory static { - Design.setComponentFactory(new ComponentFactory() { - @Override - public Component createComponent(String fullyQualifiedClassName, - DesignContext context) { - ComponentFactory componentFactory = currentComponentFactory - .get(); - if (componentFactory == null) { - componentFactory = defaultFactory; - } - return componentFactory.createComponent(fullyQualifiedClassName, - context); + Design.setComponentFactory((String fullyQualifiedClassName, DesignContext context) -> { + ComponentFactory componentFactory = currentComponentFactory + .get(); + if (componentFactory == null) { + componentFactory = defaultFactory; } + return componentFactory.createComponent(fullyQualifiedClassName, + context); }); } @@ -63,14 +59,10 @@ public class ComponentFactoryTest { @Test public void testComponentFactoryLogging() { final List messages = new ArrayList<>(); - currentComponentFactory.set(new ComponentFactory() { - @Override - public Component createComponent(String fullyQualifiedClassName, - DesignContext context) { - messages.add("Requested class " + fullyQualifiedClassName); - return defaultFactory.createComponent(fullyQualifiedClassName, - context); - } + currentComponentFactory.set((ComponentFactory) (String fullyQualifiedClassName, DesignContext context) -> { + messages.add("Requested class " + fullyQualifiedClassName); + return defaultFactory.createComponent(fullyQualifiedClassName, + context); }); Design.read(new ByteArrayInputStream("".getBytes())); @@ -83,28 +75,16 @@ public class ComponentFactoryTest { @Test(expected = DesignException.class) public void testComponentFactoryReturningNull() { - currentComponentFactory.set(new ComponentFactory() { - @Override - public Component createComponent(String fullyQualifiedClassName, - DesignContext context) { - return null; - } - }); + currentComponentFactory.set((ComponentFactory) (String fullyQualifiedClassName, DesignContext context) -> null); Design.read(new ByteArrayInputStream("".getBytes())); } @Test(expected = DesignException.class) public void testComponentFactoryThrowingStuff() { - currentComponentFactory.set(new ComponentFactory() { - @Override - public Component createComponent(String fullyQualifiedClassName, - DesignContext context) { - // Will throw because class is not found - return defaultFactory.createComponent( - "foobar." + fullyQualifiedClassName, context); - } - }); + currentComponentFactory.set((ComponentFactory) (String fullyQualifiedClassName, DesignContext context) -> defaultFactory.createComponent( + "foobar." + fullyQualifiedClassName, context) // Will throw because class is not found + ); Design.read(new ByteArrayInputStream("".getBytes())); } @@ -112,14 +92,10 @@ public class ComponentFactoryTest { @Test public void testGetDefaultInstanceUsesComponentFactory() { final List classes = new ArrayList<>(); - currentComponentFactory.set(new ComponentFactory() { - @Override - public Component createComponent(String fullyQualifiedClassName, - DesignContext context) { - classes.add(fullyQualifiedClassName); - return defaultFactory.createComponent(fullyQualifiedClassName, - context); - } + currentComponentFactory.set((ComponentFactory) (String fullyQualifiedClassName, DesignContext context) -> { + classes.add(fullyQualifiedClassName); + return defaultFactory.createComponent(fullyQualifiedClassName, + context); }); DesignContext designContext = new DesignContext(); diff --git a/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBase.java b/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBase.java index 75f8ee8b20..2b73408abc 100644 --- a/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBase.java +++ b/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBase.java @@ -34,13 +34,7 @@ public abstract class DeclarativeTestBase private static boolean debug = false; private final Map, EqualsAsserter> comparators = new HashMap<>(); - private static EqualsAsserter standardEqualsComparator = new EqualsAsserter() { - - @Override - public void assertObjectEquals(Object o1, Object o2) { - Assert.assertEquals(o1, o2); - } - }; + private static final EqualsAsserter standardEqualsComparator = (EqualsAsserter) Assert::assertEquals; public class IntrospectorEqualsAsserter implements EqualsAsserter { 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 3653108fa5..ea23f847cf 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 @@ -30,18 +30,12 @@ public class ExtendedDesignWithEmptyAnnotation customField.setPlaceholder("Something"); addComponent(customField); - ok.addClickListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - Notification.show("OK"); - } + ok.addClickListener((ClickEvent event) -> { + Notification.show("OK"); }); - CaNCEL.addClickListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - Notification.show("cancel"); - } + CaNCEL.addClickListener((ClickEvent event) -> { + 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 eea4e3e6e3..eede9138c8 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 @@ -21,12 +21,8 @@ public class ButtonClickTest { public void clickDetachedButton() { Button b = new Button(); AtomicInteger counter = new AtomicInteger(0); - b.addClickListener(new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - counter.incrementAndGet(); - } + b.addClickListener((ClickEvent event) -> { + counter.incrementAndGet(); }); b.click(); @@ -67,11 +63,8 @@ public class ButtonClickTest { private void addClickListener(Button b) { clicked = false; - b.addClickListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent ev) { - clicked = true; - } + b.addClickListener((ClickEvent ev) -> { + 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 a3ece24c76..5d0c0cc55d 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 @@ -224,13 +224,8 @@ public class AttachDetachWindowTest { final Window window = new Window(); final boolean[] eventFired = new boolean[1]; - ui.addComponentAttachListener(new ComponentAttachListener() { - - @Override - public void componentAttachedToContainer( - ComponentAttachEvent event) { - eventFired[0] = event.getAttachedComponent().equals(window); - } + ui.addComponentAttachListener((ComponentAttachEvent event) -> { + eventFired[0] = event.getAttachedComponent().equals(window); }); ui.addWindow(window); Assert.assertTrue("Attach event is not fired for added window", @@ -243,13 +238,8 @@ public class AttachDetachWindowTest { final Window window = new Window(); final boolean[] eventFired = new boolean[1]; - ui.addComponentDetachListener(new ComponentDetachListener() { - - @Override - public void componentDetachedFromContainer( - ComponentDetachEvent event) { - eventFired[0] = event.getDetachedComponent().equals(window); - } + ui.addComponentDetachListener((ComponentDetachEvent event) -> { + eventFired[0] = event.getDetachedComponent().equals(window); }); ui.addWindow(window); ui.removeWindow(window);