]> source.dussan.org Git - vaadin-framework.git/commitdiff
Replace implicit for-loop with foreach
authorPer-Åke Minborg <minborg@speedment.com>
Sat, 29 Oct 2016 06:03:46 +0000 (23:03 -0700)
committerHenri Sara <hesara@vaadin.com>
Sat, 5 Nov 2016 02:35:59 +0000 (04:35 +0200)
Change-Id: I80b73b653e97904605dc62484a7448f3bfbf7233

13 files changed:
server/src/main/java/com/vaadin/server/ComponentSizeValidator.java
server/src/main/java/com/vaadin/server/CompositeErrorMessage.java
server/src/main/java/com/vaadin/server/Page.java
server/src/main/java/com/vaadin/server/VaadinServlet.java
server/src/main/java/com/vaadin/server/communication/ResourceWriter.java
server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java
server/src/main/java/com/vaadin/ui/AbstractComponentContainer.java
server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
server/src/main/java/com/vaadin/ui/CssLayout.java
server/src/main/java/com/vaadin/ui/CustomLayout.java
server/src/main/java/com/vaadin/ui/GridLayout.java
server/src/main/java/com/vaadin/ui/TabSheet.java
server/src/main/java/com/vaadin/ui/Window.java

index a4981a94b9798a8bc3b9b7e25af4aa4c69f6b5c2..da8231eec9eac3a88cb1049b5e31fa2d2815a519 100644 (file)
@@ -518,9 +518,8 @@ public class ComponentSizeValidator implements Serializable {
      */
     private static boolean formHasNonRelativeWidthComponent(Component form) {
         HasComponents parent = (HasComponents) form;
-        for (Iterator<Component> iterator = parent.iterator(); iterator
-                .hasNext();) {
-            if (!hasRelativeWidth(iterator.next())) {
+        for (Component aParent : parent) {
+            if (!hasRelativeWidth(aParent)) {
                 return true;
             }
         }
index f96bcbac279ee14117e01075652a87f36f4f11e9..6d6a775a1b25c82ca66c8a33f45a4a358d8f2543 100644 (file)
@@ -62,9 +62,8 @@ public class CompositeErrorMessage extends AbstractErrorMessage {
         super(null);
         setErrorLevel(ErrorLevel.INFORMATION);
 
-        for (final Iterator<? extends ErrorMessage> i = errorMessages
-                .iterator(); i.hasNext();) {
-            addErrorMessage(i.next());
+        for (ErrorMessage errorMessage : errorMessages) {
+            addErrorMessage(errorMessage);
         }
 
         if (getCauses().isEmpty()) {
@@ -107,13 +106,12 @@ public class CompositeErrorMessage extends AbstractErrorMessage {
     public String toString() {
         String retval = "[";
         int pos = 0;
-        for (final Iterator<ErrorMessage> i = getCauses().iterator(); i
-                .hasNext();) {
+        for (ErrorMessage errorMessage : getCauses()) {
             if (pos > 0) {
                 retval += ",";
             }
             pos++;
-            retval += i.next().toString();
+            retval += errorMessage.toString();
         }
         retval += "]";
 
index 35fc6b96e85bd08922895900b44aee71e45981bd..d4eb2432f0fd625fa3795d8ab0d6302a71c3a814 100644 (file)
@@ -821,9 +821,8 @@ public class Page implements Serializable {
 
     public void paintContent(PaintTarget target) throws PaintException {
         if (!openList.isEmpty()) {
-            for (final Iterator<OpenResource> i = openList.iterator(); i
-                    .hasNext();) {
-                (i.next()).paintContent(target);
+            for (OpenResource anOpenList : openList) {
+                (anOpenList).paintContent(target);
             }
             openList.clear();
         }
@@ -831,9 +830,7 @@ public class Page implements Serializable {
         // Paint notifications
         if (notifications != null) {
             target.startTag("notifications");
-            for (final Iterator<Notification> it = notifications.iterator(); it
-                    .hasNext();) {
-                final Notification n = it.next();
+            for (final Notification n : notifications) {
                 target.startTag("notification");
                 if (n.getCaption() != null) {
                     target.addAttribute(
index 13713dcc54b24d1e140bd0c5fc74c689bfc099f1..b3fa527360c611e23bc4fd451d2e70e55ed7a274 100644 (file)
@@ -661,8 +661,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
     public static String stripSpecialChars(String themeName) {
         StringBuilder sb = new StringBuilder();
         char[] charArray = themeName.toCharArray();
-        for (int i = 0; i < charArray.length; i++) {
-            char c = charArray[i];
+        for (char c : charArray) {
             if (!CHAR_BLACKLIST.contains(c)) {
                 sb.append(c);
             }
@@ -1451,8 +1450,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
         }
         StringBuilder safe = new StringBuilder();
         char[] charArray = unsafe.toCharArray();
-        for (int i = 0; i < charArray.length; i++) {
-            char c = charArray[i];
+        for (char c : charArray) {
             if (isSafe(c)) {
                 safe.append(c);
             } else {
index be83bf7185dd471e0dfed13292be8573308715dd..2cfc489c11e49fca963db8c51206b41ed3a4482e 100644 (file)
@@ -21,7 +21,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Serializable;
 import java.io.Writer;
-import java.util.Iterator;
+import java.nio.charset.StandardCharsets;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -29,7 +29,6 @@ import com.vaadin.server.JsonPaintTarget;
 import com.vaadin.server.LegacyCommunicationManager;
 import com.vaadin.ui.CustomLayout;
 import com.vaadin.ui.UI;
-import java.nio.charset.StandardCharsets;
 
 /**
  * Serializes resources to JSON. Currently only used for {@link CustomLayout}
@@ -65,9 +64,8 @@ public class ResourceWriter implements Serializable {
 
         writer.write("{");
         int resourceIndex = 0;
-        for (final Iterator<Object> i = target.getUsedResources().iterator(); i
-                .hasNext();) {
-            final String resource = (String) i.next();
+        for (Object o : target.getUsedResources()) {
+            final String resource = (String) o;
             InputStream is = null;
             try {
                 is = ui.getSession().getService().getThemeResourceAsStream(ui,
@@ -84,13 +82,13 @@ public class ResourceWriter implements Serializable {
                 final StringBuffer layout = new StringBuffer();
 
                 try (InputStreamReader r = new InputStreamReader(is,
-                    StandardCharsets.UTF_8)) {
+                        StandardCharsets.UTF_8)) {
                     final char[] buffer = new char[20000];
                     int charsRead = 0;
                     while ((charsRead = r.read(buffer)) > 0) {
                         layout.append(buffer, 0, charsRead);
                     }
-                } catch (final java.io.IOException e) {
+                } catch (final IOException e) {
                     // FIXME: Handle exception
                     getLogger().log(Level.INFO, "Resource transfer failed", e);
                 }
index 4e7bc937137c5cfd9fc2eaa4360fe256f88bf999..5e5fd8a81e1b5e71068bc465b7446cda48ba5730 100644 (file)
@@ -348,17 +348,15 @@ public class ServerRpcHandler implements Serializable {
                 }
             }
 
-            for (int i = 0; i < invocations.size(); i++) {
-                MethodInvocation invocation = invocations.get(i);
-
+            for (MethodInvocation invocation : invocations) {
                 final ClientConnector connector = connectorTracker
                         .getConnector(invocation.getConnectorId());
                 if (connector == null) {
                     getLogger().log(Level.WARNING,
                             "Received RPC call for unknown connector with id {0} (tried to invoke {1}.{2})",
-                            new Object[] { invocation.getConnectorId(),
+                            new Object[]{invocation.getConnectorId(),
                                     invocation.getInterfaceName(),
-                                    invocation.getMethodName() });
+                                    invocation.getMethodName()});
                     continue;
                 }
 
index 8c10027cc4eda980ab70427576c40f3ada9eebd9..9740dff68aa0928c1c377e133b3d54845e0c8d1f 100644 (file)
@@ -72,8 +72,8 @@ public abstract class AbstractComponentContainer extends AbstractComponent
         }
 
         // Removes all component
-        for (final Iterator<Component> i = l.iterator(); i.hasNext();) {
-            removeComponent(i.next());
+        for (Component aL : l) {
+            removeComponent(aL);
         }
     }
 
@@ -90,9 +90,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent
             components.add(i.next());
         }
 
-        for (final Iterator<Component> i = components.iterator(); i
-                .hasNext();) {
-            final Component c = i.next();
+        for (final Component c : components) {
             source.removeComponent(c);
             addComponent(c);
         }
index 3ab5e32d185c09e4941f649d27216170ee849d77..f4fadeacfb71186ea04122a61782b3812d247794 100644 (file)
@@ -211,10 +211,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout
         int oldLocation = -1;
         int newLocation = -1;
         int location = 0;
-        for (final Iterator<Component> i = components.iterator(); i
-                .hasNext();) {
-            final Component component = i.next();
-
+        for (final Component component : components) {
             if (component == oldComponent) {
                 oldLocation = location;
             }
index d4daf674194516ddd20bead68e7c29a57f0ddc93..da88a442a73069ffdd200d8ffad0adfc052a82cd 100644 (file)
@@ -268,10 +268,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
         int oldLocation = -1;
         int newLocation = -1;
         int location = 0;
-        for (final Iterator<Component> i = components.iterator(); i
-                .hasNext();) {
-            final Component component = i.next();
-
+        for (final Component component : components) {
             if (component == oldComponent) {
                 oldLocation = location;
             }
index 179969765df9be2fc7fe034ccc05dc0992825e82..d7cbcee962a988dd01e27669582b575716a312ab 100644 (file)
@@ -236,9 +236,7 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent {
         // Gets the locations
         String oldLocation = null;
         String newLocation = null;
-        for (final Iterator<String> i = slots.keySet().iterator(); i
-                .hasNext();) {
-            final String location = i.next();
+        for (final String location : slots.keySet()) {
             final Component component = slots.get(location);
             if (component == oldComponent) {
                 oldLocation = location;
index a634e47cf324f37237fc83e7c358303e6a4d57c5..81f14a4f1bfe59a5dfaeda036de7caa2b39fdc1a 100644 (file)
@@ -412,9 +412,7 @@ public class GridLayout extends AbstractLayout
     public void removeComponent(int column, int row) {
 
         // Finds the area
-        for (final Iterator<Component> i = components.iterator(); i
-                .hasNext();) {
-            final Component component = i.next();
+        for (final Component component : components) {
             final ChildComponentData childData = getState().childData
                     .get(component);
             if (childData.column1 == column && childData.row1 == row) {
@@ -480,9 +478,8 @@ public class GridLayout extends AbstractLayout
 
     private float getExpandRatioSum(Map<Integer, Float> ratioMap) {
         float sum = 0;
-        for (Iterator<Entry<Integer, Float>> iterator = ratioMap.entrySet()
-                .iterator(); iterator.hasNext();) {
-            sum += iterator.next().getValue();
+        for (Float expandRatio : ratioMap.values()) {
+            sum += expandRatio;
         }
         return sum;
     }
index 91bb3a61fc90d80aa9d072ff56e7765308c69d9d..12d8bdf683228ed54eaa2d02643b1f7a123513e1 100644 (file)
@@ -710,10 +710,7 @@ public class TabSheet extends AbstractComponentContainer
         int newLocation = -1;
         int location = 0;
 
-        for (final Iterator<Component> i = components.iterator(); i
-                .hasNext();) {
-            final Component component = i.next();
-
+        for (final Component component : components) {
             if (component == oldComponent) {
                 oldLocation = location;
             }
index 318f48548d1885571cee0990cb139438b5b8fe8c..f91d61d908e9c7c732330152fda63c36e160a4cf 100644 (file)
@@ -854,8 +854,7 @@ public class Window extends Panel
      */
     @Deprecated
     public void removeCloseShortcut() {
-        for (int i = 0; i < closeShortcuts.size(); ++i) {
-            CloseShortcut sc = closeShortcuts.get(i);
+        for (CloseShortcut sc : closeShortcuts) {
             removeAction(sc);
         }
         closeShortcuts.clear();