]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use lambdas where appropriate
authorPer-Åke Minborg <minborg@speedment.com>
Fri, 28 Oct 2016 23:01:40 +0000 (16:01 -0700)
committerVaadin Code Review <review@vaadin.com>
Mon, 7 Nov 2016 06:56:41 +0000 (06:56 +0000)
Change-Id: I80b73b653e97904605dc62484a7448f3bfbf722d

38 files changed:
server/src/main/java/com/vaadin/server/AbstractClientConnector.java
server/src/main/java/com/vaadin/server/JavaScriptCallbackHelper.java
server/src/main/java/com/vaadin/server/LegacyVaadinPortlet.java
server/src/main/java/com/vaadin/server/LegacyVaadinServlet.java
server/src/main/java/com/vaadin/server/VaadinService.java
server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
server/src/main/java/com/vaadin/server/communication/LegacyUidlWriter.java
server/src/main/java/com/vaadin/server/communication/PushHandler.java
server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java
server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java
server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java
server/src/main/java/com/vaadin/ui/AbsoluteLayout.java
server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
server/src/main/java/com/vaadin/ui/AbstractComponent.java
server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
server/src/main/java/com/vaadin/ui/CheckBox.java
server/src/main/java/com/vaadin/ui/CssLayout.java
server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java
server/src/main/java/com/vaadin/ui/Embedded.java
server/src/main/java/com/vaadin/ui/GridLayout.java
server/src/main/java/com/vaadin/ui/Image.java
server/src/main/java/com/vaadin/ui/JavaScript.java
server/src/main/java/com/vaadin/ui/LoginForm.java
server/src/main/java/com/vaadin/ui/Panel.java
server/src/main/java/com/vaadin/ui/PopupView.java
server/src/main/java/com/vaadin/ui/Slider.java
server/src/main/java/com/vaadin/ui/TabSheet.java
server/src/main/java/com/vaadin/ui/declarative/Design.java
server/src/main/java/com/vaadin/ui/declarative/ShouldWriteDataDelegate.java
server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java
server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java
server/src/test/java/com/vaadin/server/VaadinSessionTest.java
server/src/test/java/com/vaadin/tests/VaadinClasses.java
server/src/test/java/com/vaadin/tests/design/ComponentFactoryTest.java
server/src/test/java/com/vaadin/tests/design/DeclarativeTestBase.java
server/src/test/java/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java
server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java
server/src/test/java/com/vaadin/tests/server/component/window/AttachDetachWindowTest.java

index 3299568778129483fd881dd05729bd5fde4af6f9..b1c543b46e2f6bc220d89a46a94c3f293d584147 100644 (file)
@@ -537,36 +537,30 @@ public abstract class AbstractClientConnector
         final Iterator<Component> componentsIterator = ((HasComponents) connector)
                 .iterator();
         final Iterator<Extension> extensionsIterator = extensions.iterator();
-        Iterable<? extends ClientConnector> combinedIterable = new Iterable<ClientConnector>() {
-
+        Iterable<? extends ClientConnector> combinedIterable = () -> new Iterator<ClientConnector>() {
+            
             @Override
-            public Iterator<ClientConnector> iterator() {
-                return new Iterator<ClientConnector>() {
-
-                    @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;
     }
index cdd42c19da8090ac0fd703da4faa74d261dfff6a..9b066a4ff8903fd34ddab9806adc680a8ed755d6 100644 (file)
@@ -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);
index ab0f9666e961c99a0032875e582f92faa2d2c91d..4553f577a2a8302f1150693974481310591e89ea 100644 (file)
@@ -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);
             }
         });
     }
index 7f27c4dd195db446a593b72c3b073c06bb196280..06628d644af236de8495998bb07ed62a8c6860b4 100644 (file)
@@ -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);
             }
         });
     }
index af61064ada2259d57fd21fa7baf5d2a6cef42f36..28b7ca04a1a88932384d9c42d638cfb833ada68b 100644 (file)
@@ -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<UI> 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<UI> 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<UI> 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();
                 });
             }
         }
index 6a860bd5e27aa47a1726883686a47dc69db76b71..2a5af77b84efae7db9a9b139031e9595477d295a 100644 (file)
@@ -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);
         });
     }
 }
index 498dcf5bf4eab3ab39fa9c7218b61293ff5455af..52c32ff89204e3e97e9d7dad866582a800d9fd98 100644 (file)
@@ -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<Component>() {
-            @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;
         });
     }
 
index 6727adc427500e50585774eb9dfce59fcf298de6..5423226e6ad5d4faa73fd478719629682cbd0cfa 100644 (file)
@@ -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);
         }
     };
 
index 9f1c039123a3b5ec84d7dfecb5937dcdb51e13b2..140e41b992b37d3fc77d5eeb74a321cca7f9e225 100644 (file)
@@ -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()
index 92684a689e9dfd90c5130ce377dfbbc4413b7715..a087a1ed31fc40d2b924d1404e7ac477697b6d77 100644 (file)
@@ -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<String> paths = new ArrayList<>(addonThemes.keySet());
-            Collections.sort(paths, new Comparator<String>() {
-
-                @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<String> mixins = new ArrayList<>();
index 1e159a68c3369c0a3633507590b3300ba4e706fb..b5e377fffcabf1d375cf479f22b2b0dbad1e0227 100644 (file)
@@ -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;
         }
     };
 
index 04c53fa84ce65c7b72a1484dd10ca520422edb4f..e968568a09f53f2606dd0f328fe86e3f11d85ad8 100644 (file)
@@ -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<Component, ComponentPosition> componentToCoordinates = new LinkedHashMap<>();
index b9503617987b1d417acd7b54add33d0b37ba7029..7f79cecf551512273a0443ce9b2de6e42c1d0639 100644 (file)
@@ -87,13 +87,7 @@ public abstract class AbstractColorPicker extends AbstractField<Color> {
         }
     }
 
-    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";
index dd6e44735d41c27c7b0f7a8df789602401e1179a..f827e3c6f4e1e597f0625894853c68ba0ec4c599 100644 (file)
@@ -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));
             });
         }
 
index f4fadeacfb71186ea04122a61782b3812d247794..6c995611fbec323785be70e019963d3e17c78a28 100644 (file)
@@ -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);
 
index 72d5f9a56c0322f6532fb9e0226b5ed02fa31781..8048bcd899762f9dbe97cb484e0fa3550cd5b584 100644 (file)
@@ -38,34 +38,28 @@ import com.vaadin.ui.declarative.DesignContext;
 public class CheckBox extends AbstractField<Boolean>
         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);
         }
     };
 
index da88a442a73069ffdd200d8ffad0adfc052a82cd..2c2c838cb2b8162ff4fac4361730582d601deb3b 100644 (file)
@@ -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.
index deffa066319dcb96d3a4912b3a7e201c8f2cf8da..7f2e5582200a32885796735bbce3b1e7035f2b43 100644 (file)
@@ -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<String, ProxyReceiver> receivers = new HashMap<>();
index 4d4c3472b59ff071c6b66d440760e8da5c31fe47..6c5d5e26dc3a52999b743c6be5f3df52e786855d 100644 (file)
@@ -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));
     };
 
     /**
index 81f14a4f1bfe59a5dfaeda036de7caa2b39fdc1a..afcc780e84c5c0aaccc1fe9f43cf6f76653e6b68 100644 (file)
@@ -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
index fca1bc7b8ad594ebdcba1e9dfb973cc5ff4ab416..5b7ce9ce6b39f887f17e68a363a77853e449370f 100644 (file)
@@ -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));
     };
 
     /**
index 92320c6df1598144cc73d2d9c28a6ef2691875b1..97fd0ad3f358f76da8ac663ad75dfb0c3b65413c 100644 (file)
@@ -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);
             }
         });
     }
index fe31eb3d7504c57d9abdce45e319fa2609e02921..74432d001a1e21e07e5de285a0bb0cf7b761cc21 100644 (file)
@@ -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;
 
index 95dddb000388226ca5107e67d5f7217bdec5988e..c179df9be26da691ddfcfcad85239eb246ba6c29 100644 (file)
@@ -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));
     };
 
     /**
index 7223facdfe2a83de662f2d9e68ec6d3a1e510101..ba4702342550ebc730d3a01bd58b7cb2d629a4fa 100644 (file)
@@ -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 */
 
index 3a1d77e38f1553e719cf429b360c6bd70831e1ec..f6cc37f61acc9056ca9f58e2e76330f0fa3d0807 100644 (file)
@@ -35,37 +35,32 @@ import com.vaadin.ui.declarative.DesignContext;
  */
 public class Slider extends AbstractField<Double> {
 
-    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);
         }
-
     };
 
     /**
index 12d8bdf683228ed54eaa2d02643b1f7a123513e1..562316635788b887e9dbc6fc531fae0865ba360e 100644 (file)
@@ -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);
     }
 
     /**
index b5b6762f209c853a8d497a261d8306353ec12d4d..0644b27877989d8ef91bb44004176bcb8e1f04e9 100644 (file)
@@ -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
index d0aa9faf70b963e0a1cbe3852c6ca9691df98562..5ad97fb4ef0e53b5200a574f18864c70884b7160 100644 (file)
@@ -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
index 18287d7f901c391bfaebfdea2b5a7d724cdf271b..3073517b6584fcb04975d0ec1f1003e371c8e4a9 100644 (file)
@@ -126,19 +126,13 @@ public abstract class ClickableRenderer<T, V> extends AbstractRenderer<T, V> {
     protected ClickableRenderer(Class<V> presentationType,
             String nullRepresentation) {
         super(presentationType, nullRepresentation);
-        registerRpc(new RendererClickRpc() {
-
-            @Override
-            public void click(String rowKey, String columnId,
-                    MouseEventDetails mouseDetails) {
-
-                Grid<T> 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<T> grid = getParentGrid();
+            T item = grid.getDataCommunicator().getKeyMapper().get(rowKey);
+            Column column = grid.getColumn(columnId);
+            
+            fireEvent(new RendererClickEvent<>(grid, item, column,
+                mouseDetails));
         });
     }
 
index ba3804ca8b955967d755246a2bb3c093836d3c15..c567f6e5df1c9662d8c3a84af95c467b7c0e99d0 100644 (file)
@@ -91,12 +91,8 @@ public class BinderConverterValidatorTest
         binding.withValidator(Validator.alwaysPass());
         String msg1 = "foo";
         String msg2 = "bar";
-        binding.withValidator(new Validator<String>() {
-            @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));
 
index 0310b9293d53d735972b24e4d7baa83efeff0c2d..0a26bef1f6ceb0bf1b0bde41594e6582048ccc14 100644 (file)
@@ -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();
index ac40622a02fb79168826b7be446a3a6d52ee2f3d..3e3c641de8aaac9d9770ebac48d57b0969404163 100644 (file)
@@ -152,14 +152,7 @@ public class VaadinClasses {
             findPackages(juc, basePackage, baseClass, classes);
         }
 
-        Collections.sort(classes, new Comparator<Class<? extends T>>() {
-
-            @Override
-            public int compare(Class<? extends T> o1, Class<? extends T> o2) {
-                return o1.getName().compareTo(o2.getName());
-            }
-
-        });
+        Collections.sort(classes, (Class<? extends T> o1, Class<? extends T> o2) -> o1.getName().compareTo(o2.getName()));
         return classes;
     }
 
index 977a96f245cb1afb55fddf5e3831a3379295938a..1aacaf44ccfb73b3e78e9d676abdde3b3d3d0c06 100644 (file)
@@ -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<String> 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("<vaadin-label />".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("<vaadin-label />".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("<vaadin-label />".getBytes()));
     }
@@ -112,14 +92,10 @@ public class ComponentFactoryTest {
     @Test
     public void testGetDefaultInstanceUsesComponentFactory() {
         final List<String> 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();
index 75f8ee8b208da8a74a2eb16a47ebd10294eaaabd..2b73408abc42035b476e9e4b8ed936dbec53391b 100644 (file)
@@ -34,13 +34,7 @@ public abstract class DeclarativeTestBase<T extends Component>
     private static boolean debug = false;
 
     private final Map<Class<?>, EqualsAsserter<?>> comparators = new HashMap<>();
-    private static EqualsAsserter standardEqualsComparator = new EqualsAsserter<Object>() {
-
-        @Override
-        public void assertObjectEquals(Object o1, Object o2) {
-            Assert.assertEquals(o1, o2);
-        }
-    };
+    private static final EqualsAsserter standardEqualsComparator = (EqualsAsserter<Object>) Assert::assertEquals;
 
     public class IntrospectorEqualsAsserter<C> implements EqualsAsserter<C> {
 
index 3653108fa51f7131cc8776ab1179d3c6ec67719b..ea23f847cf8c3f7a5866b802030c0dc7c6492276 100644 (file)
@@ -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");
         });
     }
 }
index eea4e3e6e3b1f5c15f2ff65853ceec61ff002043..eede9138c8450221cac3d5b9cb43e877e07024fe 100644 (file)
@@ -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;
         });
     }
 }
index a3ece24c76b019ebd6cc4574a6e41a3eea4814b0..5d0c0cc55d027cf0d0b4a84f80d27b64576ee67b 100644 (file)
@@ -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);