diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-09-29 14:14:05 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-09-29 15:14:05 +0300 |
commit | adcf2e2e80c6a05ea5e43be15dc7a2576fd2bbb4 (patch) | |
tree | 0a58b0b09cb371f757d74f83ad872f2113f96272 /server/src | |
parent | 46950473fdb3cfb9d44660b3a642a9229cecded2 (diff) | |
download | vaadin-framework-adcf2e2e80c6a05ea5e43be15dc7a2576fd2bbb4.tar.gz vaadin-framework-adcf2e2e80c6a05ea5e43be15dc7a2576fd2bbb4.zip |
Use enhanced for loop instead of Iterator. (#10100)
Diffstat (limited to 'server/src')
11 files changed, 25 insertions, 58 deletions
diff --git a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java index 65e3413122..66ba4d0d9f 100644 --- a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java +++ b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java @@ -24,7 +24,6 @@ import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -533,9 +532,7 @@ public class ClassPathExplorer { } URL firstDirectory = null; - Iterator<String> it = rawClasspathEntries.iterator(); - while (it.hasNext()) { - String entry = it.next(); + for (String entry : rawClasspathEntries) { File directory = new File(entry); if (directory.exists() && !directory.isHidden() diff --git a/server/src/main/java/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java b/server/src/main/java/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java index fc01891b2e..608f84782c 100644 --- a/server/src/main/java/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java +++ b/server/src/main/java/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java @@ -29,7 +29,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -116,9 +115,7 @@ public class WidgetSetBuilder { content); // add widgetsets that do not exist - Iterator<String> i = availableWidgetSets.keySet().iterator(); - while (i.hasNext()) { - String ws = i.next(); + for (String ws : availableWidgetSets.keySet()) { if (ws.equals(widgetset)) { // do not inherit the module itself continue; diff --git a/server/src/main/java/com/vaadin/ui/ConnectorTracker.java b/server/src/main/java/com/vaadin/ui/ConnectorTracker.java index a128e24e95..2ac5e33f34 100644 --- a/server/src/main/java/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/main/java/com/vaadin/ui/ConnectorTracker.java @@ -399,10 +399,9 @@ public class ConnectorTracker implements Serializable { } private static boolean hasVisibleChild(ClientConnector parent) { - Iterator<? extends ClientConnector> iterator = AbstractClientConnector - .getAllChildrenIterable(parent).iterator(); - while (iterator.hasNext()) { - ClientConnector child = iterator.next(); + Iterable<? extends ClientConnector> iterable = AbstractClientConnector + .getAllChildrenIterable(parent); + for (ClientConnector child : iterable) { if (LegacyCommunicationManager.isConnectorVisibleToClient(child)) { return true; } diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java index b4d97018ce..b7bbcd061b 100644 --- a/server/src/main/java/com/vaadin/ui/GridLayout.java +++ b/server/src/main/java/com/vaadin/ui/GridLayout.java @@ -217,16 +217,16 @@ public class GridLayout extends AbstractLayout // Inserts the component to right place at the list // Respect top-down, left-right ordering // component.setParent(this); - final Iterator<Component> i = components.iterator(); final Map<Connector, ChildComponentData> childDataMap = getState().childData; int index = 0; boolean done = false; - while (!done && i.hasNext()) { - final ChildComponentData existingArea = childDataMap.get(i.next()); + for (Component c : components) { + final ChildComponentData existingArea = childDataMap.get(c); if ((existingArea.row1 >= row1 && existingArea.column1 > column1) || existingArea.row1 > row1) { components.add(index, component); done = true; + break; } index++; } diff --git a/server/src/main/java/com/vaadin/ui/MenuBar.java b/server/src/main/java/com/vaadin/ui/MenuBar.java index 35988bb84d..f7682408d4 100644 --- a/server/src/main/java/com/vaadin/ui/MenuBar.java +++ b/server/src/main/java/com/vaadin/ui/MenuBar.java @@ -20,7 +20,6 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; import java.util.Deque; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -169,9 +168,8 @@ public class MenuBar extends AbstractComponent if (variables.containsKey("clickedId")) { Integer clickedId = (Integer) variables.get("clickedId"); - Iterator<MenuItem> itr = getItems().iterator(); - while (itr.hasNext()) { - items.push(itr.next()); + for (MenuItem i : getItems()) { + items.push(i); } MenuItem tmpItem = null; @@ -182,9 +180,8 @@ public class MenuBar extends AbstractComponent found = (clickedId == tmpItem.getId()); if (tmpItem.hasChildren()) { - itr = tmpItem.getChildren().iterator(); - while (itr.hasNext()) { - items.push(itr.next()); + for (MenuItem i : tmpItem.getChildren()) { + items.push(i); } } diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java index 41606737d5..33ca7267ec 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java @@ -109,14 +109,7 @@ public class ColorPickerHistory extends CustomField<Color> { ArrayBlockingQueue<Color> colorHistory = getColorHistory(); // Check that the color does not already exist - boolean exists = false; - Iterator<Color> iter = colorHistory.iterator(); - while (iter.hasNext()) { - if (color.equals(iter.next())) { - exists = true; - break; - } - } + boolean exists = colorHistory.contains(color); // If the color does not exist then add it if (!exists) { @@ -136,7 +129,7 @@ public class ColorPickerHistory extends CustomField<Color> { // Create 2d color map Color[][] colors = new Color[ROWS][COLUMNS]; - iter = colorList.iterator(); + Iterator<Color> iter = colorList.iterator(); for (int row = 0; row < ROWS; row++) { for (int col = 0; col < COLUMNS; col++) { diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java index 8d945e9e9c..435f20d64f 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java @@ -18,7 +18,6 @@ package com.vaadin.ui.components.colorpicker; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.Set; @@ -761,10 +760,8 @@ public class ColorPickerPopup extends Window implements HasValue<Color> { .setRequiredIndicatorVisible(isRequiredIndicatorVisible()); } if (component instanceof HasComponents) { - Iterator<Component> iterator = ((HasComponents) component) - .iterator(); - while (iterator.hasNext()) { - updateColorComponents(iterator.next()); + for (Component c : (HasComponents) component) { + updateColorComponents(c); } } } diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java index 6953d980f4..485fdcc721 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java @@ -15,7 +15,6 @@ */ package com.vaadin.ui.components.colorpicker; -import java.util.Iterator; import java.util.Objects; import com.vaadin.data.HasValue; @@ -220,10 +219,8 @@ public class ColorPickerPreview extends CssLayout implements HasValue<Color> { ((HasValue<?>) component).setReadOnly(isReadOnly()); } if (component instanceof HasComponents) { - Iterator<Component> iterator = ((HasComponents) component) - .iterator(); - while (iterator.hasNext()) { - updateColorComponents(iterator.next()); + for (Component c : (HasComponents) component) { + updateColorComponents(c); } } } diff --git a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java index c42a11e31d..aa37e860d7 100644 --- a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java +++ b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java @@ -19,7 +19,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; -import java.util.Iterator; import java.util.List; import java.util.Optional; import java.util.jar.JarEntry; @@ -119,7 +118,7 @@ public class ClassesSerializableTest { classes.addAll(findServerClasses(location)); } - List<Field> nonSerializableFunctionFields = new ArrayList<>(); + ArrayList<Field> nonSerializableFunctionFields = new ArrayList<>(); List<Class<?>> nonSerializableClasses = new ArrayList<>(); for (String className : classes) { @@ -221,9 +220,7 @@ public class ClassesSerializableTest { private void failSerializableClasses( List<Class<?>> nonSerializableClasses) { String nonSerializableString = ""; - Iterator<Class<?>> it = nonSerializableClasses.iterator(); - while (it.hasNext()) { - Class<?> c = it.next(); + for (Class<?> c : nonSerializableClasses) { nonSerializableString += ", " + c.getName(); if (c.isAnonymousClass()) { nonSerializableString += "(super: "; diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridDetailsTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridDetailsTest.java index c7f1fbd778..454b5d3b3d 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridDetailsTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridDetailsTest.java @@ -54,10 +54,7 @@ public class GridDetailsTest { @Test public void testGridComponentIteratorContainsDetailsComponents() { - Iterator<Component> i = grid.iterator(); - - while (i.hasNext()) { - Component c = i.next(); + for (Component c : grid) { if (c instanceof Label) { String value = ((Label) c).getValue(); Assert.assertTrue( diff --git a/server/src/test/java/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java b/server/src/test/java/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java index b13a379b05..5f4f3cea65 100644 --- a/server/src/test/java/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java +++ b/server/src/test/java/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java @@ -7,8 +7,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import java.util.Iterator; - import org.junit.Before; import org.junit.Test; @@ -63,9 +61,8 @@ public class ComponentAttachDetachListenerTest { attachTarget = event.getContainer(); // Search for component in container (should be found) - Iterator<Component> iter = attachTarget.iterator(); - while (iter.hasNext()) { - if (iter.next() == attachedComponent) { + for (Component c : attachTarget) { + if (c == attachedComponent) { foundInContainer = true; break; } @@ -93,9 +90,8 @@ public class ComponentAttachDetachListenerTest { detachedTarget = event.getContainer(); // Search for component in container (should NOT be found) - Iterator<Component> iter = detachedTarget.iterator(); - while (iter.hasNext()) { - if (iter.next() == detachedComponent) { + for (Component c : detachedTarget) { + if (c == detachedComponent) { foundInContainer = true; break; } |