]> source.dussan.org Git - vaadin-framework.git/commitdiff
Revert "Convert to for-each loop, Stream and switch-over-strings"
authorPekka Hyvönen <pekka@vaadin.com>
Thu, 3 Nov 2016 07:29:32 +0000 (07:29 +0000)
committerPekka Hyvönen <pekka@vaadin.com>
Thu, 3 Nov 2016 07:38:01 +0000 (09:38 +0200)
This reverts commit 73078c7560d40db80dae6a6fb8047c29a92dd8d0.

Change-Id: I2757232d1312ae5162550d9fafb26c2d657c1b7f

server/src/main/java/com/vaadin/event/EventRouter.java
server/src/main/java/com/vaadin/event/ListenerMethod.java
server/src/main/java/com/vaadin/server/ComponentSizeValidator.java
server/src/main/java/com/vaadin/server/JsonCodec.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/Upload.java
server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java
server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTest.java

index 6b96e91f25ed42eae3d9b3ab0e4d25c3d7aa96a1..c5237d9acabb975ea4de111573d648b18cef6cbb 100644 (file)
@@ -28,7 +28,6 @@ import java.util.logging.Logger;
 
 import com.vaadin.server.ErrorEvent;
 import com.vaadin.server.ErrorHandler;
-import java.util.stream.Stream;
 
 /**
  * <code>EventRouter</code> class implementing the inheritable event listening
@@ -125,10 +124,15 @@ public class EventRouter implements MethodEventSource {
 
         // Find the correct method
         final Method[] methods = target.getClass().getMethods();
-        
-        final Method method = Stream.of(methods)
-            .filter(m -> methodName.equals(m.getName()))
-            .findAny().orElseThrow(IllegalArgumentException::new);        
+        Method method = null;
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].getName().equals(methodName)) {
+                method = methods[i];
+            }
+        }
+        if (method == null) {
+            throw new IllegalArgumentException();
+        }
 
         // Remove the listeners
         if (listenerList != null) {
@@ -187,8 +191,8 @@ public class EventRouter implements MethodEventSource {
             // Send the event to all listeners. The listeners themselves
             // will filter out unwanted events.
             final Object[] listeners = listenerList.toArray();
-            for (Object listener : listeners) {
-                ListenerMethod listenerMethod = (ListenerMethod) listener;
+            for (int i = 0; i < listeners.length; i++) {
+                ListenerMethod listenerMethod = (ListenerMethod) listeners[i];
                 if (null != errorHandler) {
                     try {
                         listenerMethod.receiveEvent(event);
index bf80f1e74b92af2ee6b56547f56d67a9178f69f4..f20a14a034e6ccb9b91981e82a0abfc397a8311a 100644 (file)
@@ -25,7 +25,6 @@ import java.util.EventListener;
 import java.util.EventObject;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.stream.Stream;
 
 /**
  * <p>
@@ -119,8 +118,9 @@ public class ListenerMethod implements EventListener, Serializable {
     private static Method findHighestMethod(Class<?> cls, String method,
             Class<?>[] paramTypes) {
         Class<?>[] ifaces = cls.getInterfaces();
-        for (Class<?> iface : ifaces) {
-            Method ifaceMethod = findHighestMethod(iface, method, paramTypes);
+        for (int i = 0; i < ifaces.length; i++) {
+            Method ifaceMethod = findHighestMethod(ifaces[i], method,
+                    paramTypes);
             if (ifaceMethod != null) {
                 return ifaceMethod;
             }
@@ -132,12 +132,14 @@ public class ListenerMethod implements EventListener, Serializable {
                 return parentMethod;
             }
         }
-        
-        // we ignore parameter types for now - you need to add this
-        return Stream.of(cls.getMethods())
-            .filter(m -> method.equals(m.getName()))
-            .findAny().orElse(null);
-        
+        Method[] methods = cls.getMethods();
+        for (int i = 0; i < methods.length; i++) {
+            // we ignore parameter types for now - you need to add this
+            if (methods[i].getName().equals(method)) {
+                return methods[i];
+            }
+        }
+        return null;
     }
 
     /**
@@ -245,9 +247,9 @@ public class ListenerMethod implements EventListener, Serializable {
         // Finds the correct method
         final Method[] methods = target.getClass().getMethods();
         Method method = null;
-        for (Method method1 : methods) {
-            if (method1.getName().equals(methodName)) {
-                method = method1;
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].getName().equals(methodName)) {
+                method = methods[i];
             }
         }
         if (method == null) {
@@ -357,9 +359,9 @@ public class ListenerMethod implements EventListener, Serializable {
         // Find the correct method
         final Method[] methods = target.getClass().getMethods();
         Method method = null;
-        for (Method method1 : methods) {
-            if (method1.getName().equals(methodName)) {
-                method = method1;
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].getName().equals(methodName)) {
+                method = methods[i];
             }
         }
         if (method == null) {
@@ -459,9 +461,9 @@ public class ListenerMethod implements EventListener, Serializable {
         // Finds the correct method
         final Method[] methods = target.getClass().getMethods();
         Method method = null;
-        for (Method method1 : methods) {
-            if (method1.getName().equals(methodName)) {
-                method = method1;
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].getName().equals(methodName)) {
+                method = methods[i];
             }
         }
         if (method == null) {
index c7c6541c9ef0c0a09d9478e7f91bfdc5cc91b087..e68fbb59033f8e4048ff64ff4ebb6171fea7f8a6 100644 (file)
@@ -92,7 +92,9 @@ public class ComponentSizeValidator implements Serializable {
             }
         } else if (isForm(component)) {
             HasComponents form = (HasComponents) component;
-            for (Component child : form) {
+            for (Iterator<Component> iterator = form.iterator(); iterator
+                    .hasNext();) {
+                Component child = iterator.next();
                 errors = validateComponentRelativeSizes(child, errors, parent);
             }
         }
index a85dd5c0e9522a31b345b0a4c055c90f154ea08b..588443d55bb3cf5b78fb50e1dcee7f4279a238f1 100644 (file)
@@ -398,19 +398,16 @@ public class JsonCodec implements Serializable {
                     connectorTracker);
         }
 
-        if (null != transportType) // Collections
-        switch (transportType) {
-            case JsonConstants.VTYPE_LIST:
-                return decodeList(targetType, restrictToInternalTypes,
+        // Collections
+        if (JsonConstants.VTYPE_LIST.equals(transportType)) {
+            return decodeList(targetType, restrictToInternalTypes,
                     (JsonArray) encodedJsonValue, connectorTracker);
-            case JsonConstants.VTYPE_SET:
-                return decodeSet(targetType, restrictToInternalTypes,
+        } else if (JsonConstants.VTYPE_SET.equals(transportType)) {
+            return decodeSet(targetType, restrictToInternalTypes,
                     (JsonArray) encodedJsonValue, connectorTracker);
-            case JsonConstants.VTYPE_MAP:
-                return decodeMap(targetType, restrictToInternalTypes,
+        } else if (JsonConstants.VTYPE_MAP.equals(transportType)) {
+            return decodeMap(targetType, restrictToInternalTypes,
                     encodedJsonValue, connectorTracker);
-            default:
-                break;
         }
 
         // Arrays
@@ -430,23 +427,20 @@ public class JsonCodec implements Serializable {
             return connectorTracker.getConnector(encodedJsonValue.asString());
         }
 
-
-        if (null != transportType) // Legacy types
-        switch (transportType) {
-            case JsonConstants.VTYPE_STRING:
-                return encodedJsonValue.asString();
-            case JsonConstants.VTYPE_INTEGER:
-                return (int) encodedJsonValue.asNumber();
-            case JsonConstants.VTYPE_LONG:
-                return (long) encodedJsonValue.asNumber();
-            case JsonConstants.VTYPE_FLOAT:
-                return (float) encodedJsonValue.asNumber();
-            case JsonConstants.VTYPE_DOUBLE:
-                return encodedJsonValue.asNumber();
-            case JsonConstants.VTYPE_BOOLEAN:
-                return encodedJsonValue.asBoolean();
-            default:
-                break;
+        // Legacy types
+
+        if (JsonConstants.VTYPE_STRING.equals(transportType)) {
+            return encodedJsonValue.asString();
+        } else if (JsonConstants.VTYPE_INTEGER.equals(transportType)) {
+            return (int) encodedJsonValue.asNumber();
+        } else if (JsonConstants.VTYPE_LONG.equals(transportType)) {
+            return (long) encodedJsonValue.asNumber();
+        } else if (JsonConstants.VTYPE_FLOAT.equals(transportType)) {
+            return (float) encodedJsonValue.asNumber();
+        } else if (JsonConstants.VTYPE_DOUBLE.equals(transportType)) {
+            return encodedJsonValue.asNumber();
+        } else if (JsonConstants.VTYPE_BOOLEAN.equals(transportType)) {
+            return encodedJsonValue.asBoolean();
         }
 
         throw new JsonException("Unknown type " + transportType);
index 9bc01e7ce255a11efd18e8d4d55af3e7af37c0d9..6903a17ddd3cb819b0c5e225b8fa5aa6f91e0480 100644 (file)
@@ -203,42 +203,45 @@ public class ClassPathExplorer {
         if (directory.exists() && !directory.isHidden()) {
             // Get the list of the files contained in the directory
             String[] files = directory.list();
-            for (String file : files) {
+            for (int i = 0; i < files.length; i++) {
                 // we are only interested in .gwt.xml files
-                if (!file.endsWith(".gwt.xml")) {
+                if (!files[i].endsWith(".gwt.xml")) {
                     continue;
                 }
+
                 // remove the .gwt.xml extension
-                String classname = file.substring(0, file.length() - 8);
+                String classname = files[i].substring(0, files[i].length() - 8);
                 String packageName = locationString
                     .substring(locationString.lastIndexOf('/') + 1);
                 classname = packageName + "." + classname;
+
                 if (!WidgetSetBuilder.isWidgetset(classname)) {
                     // Only return widgetsets and not GWT modules to avoid
                     // comparing modules and widgetsets
                     continue;
                 }
+
                 if (!widgetsets.containsKey(classname)) {
                     String packagePath = packageName.replaceAll("\\.", "/");
 
                     String basePath = location.getFile();
                     if (basePath.endsWith("/" + packagePath)) {
                         basePath = basePath.replaceAll("/" + packagePath + "$",
-                            "");
+                                "");
                     } else if (basePath.endsWith("/" + packagePath + "/")) {
                         basePath = basePath.replaceAll("/" + packagePath + "/$",
-                            "");
+                                "");
                     } else {
                         throw new IllegalStateException(
-                            "Error trying to find base path, location ("
-                                + location.getFile()
-                                + ") does not end in expected '/"
-                                + packagePath + "'");
+                                "Error trying to find base path, location ("
+                                        + location.getFile()
+                                        + ") does not end in expected '/"
+                                        + packagePath + "'");
                     }
                     try {
                         URL url = new URL(location.getProtocol(),
-                            location.getHost(), location.getPort(),
-                            basePath);
+                                location.getHost(), location.getPort(),
+                                basePath);
                         widgetsets.put(classname, url);
                     } catch (MalformedURLException e) {
                         // should never happen as based on an existing URL,
@@ -270,8 +273,8 @@ public class ClassPathExplorer {
                             .getValue("Vaadin-Widgetsets");
                     if (value != null) {
                         String[] widgetsetNames = value.split(",");
-                        for (String widgetsetName : widgetsetNames) {
-                            String widgetsetname = widgetsetName.trim();
+                        for (int i = 0; i < widgetsetNames.length; i++) {
+                            String widgetsetname = widgetsetNames[i].trim();
                             if (!widgetsetname.equals("")) {
                                 widgetsets.put(widgetsetname, location);
                             }
@@ -283,8 +286,8 @@ public class ClassPathExplorer {
                             .getValue("Vaadin-Stylesheets");
                     if (value != null) {
                         String[] stylesheets = value.split(",");
-                        for (String untrimmedStylesheet : stylesheets) {
-                            String stylesheet = untrimmedStylesheet.trim();
+                        for (int i = 0; i < stylesheets.length; i++) {
+                            String stylesheet = stylesheets[i].trim();
                             if (!stylesheet.equals("")) {
                                 addonStyles.put(stylesheet, location);
                             }
@@ -323,7 +326,8 @@ public class ClassPathExplorer {
         debug("Classpath: " + classpath);
 
         String[] split = classpath.split(pathSep);
-        for (String classpathEntry : split) {
+        for (int i = 0; i < split.length; i++) {
+            String classpathEntry = split[i];
             if (acceptClassPathEntry(classpathEntry)) {
                 locations.add(classpathEntry);
             }
@@ -455,18 +459,20 @@ public class ClassPathExplorer {
 
         // add all directories recursively
         File[] dirs = file.listFiles(DIRECTORIES_ONLY);
-        for (File dir : dirs) {
+        for (int i = 0; i < dirs.length; i++) {
             try {
                 // add the present directory
-                if (!dir.isHidden() && !dir.getPath().contains(File.separator + ".")) {
-                    String key = dir.getCanonicalPath() + "/" + name + dir.getName();
-                    URL url = dir.getCanonicalFile().toURI().toURL();
+                if (!dirs[i].isHidden()
+                        && !dirs[i].getPath().contains(File.separator + ".")) {
+                    String key = dirs[i].getCanonicalPath() + "/" + name
+                            + dirs[i].getName();
+                    URL url = dirs[i].getCanonicalFile().toURI().toURL();
                     locations.put(key, url);
                 }
-            }catch (Exception ioe) {
+            } catch (Exception ioe) {
                 return;
             }
-            include(name + dir.getName(), dir, locations);
+            include(name + dirs[i].getName(), dirs[i], locations);
         }
     }
 
index cb0e1445ab1675506b5e6327b29e4f8f5ca3b656..5aa008e8293bb9627e27b29d93df835fad675e44 100644 (file)
@@ -301,8 +301,8 @@ public class AbsoluteLayout extends AbstractLayout
             }
 
             String[] cssProperties = css.split(";");
-            for (String cssProperty : cssProperties) {
-                String[] keyValuePair = cssProperty.split(":");
+            for (int i = 0; i < cssProperties.length; i++) {
+                String[] keyValuePair = cssProperties[i].split(":");
                 String key = keyValuePair[0].trim();
                 if (key.equals("")) {
                     continue;
@@ -319,27 +319,22 @@ public class AbsoluteLayout extends AbstractLayout
                     String symbol = value.replaceAll("[0-9\\.\\-]+", "");
                     if (!symbol.equals("")) {
                         value = value.substring(0, value.indexOf(symbol))
-                            .trim();
+                                .trim();
                     }
                     float v = Float.parseFloat(value);
                     Unit unit = Unit.getUnitFromSymbol(symbol);
-                    switch (key) {
-                        case "top":
-                            topValue = v;
-                            topUnits = unit;
-                            break;
-                        case "right":
-                            rightValue = v;
-                            rightUnits = unit;
-                            break;
-                        case "bottom":
-                            bottomValue = v;
-                            bottomUnits = unit;
-                            break;
-                        case "left":
-                            leftValue = v;
-                            leftUnits = unit;
-                            break;
+                    if (key.equals("top")) {
+                        topValue = v;
+                        topUnits = unit;
+                    } else if (key.equals("right")) {
+                        rightValue = v;
+                        rightUnits = unit;
+                    } else if (key.equals("bottom")) {
+                        bottomValue = v;
+                        bottomUnits = unit;
+                    } else if (key.equals("left")) {
+                        leftValue = v;
+                        leftUnits = unit;
                     }
                 }
             }
index 155bdfb811f2bb62dd2ee71f998ec686e194cee0..a08fce099e26c42d7d8cd49556f27811a418baca 100644 (file)
@@ -840,7 +840,9 @@ public class Upload extends AbstractComponent
         // this is implemented differently than other listeners to maintain
         // backwards compatibility
         if (progressListeners != null) {
-            for (ProgressListener l : progressListeners) {
+            for (Iterator<ProgressListener> it = progressListeners
+                    .iterator(); it.hasNext();) {
+                ProgressListener l = it.next();
                 l.updateProgress(totalBytes, contentLength);
             }
         }
index 2fad5fb14f1cfc13e69704a3e0bbc31e51a31529..44248d095b587b63815f1bf432b35c9daeb0fb92 100644 (file)
@@ -318,11 +318,11 @@ public class DesignAttributeHandler implements Serializable {
         propertyName = removeSubsequentUppercase(propertyName);
         String[] words = propertyName.split("(?<!^)(?=[A-Z])");
         StringBuilder builder = new StringBuilder();
-        for (String word : words) {
+        for (int i = 0; i < words.length; i++) {
             if (builder.length() > 0) {
                 builder.append("-");
             }
-            builder.append(word.toLowerCase());
+            builder.append(words[i].toLowerCase());
         }
         return builder.toString();
     }
index ac530c266f6cf1591d5a218a33f69ae9beb5d382..0711ae24bf5a2bc14576f85de159546935805b68 100644 (file)
@@ -235,15 +235,14 @@ public class BinderConverterValidatorTest
                     throw new IllegalArgumentException(
                             "Value must be OK or NOTOK");
                 }, model -> {
-            switch (model) {
-                case "1":
-                    return "OK";
-                case "2":
-                    return "NOTOK";
-                default:
-                    throw new IllegalArgumentException(
-                        "Value in model must be 1 or 2");
-            }
+                    if (model.equals("1")) {
+                        return "OK";
+                    } else if (model.equals("2")) {
+                        return "NOTOK";
+                    } else {
+                        throw new IllegalArgumentException(
+                                "Value in model must be 1 or 2");
+                    }
                 });
         binding.bind(StatusBean::getStatus, StatusBean::setStatus);
         binder.setBean(bean);
index b8875c34fd89866f90cfa73153d3a11d60378df6..b13499983e656b6d3c0086a68de903297a3fe605 100644 (file)
@@ -97,8 +97,10 @@ public class AbstractComponentDeclarativeTest
         Boolean[] explicitImmediate = { null, Boolean.FALSE, Boolean.TRUE,
                 Boolean.TRUE };
         boolean[] immediate = { true, false, true, true };
-        for (String designElements : design) {
-            component = (AbstractComponent) Design.read(new ByteArrayInputStream(designElements.getBytes(Charset.forName("UTF-8"))));
+        for (int i = 0; i < design.length; i++) {
+            component = (AbstractComponent) Design
+                    .read(new ByteArrayInputStream(
+                            design[i].getBytes(Charset.forName("UTF-8"))));
         }
     }